Bug 1291821 - Wrap local repositories in buffering middleware r=rnewman

History stage does not wrap history respository in a buffer, because we'd like to
use a high-water-mark and offset resuming later on, and using a persistent buffer
for this stage does not make sense.

MozReview-Commit-ID: FS1swml2bIC

--HG--
extra : rebase_source : be197e0459d86a320076174936cea8ee76e1dbed
This commit is contained in:
Grisha Kruglov 2016-10-20 16:31:31 -07:00
Родитель dc5b52e557
Коммит 5632261a6b
6 изменённых файлов: 44 добавлений и 6 удалений

Просмотреть файл

@ -191,6 +191,11 @@ public class AndroidBrowserHistoryRepositorySession extends AndroidBrowserReposi
@Override @Override
public void storeDone() { public void storeDone() {
storeDone(System.currentTimeMillis());
}
@Override
public void storeDone(final long end) {
storeWorkQueue.execute(new Runnable() { storeWorkQueue.execute(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -201,7 +206,7 @@ public class AndroidBrowserHistoryRepositorySession extends AndroidBrowserReposi
Logger.warn(LOG_TAG, "Error flushing records to database.", e); Logger.warn(LOG_TAG, "Error flushing records to database.", e);
} }
} }
storeDone(System.currentTimeMillis()); AndroidBrowserHistoryRepositorySession.super.storeDone(end);
} }
}); });
} }

Просмотреть файл

@ -7,6 +7,8 @@ package org.mozilla.gecko.sync.stage;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import org.mozilla.gecko.sync.MetaGlobalException; import org.mozilla.gecko.sync.MetaGlobalException;
import org.mozilla.gecko.sync.middleware.BufferingMiddlewareRepository;
import org.mozilla.gecko.sync.middleware.storage.MemoryBufferStorage;
import org.mozilla.gecko.sync.repositories.ConstrainedServer11Repository; import org.mozilla.gecko.sync.repositories.ConstrainedServer11Repository;
import org.mozilla.gecko.sync.repositories.RecordFactory; import org.mozilla.gecko.sync.repositories.RecordFactory;
import org.mozilla.gecko.sync.repositories.Repository; import org.mozilla.gecko.sync.repositories.Repository;
@ -53,7 +55,11 @@ public class AndroidBrowserBookmarksServerSyncStage extends ServerSyncStage {
@Override @Override
protected Repository getLocalRepository() { protected Repository getLocalRepository() {
return new AndroidBrowserBookmarksRepository(); return new BufferingMiddlewareRepository(
session.getSyncDeadline(),
new MemoryBufferStorage(),
new AndroidBrowserBookmarksRepository()
);
} }
@Override @Override

Просмотреть файл

@ -4,6 +4,8 @@
package org.mozilla.gecko.sync.stage; package org.mozilla.gecko.sync.stage;
import org.mozilla.gecko.sync.middleware.BufferingMiddlewareRepository;
import org.mozilla.gecko.sync.middleware.storage.MemoryBufferStorage;
import org.mozilla.gecko.sync.repositories.RecordFactory; import org.mozilla.gecko.sync.repositories.RecordFactory;
import org.mozilla.gecko.sync.repositories.Repository; import org.mozilla.gecko.sync.repositories.Repository;
import org.mozilla.gecko.sync.repositories.android.FennecTabsRepository; import org.mozilla.gecko.sync.repositories.android.FennecTabsRepository;
@ -30,7 +32,11 @@ public class FennecTabsServerSyncStage extends ServerSyncStage {
@Override @Override
protected Repository getLocalRepository() { protected Repository getLocalRepository() {
return new FennecTabsRepository(session.getClientsDelegate()); return new BufferingMiddlewareRepository(
session.getSyncDeadline(),
new MemoryBufferStorage(),
new FennecTabsRepository(session.getClientsDelegate())
);
} }
@Override @Override

Просмотреть файл

@ -7,6 +7,8 @@ package org.mozilla.gecko.sync.stage;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import org.mozilla.gecko.sync.CryptoRecord; import org.mozilla.gecko.sync.CryptoRecord;
import org.mozilla.gecko.sync.middleware.BufferingMiddlewareRepository;
import org.mozilla.gecko.sync.middleware.storage.MemoryBufferStorage;
import org.mozilla.gecko.sync.repositories.ConstrainedServer11Repository; import org.mozilla.gecko.sync.repositories.ConstrainedServer11Repository;
import org.mozilla.gecko.sync.repositories.RecordFactory; import org.mozilla.gecko.sync.repositories.RecordFactory;
import org.mozilla.gecko.sync.repositories.Repository; import org.mozilla.gecko.sync.repositories.Repository;
@ -54,7 +56,11 @@ public class FormHistoryServerSyncStage extends ServerSyncStage {
@Override @Override
protected Repository getLocalRepository() { protected Repository getLocalRepository() {
return new FormHistoryRepositorySession.FormHistoryRepository(); return new BufferingMiddlewareRepository(
session.getSyncDeadline(),
new MemoryBufferStorage(),
new FormHistoryRepositorySession.FormHistoryRepository()
);
} }
public class FormHistoryRecordFactory extends RecordFactory { public class FormHistoryRecordFactory extends RecordFactory {

Просмотреть файл

@ -4,6 +4,8 @@
package org.mozilla.gecko.sync.stage; package org.mozilla.gecko.sync.stage;
import org.mozilla.gecko.sync.middleware.BufferingMiddlewareRepository;
import org.mozilla.gecko.sync.middleware.storage.MemoryBufferStorage;
import org.mozilla.gecko.sync.repositories.RecordFactory; import org.mozilla.gecko.sync.repositories.RecordFactory;
import org.mozilla.gecko.sync.repositories.Repository; import org.mozilla.gecko.sync.repositories.Repository;
import org.mozilla.gecko.sync.repositories.android.PasswordsRepositorySession; import org.mozilla.gecko.sync.repositories.android.PasswordsRepositorySession;
@ -28,7 +30,11 @@ public class PasswordsServerSyncStage extends ServerSyncStage {
@Override @Override
protected Repository getLocalRepository() { protected Repository getLocalRepository() {
return new PasswordsRepositorySession.PasswordsRepository(); return new BufferingMiddlewareRepository(
session.getSyncDeadline(),
new MemoryBufferStorage(),
new PasswordsRepositorySession.PasswordsRepository()
);
} }
@Override @Override

Просмотреть файл

@ -170,7 +170,16 @@ public class RecordsChannel implements
this.consumer = new ConcurrentRecordConsumer(this); this.consumer = new ConcurrentRecordConsumer(this);
ThreadPool.run(this.consumer); ThreadPool.run(this.consumer);
waitingForQueueDone = true; waitingForQueueDone = true;
source.fetchSince(source.getLastSyncTimestamp(), this);
// Fetch all records that were modified since our previous flow. If our previous flow succeeded,
// we will use source's last-sync timestamp. If our previous flow didn't complete, resume it,
// starting from sink's high water mark timestamp.
// If there was no previous flow (first sync, or data was cleared...), fetch everything.
// Resuming a flow is supported for buffered RepositorySessions. We degrade gracefully otherwise.
final long highWaterMark = sink.getHighWaterMarkTimestamp();
final long lastSync = source.getLastSyncTimestamp();
final long sinceTimestamp = Math.max(highWaterMark, lastSync);
source.fetchSince(sinceTimestamp, this);
} }
/** /**