RebuildNotedb: batch changes by project

If we batch changes by project before rebuilding them and writing them
to the notedb, we can use a single BatchRefUpdate for all of the
changes in a project, which reduces overhead for writing every change
to the notedb.

Additionally, within the code the rebuilds each change, I synchronized
on the BatchRefUpdate object because it is not thread safe. Since all
changes in a project will be using the same one, we can just
synchronize the function calls that modify that BatchRefUpdate.

Change-Id: I4af196fa720180b0846e9a6e7cc6d9083a75f695
This commit is contained in:
Yacob Yonas
2014-08-08 11:11:47 -07:00
parent 7c51481994
commit 904c08183c
2 changed files with 116 additions and 64 deletions

View File

@@ -72,12 +72,12 @@ public class ChangeRebuilder {
this.updateFactory = updateFactory;
}
public ListenableFuture<?> rebuildAsync(
final Change change, ListeningExecutorService executor) {
public ListenableFuture<?> rebuildAsync(final Change change,
ListeningExecutorService executor, final BatchRefUpdate bru) {
return executor.submit(new Callable<Void>() {
@Override
@Override
public Void call() throws Exception {
rebuild(change, null);
rebuild(change, bru);
return null;
}
});
@@ -109,7 +109,7 @@ public class ChangeRebuilder {
controlFactory.controlFor(change, user), e.when);
update.setPatchSetId(e.psId);
if (batch == null) {
batch = update.openUpdate();
batch = update.openUpdateInBatch(bru);
}
}
e.apply(update);
@@ -118,7 +118,15 @@ public class ChangeRebuilder {
if (update != null) {
writeToBatch(batch, update);
}
batch.commit();
// Since the BatchMetaDataUpdates generated by all ChangeRebuilders on a
// given project are backed by the same BatchRefUpdate, we need to
// synchronize on the BatchRefUpdate. Therefore, since commit on a
// BatchMetaDataUpdate is the only method that modifies a BatchRefUpdate,
// we can just synchronize this call.
synchronized (bru) {
batch.commit();
}
}
}