Support treating NoteDb as the source of truth

Handle the new enum value PrimaryStorage.NOTE_DB. When updating a
change, if its state indicates NoteDb is the source of truth, we don't
have to bother writing to ReviewDb, including to update the
NoteDbChangeState. This means that NoteDb and ReviewDb will get out of
sync, and we would need a separate migration process to copy data from
NoteDb back to ReviewDb, not yet implemented.

Many code changes here come from the fact that various handlers
manually delete entities from ReviewDb, where the keys may now have
originally been read from NoteDb. Since we now don't write new
entities to ReviewDb, trying to delete non-existent keys will fail
with OrmConcurrencyException. In fact the transaction would have been
rolled back later in BatchUpdate, so the delete would never really
take effect, but unfortunately gwtorm actually throws at the call site
of delete, prior to committing the transaction.

This change supports changes in in the database with PrimaryStorage ==
NOTE_DB, but does not yet implement a migration path. In the new
acceptance tests, we just set the state manually.

Change-Id: If177aa0b9666f9d14869552c661d5aa8b86ead3b
This commit is contained in:
Dave Borowitz
2016-07-28 15:40:09 -04:00
parent 3187100210
commit fc89596b5b
17 changed files with 419 additions and 86 deletions

View File

@@ -31,6 +31,7 @@ import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.reviewdb.client.RevId;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.git.RepoRefCache;
import com.google.gerrit.server.notedb.NoteDbChangeState.PrimaryStorage;
import com.google.gerrit.server.notedb.NoteDbUpdateManager.StagedResult;
import com.google.gerrit.server.notedb.rebuild.ChangeRebuilder;
import com.google.gerrit.server.project.NoSuchChangeException;
@@ -85,7 +86,9 @@ public class DraftCommentNotes extends AbstractChangeNotes<DraftCommentNotes> {
Args args,
@Assisted Change.Id changeId,
@Assisted Account.Id author) {
super(args, changeId, true);
// PrimaryStorage is unknown; this should only called by
// PatchLineCommentsUtil#draftByAuthor, which can live with this.
super(args, changeId, null, false);
this.change = null;
this.author = author;
this.rebuildResult = null;
@@ -97,7 +100,7 @@ public class DraftCommentNotes extends AbstractChangeNotes<DraftCommentNotes> {
Account.Id author,
boolean autoRebuild,
NoteDbUpdateManager.Result rebuildResult) {
super(args, change.getId(), autoRebuild);
super(args, change.getId(), PrimaryStorage.of(change), autoRebuild);
this.change = change;
this.author = author;
this.rebuildResult = rebuildResult;