Add config option setting default primary storage for new changes

Setting to NOTE_DB means new changes will never be written to
ReviewDb. Update ChangeNotes.Factory to properly detect the case of a
change not existing in ReviewDb but possibly still existing in NoteDb.

This config option only controls the primary storage for new changes.
Old changes (that have not been migrated, which is all of them since
this change predates the migration tools) keep their primary storage
as REVIEW_DB. This means that a single running server needs to be able
to handle a mix of NOTE_DB/REVIEW_DB changes. Thus we need to continue
using a live ReviewDb instance in the server, and just avoid writing
any NoteDb-primary changes to that instance.

The easiest way to implement this technically is to keep all the
BatchUpdate code the same but only commit the change transaction if
the change requires ReviewDb. This means we don't have to change any
BatchUpdate.Op implementations, they can continue unconditionally
writing. Rolling back the transaction is much simpler than creating
some kind of ReviewDb wrapper that drops writes on the floor, even
though it does technically create some database traffic even though no
writes are committed.

Add a new NoteDbMode to run all tests with this option enabled,
double-checking after the tests that no changes were stored in
ReviewDb. Tweak tests in various ways to work with this option
enabled, avoiding direct use of ReviewDb when the primary storage is
NoteDb.

Change-Id: I9caf13192f955c4ec90409da32609d0a6f496d96
This commit is contained in:
Dave Borowitz
2016-12-19 14:50:54 -05:00
parent 3dbcb6ea48
commit fc9d1ae55f
14 changed files with 247 additions and 56 deletions

View File

@@ -25,6 +25,8 @@ import com.google.gerrit.pgm.Init;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.git.AsyncReceiveCommits;
import com.google.gerrit.server.ssh.NoSshModule;
import com.google.gerrit.server.util.ManualRequestContext;
import com.google.gerrit.server.util.OneOffRequestContext;
import com.google.gerrit.server.util.SocketUtil;
import com.google.gerrit.server.util.SystemLog;
import com.google.gerrit.testutil.FakeEmailSender;
@@ -62,6 +64,7 @@ public class GerritServer {
static Description forTestClass(org.junit.runner.Description testDesc,
String configName) {
return new AutoValue_GerritServer_Description(
testDesc,
configName,
true, // @UseLocalDisk is only valid on methods.
!has(NoHttpd.class, testDesc.getTestClass()),
@@ -75,6 +78,7 @@ public class GerritServer {
static Description forTestMethod(org.junit.runner.Description testDesc,
String configName) {
return new AutoValue_GerritServer_Description(
testDesc,
configName,
testDesc.getAnnotation(UseLocalDisk.class) == null,
testDesc.getAnnotation(NoHttpd.class) == null
@@ -97,6 +101,7 @@ public class GerritServer {
return false;
}
abstract org.junit.runner.Description testDescription();
@Nullable abstract String configName();
abstract boolean memory();
abstract boolean httpd();
@@ -297,10 +302,7 @@ public class GerritServer {
void stop() throws Exception {
try {
if (NoteDbMode.get().equals(NoteDbMode.CHECK)) {
testInjector.getInstance(NoteDbChecker.class)
.rebuildAndCheckAllChanges();
}
checkNoteDbState();
} finally {
daemon.getLifecycleManager().stop();
if (daemonService != null) {
@@ -312,6 +314,23 @@ public class GerritServer {
}
}
private void checkNoteDbState() throws Exception {
NoteDbMode mode = NoteDbMode.get();
if (mode != NoteDbMode.CHECK && mode != NoteDbMode.PRIMARY) {
return;
}
NoteDbChecker checker = testInjector.getInstance(NoteDbChecker.class);
OneOffRequestContext oneOffRequestContext =
testInjector.getInstance(OneOffRequestContext.class);
try (ManualRequestContext ctx = oneOffRequestContext.open()) {
if (mode == NoteDbMode.CHECK) {
checker.rebuildAndCheckAllChanges();
} else if (mode == NoteDbMode.PRIMARY) {
checker.assertNoReviewDbChanges(desc.testDescription());
}
}
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this).addValue(desc).toString();