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:
@@ -60,6 +60,7 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDbUtil;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.PatchSetUtil;
|
||||
import com.google.gerrit.server.Sequences;
|
||||
import com.google.gerrit.server.StarredChangesUtil;
|
||||
import com.google.gerrit.server.account.AccountManager;
|
||||
@@ -146,6 +147,7 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
||||
@Inject protected InternalChangeQuery internalChangeQuery;
|
||||
@Inject protected ChangeNotes.Factory notesFactory;
|
||||
@Inject protected PatchSetInserter.Factory patchSetFactory;
|
||||
@Inject protected PatchSetUtil psUtil;
|
||||
@Inject protected ChangeControl.GenericFactory changeControlFactory;
|
||||
@Inject protected ChangeQueryProcessor queryProcessor;
|
||||
@Inject protected SchemaCreator schemaCreator;
|
||||
@@ -1579,9 +1581,13 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
||||
Account.Id user2 = createAccount("user2");
|
||||
TestRepository<Repo> repo = createProject("repo");
|
||||
Change change1 = insert(repo, newChange(repo));
|
||||
PatchSet ps1 = db.patchSets().get(change1.currentPatchSetId());
|
||||
ChangeNotes notes1 =
|
||||
notesFactory.create(db, change1.getProject(), change1.getId());
|
||||
PatchSet ps1 = psUtil.get(db, notes1, change1.currentPatchSetId());
|
||||
Change change2 = insert(repo, newChange(repo));
|
||||
PatchSet ps2 = db.patchSets().get(change2.currentPatchSetId());
|
||||
ChangeNotes notes2 =
|
||||
notesFactory.create(db, change2.getProject(), change2.getId());
|
||||
PatchSet ps2 = psUtil.get(db, notes2, change2.currentPatchSetId());
|
||||
|
||||
requestContext.setContext(newRequestContext(user1));
|
||||
assertQuery("has:edit");
|
||||
@@ -1692,7 +1698,9 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
||||
Project.NameKey project = new Project.NameKey("repo");
|
||||
TestRepository<Repo> repo = createProject(project.get());
|
||||
Change change = insert(repo, newChange(repo));
|
||||
PatchSet ps = db.patchSets().get(change.currentPatchSetId());
|
||||
ChangeNotes notes =
|
||||
notesFactory.create(db, change.getProject(), change.getId());
|
||||
PatchSet ps = psUtil.get(db, notes, change.currentPatchSetId());
|
||||
|
||||
requestContext.setContext(newRequestContext(user));
|
||||
assertThat(changeEditModifier.createEdit(change, ps))
|
||||
@@ -1714,6 +1722,9 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
||||
|
||||
@Test
|
||||
public void refStateFields() throws Exception {
|
||||
// This test method manages primary storage manually.
|
||||
assume().that(notesMigration.changePrimaryStorage())
|
||||
.isEqualTo(PrimaryStorage.REVIEW_DB);
|
||||
Account.Id user = createAccount("user");
|
||||
Project.NameKey project = new Project.NameKey("repo");
|
||||
TestRepository<Repo> repo = createProject(project.get());
|
||||
@@ -1723,7 +1734,9 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
||||
Change change = insert(repo, newChangeForCommit(repo, commit));
|
||||
Change.Id id = change.getId();
|
||||
int c = id.get();
|
||||
PatchSet ps = db.patchSets().get(change.currentPatchSetId());
|
||||
ChangeNotes notes =
|
||||
notesFactory.create(db, change.getProject(), change.getId());
|
||||
PatchSet ps = psUtil.get(db, notes, change.currentPatchSetId());
|
||||
requestContext.setContext(newRequestContext(user));
|
||||
|
||||
// Ensure one of each type of supported ref is present for the change. If
|
||||
|
||||
Reference in New Issue
Block a user