Enable RepoSequence with a config option

When noteDb.changes.sequence is true, read changes from the
refs/sequences/changes blob in All-Projects. Use a lazily evaluated
Seed that reads the next change number from ReviewDb and uses it as
the first number in NoteDb.

In a single-server setting this is sufficient, but in a multi-master
environment it may be desirable to leave a gap after the next
ReviewDb counter to account for the fact that not all servers may
receive the configuration update immediately. Control this with an
undocumented config option.

Change-Id: I2de8fbd42b525a75b3cdbcdb4b3f9e33e382b7a7
This commit is contained in:
Dave Borowitz
2016-07-21 15:20:16 -04:00
parent 9448ed4c81
commit 08de3c852b
7 changed files with 167 additions and 35 deletions

View File

@@ -48,6 +48,7 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.reviewdb.server.ReviewDbUtil;
import com.google.gerrit.server.ChangeUtil;
import com.google.gerrit.server.PatchLineCommentsUtil;
import com.google.gerrit.server.Sequences;
import com.google.gerrit.server.change.PostReview;
import com.google.gerrit.server.change.Rebuild;
import com.google.gerrit.server.change.RevisionResource;
@@ -118,8 +119,11 @@ public class ChangeRebuilderIT extends AbstractDaemonTest {
@Inject
private BatchUpdate.Factory batchUpdateFactory;
@Inject
private Sequences seq;
@Before
public void setUp() {
public void setUp() throws Exception {
assume().that(NoteDbMode.readWrite()).isFalse();
TestTimeUtil.resetWithClockStep(1, TimeUnit.SECONDS);
setNotesMigration(false, false);
@@ -130,10 +134,20 @@ public class ChangeRebuilderIT extends AbstractDaemonTest {
TestTimeUtil.useSystemTime();
}
private void setNotesMigration(boolean writeChanges, boolean readChanges) {
@SuppressWarnings("deprecation")
private void setNotesMigration(boolean writeChanges, boolean readChanges)
throws Exception {
notesMigration.setWriteChanges(writeChanges);
notesMigration.setReadChanges(readChanges);
db = atrScope.reopenDb().getReviewDbProvider().get();
if (notesMigration.readChangeSequence()) {
// Copy next ReviewDb ID to NoteDb.
seq.getChangeIdRepoSequence().set(db.nextChangeId());
} else {
// Copy next NoteDb ID to ReviewDb.
while (db.nextChangeId() < seq.getChangeIdRepoSequence().next()) {}
}
}
@Test
@@ -163,8 +177,7 @@ public class ChangeRebuilderIT extends AbstractDaemonTest {
@Test
public void patchSetWithNullGroups() throws Exception {
Timestamp ts = TimeUtil.nowTs();
@SuppressWarnings("deprecation")
Change c = TestChanges.newChange(project, user.getId(), db.nextChangeId());
Change c = TestChanges.newChange(project, user.getId(), seq.nextChangeId());
c.setCreatedOn(ts);
c.setLastUpdatedOn(ts);
PatchSet ps = TestChanges.newPatchSet(