Sequences: Remove ReviewDb support

Change-Id: I41bc697c3cab890005ceab596e28a1addc87d248
This commit is contained in:
Dave Borowitz
2018-11-16 14:05:17 -08:00
parent 7397e6956d
commit 29f2c634fa
2 changed files with 8 additions and 47 deletions

View File

@@ -14,8 +14,6 @@
package com.google.gerrit.server; package com.google.gerrit.server;
import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.gerrit.metrics.Description; import com.google.gerrit.metrics.Description;
@@ -29,14 +27,10 @@ import com.google.gerrit.server.config.AllUsersName;
import com.google.gerrit.server.config.GerritServerConfig; import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.extensions.events.GitReferenceUpdated; import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
import com.google.gerrit.server.git.GitRepositoryManager; import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.notedb.NotesMigration;
import com.google.gerrit.server.notedb.RepoSequence; import com.google.gerrit.server.notedb.RepoSequence;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
@Singleton @Singleton
@@ -55,8 +49,6 @@ public class Sequences {
GROUPS; GROUPS;
} }
private final Provider<ReviewDb> db;
private final NotesMigration migration;
private final RepoSequence accountSeq; private final RepoSequence accountSeq;
private final RepoSequence changeSeq; private final RepoSequence changeSeq;
private final RepoSequence groupSeq; private final RepoSequence groupSeq;
@@ -65,15 +57,11 @@ public class Sequences {
@Inject @Inject
public Sequences( public Sequences(
@GerritServerConfig Config cfg, @GerritServerConfig Config cfg,
Provider<ReviewDb> db,
NotesMigration migration,
GitRepositoryManager repoManager, GitRepositoryManager repoManager,
GitReferenceUpdated gitRefUpdated, GitReferenceUpdated gitRefUpdated,
AllProjectsName allProjects, AllProjectsName allProjects,
AllUsersName allUsers, AllUsersName allUsers,
MetricMaker metrics) { MetricMaker metrics) {
this.db = db;
this.migration = migration;
int accountBatchSize = cfg.getInt("noteDb", "accounts", "sequenceBatchSize", 1); int accountBatchSize = cfg.getInt("noteDb", "accounts", "sequenceBatchSize", 1);
accountSeq = accountSeq =
@@ -85,13 +73,15 @@ public class Sequences {
() -> ReviewDb.FIRST_ACCOUNT_ID, () -> ReviewDb.FIRST_ACCOUNT_ID,
accountBatchSize); accountBatchSize);
int gap = getChangeSequenceGap(cfg);
@SuppressWarnings("deprecation")
RepoSequence.Seed changeSeed = () -> db.get().nextChangeId() + gap;
int changeBatchSize = cfg.getInt("noteDb", "changes", "sequenceBatchSize", 20); int changeBatchSize = cfg.getInt("noteDb", "changes", "sequenceBatchSize", 20);
changeSeq = changeSeq =
new RepoSequence( new RepoSequence(
repoManager, gitRefUpdated, allProjects, NAME_CHANGES, changeSeed, changeBatchSize); repoManager,
gitRefUpdated,
allProjects,
NAME_CHANGES,
() -> ReviewDb.FIRST_CHANGE_ID,
changeBatchSize);
int groupBatchSize = 1; int groupBatchSize = 1;
groupSeq = groupSeq =
@@ -120,33 +110,17 @@ public class Sequences {
} }
public int nextChangeId() throws OrmException { public int nextChangeId() throws OrmException {
if (!migration.readChangeSequence()) {
return nextChangeId(db.get());
}
try (Timer2.Context timer = nextIdLatency.start(SequenceType.CHANGES, false)) { try (Timer2.Context timer = nextIdLatency.start(SequenceType.CHANGES, false)) {
return changeSeq.next(); return changeSeq.next();
} }
} }
public ImmutableList<Integer> nextChangeIds(int count) throws OrmException { public ImmutableList<Integer> nextChangeIds(int count) throws OrmException {
if (migration.readChangeSequence()) {
try (Timer2.Context timer = nextIdLatency.start(SequenceType.CHANGES, count > 1)) { try (Timer2.Context timer = nextIdLatency.start(SequenceType.CHANGES, count > 1)) {
return changeSeq.next(count); return changeSeq.next(count);
} }
} }
if (count == 0) {
return ImmutableList.of();
}
checkArgument(count > 0, "count is negative: %s", count);
List<Integer> ids = new ArrayList<>(count);
ReviewDb db = this.db.get();
for (int i = 0; i < count; i++) {
ids.add(nextChangeId(db));
}
return ImmutableList.copyOf(ids);
}
public int nextGroupId() throws OrmException { public int nextGroupId() throws OrmException {
try (Timer2.Context timer = nextIdLatency.start(SequenceType.GROUPS, false)) { try (Timer2.Context timer = nextIdLatency.start(SequenceType.GROUPS, false)) {
return groupSeq.next(); return groupSeq.next();
@@ -157,9 +131,4 @@ public class Sequences {
public RepoSequence getChangeIdRepoSequence() { public RepoSequence getChangeIdRepoSequence() {
return changeSeq; return changeSeq;
} }
@SuppressWarnings("deprecation")
private static int nextChangeId(ReviewDb db) throws OrmException {
return db.nextChangeId();
}
} }

View File

@@ -42,7 +42,6 @@ import com.google.gerrit.server.group.db.InternalGroupCreation;
import com.google.gerrit.server.group.db.InternalGroupUpdate; import com.google.gerrit.server.group.db.InternalGroupUpdate;
import com.google.gerrit.server.index.group.GroupIndex; import com.google.gerrit.server.index.group.GroupIndex;
import com.google.gerrit.server.index.group.GroupIndexCollection; import com.google.gerrit.server.index.group.GroupIndexCollection;
import com.google.gerrit.server.notedb.NotesMigration;
import com.google.gwtorm.jdbc.JdbcExecutor; import com.google.gwtorm.jdbc.JdbcExecutor;
import com.google.gwtorm.jdbc.JdbcSchema; import com.google.gwtorm.jdbc.JdbcSchema;
import com.google.gwtorm.server.OrmDuplicateKeyException; import com.google.gwtorm.server.OrmDuplicateKeyException;
@@ -72,7 +71,6 @@ public class ReviewDbSchemaCreator {
private final Config config; private final Config config;
private final MetricMaker metricMaker; private final MetricMaker metricMaker;
private final NotesMigration migration;
private final AllProjectsName allProjectsName; private final AllProjectsName allProjectsName;
@Inject @Inject
@@ -88,7 +86,6 @@ public class ReviewDbSchemaCreator {
@GerritServerId String serverId, @GerritServerId String serverId,
@GerritServerConfig Config config, @GerritServerConfig Config config,
MetricMaker metricMaker, MetricMaker metricMaker,
NotesMigration migration,
AllProjectsName apName) { AllProjectsName apName) {
this( this(
site.site_path, site.site_path,
@@ -102,7 +99,6 @@ public class ReviewDbSchemaCreator {
serverId, serverId,
config, config,
metricMaker, metricMaker,
migration,
apName); apName);
} }
@@ -118,7 +114,6 @@ public class ReviewDbSchemaCreator {
String serverId, String serverId,
Config config, Config config,
MetricMaker metricMaker, MetricMaker metricMaker,
NotesMigration migration,
AllProjectsName apName) { AllProjectsName apName) {
site_path = site; site_path = site;
this.repoManager = repoManager; this.repoManager = repoManager;
@@ -132,7 +127,6 @@ public class ReviewDbSchemaCreator {
this.config = config; this.config = config;
this.allProjectsName = apName; this.allProjectsName = apName;
this.migration = migration;
this.metricMaker = metricMaker; this.metricMaker = metricMaker;
} }
@@ -157,8 +151,6 @@ public class ReviewDbSchemaCreator {
Sequences seqs = Sequences seqs =
new Sequences( new Sequences(
config, config,
() -> db,
migration,
repoManager, repoManager,
GitReferenceUpdated.DISABLED, GitReferenceUpdated.DISABLED,
allProjectsName, allProjectsName,