Rewrite AbstractChangeUpdate to not extend MetaDataUpdate

This was never a particularly good fit for ChangeUpdate, as evidenced
by all the methods we had to override to throw exceptions to say
"don't use this method, use this other method." Plus, the
BatchMetaDataUpdate interface was confusing, and moreover didn't allow
us to group draft updates into a single BatchRefUpdate.

Reduce the methods in AbstractChangeUpdate to what is actually
required. Add a new class, the somewhat clumsily named
NoteDbUpdateManager, that understands enough about ChangeUpdates to
batch both the change repo and All-Users repo changes together.

This allows us to replace:

 BatchMetaDataUpdate batch = update1.openUpdate();
 try {
   update1.writeCommit(batch);
   update2.writeCommit(batch);
   batch.commit();
 } finally {
   batch.close();
 }

With:

 NoteDbUpdateManager manager = updateManagerFactory.create(project);
 manager.add(update1);
 manager.add(update2);
 manager.execute();

The explicit creation of the update manager without having to call a
method on one of the update instances reduces one possibility of
error.

The changes to ChangeRebuilder are just enough to get it to compile;
there are still problems with this class that I identified when trying
to write tests, so a further rewrite (including tests) will be coming.

It is not a coincidence that the structure and API of
NoteDbUpdateManager are reminiscent of BatchUpdate. This will allow us
to eventually use a single NoteDbUpdateManager per BatchUpdate and
even update change and meta refs at the same time.

Change-Id: Ib163d2092b76066203b8bfd78ddc69376e0e441b
This commit is contained in:
Dave Borowitz
2016-02-18 09:49:19 -05:00
parent 2ce83d538f
commit 0e8077dc8d
12 changed files with 505 additions and 358 deletions

View File

@@ -121,9 +121,6 @@ public class RebuildNotedb extends SiteProgram {
deleteRefs(RefNames.REFS_STARRED_CHANGES, allUsersRepo);
for (final Project.NameKey project : changesByProject.keySet()) {
try (Repository repo = repoManager.openMetadataRepository(project)) {
final BatchRefUpdate bru = repo.getRefDatabase().newBatchUpdate();
final BatchRefUpdate bruAllUsers =
allUsersRepo.getRefDatabase().newBatchUpdate();
List<ListenableFuture<?>> futures = Lists.newArrayList();
// Here, we elide the project name to 50 characters to ensure that
@@ -136,8 +133,8 @@ public class RebuildNotedb extends SiteProgram {
mpm.beginSubTask("failed", MultiProgressMonitor.UNKNOWN);
for (final Change c : changesByProject.get(project)) {
final ListenableFuture<?> future = rebuilder.rebuildAsync(c,
executor, bru, bruAllUsers, repo, allUsersRepo);
final ListenableFuture<?> future =
rebuilder.rebuildAsync(c, executor, repo);
futures.add(future);
future.addListener(
new RebuildListener(c.getId(), future, ok, doneTask, failedTask),
@@ -149,8 +146,6 @@ public class RebuildNotedb extends SiteProgram {
@Override
public ListenableFuture<Void> apply(List<?> input)
throws Exception {
execute(bru, repo);
execute(bruAllUsers, allUsersRepo);
mpm.end();
return Futures.immediateFuture(null);
}