Rewrite schema versioning in preparation for multiple versions
Store indexes in versioned directories, and don't consider open/closed to have separate versions. Extract a simple base Schema class with a version and a list of fields, which is analogous to the DB's SchemaVersion. Construct indexes using specific versions. Change-Id: I11e8e3a78cd62b1a01aa122bfd747ed5295fe057
This commit is contained in:
@@ -15,13 +15,12 @@
|
||||
package com.google.gerrit.lucene;
|
||||
|
||||
import static com.google.gerrit.lucene.LuceneChangeIndex.LUCENE_VERSION;
|
||||
|
||||
import static org.apache.lucene.util.Version.LUCENE_CURRENT;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gerrit.extensions.events.LifecycleListener;
|
||||
import com.google.gerrit.server.config.SitePaths;
|
||||
import com.google.gerrit.server.index.ChangeField;
|
||||
import com.google.gerrit.server.index.ChangeSchemas;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.ProvisionException;
|
||||
|
||||
@@ -36,8 +35,8 @@ import java.util.Map;
|
||||
|
||||
public class IndexVersionCheck implements LifecycleListener {
|
||||
public static final Map<String, Integer> SCHEMA_VERSIONS = ImmutableMap.of(
|
||||
LuceneChangeIndex.CHANGES_OPEN, ChangeField.SCHEMA_VERSION,
|
||||
LuceneChangeIndex.CHANGES_CLOSED, ChangeField.SCHEMA_VERSION);
|
||||
LuceneChangeIndex.CHANGES_OPEN, ChangeSchemas.getLatestRelease().getVersion(),
|
||||
LuceneChangeIndex.CHANGES_CLOSED, ChangeSchemas.getLatestRelease().getVersion());
|
||||
|
||||
public static File gerritIndexConfig(SitePaths sitePaths) {
|
||||
return new File(sitePaths.index_dir, "gerrit_index.config");
|
||||
|
@@ -35,6 +35,7 @@ import com.google.gerrit.server.index.FieldDef;
|
||||
import com.google.gerrit.server.index.FieldDef.FillArgs;
|
||||
import com.google.gerrit.server.index.FieldType;
|
||||
import com.google.gerrit.server.index.IndexRewriteImpl;
|
||||
import com.google.gerrit.server.index.Schema;
|
||||
import com.google.gerrit.server.query.Predicate;
|
||||
import com.google.gerrit.server.query.QueryParseException;
|
||||
import com.google.gerrit.server.query.change.ChangeData;
|
||||
@@ -93,8 +94,8 @@ public class LuceneChangeIndex implements ChangeIndex, LifecycleListener {
|
||||
LoggerFactory.getLogger(LuceneChangeIndex.class);
|
||||
|
||||
public static final Version LUCENE_VERSION = Version.LUCENE_43;
|
||||
public static final String CHANGES_OPEN = "changes_open";
|
||||
public static final String CHANGES_CLOSED = "changes_closed";
|
||||
public static final String CHANGES_OPEN = "open";
|
||||
public static final String CHANGES_CLOSED = "closed";
|
||||
private static final String ID_FIELD = ChangeField.LEGACY_ID.getName();
|
||||
|
||||
private static IndexWriterConfig getIndexWriterConfig(Config cfg, String name) {
|
||||
@@ -113,19 +114,23 @@ public class LuceneChangeIndex implements ChangeIndex, LifecycleListener {
|
||||
private final FillArgs fillArgs;
|
||||
private final ExecutorService executor;
|
||||
private final boolean readOnly;
|
||||
private final Schema<ChangeData> fields;
|
||||
private final SubIndex openIndex;
|
||||
private final SubIndex closedIndex;
|
||||
|
||||
LuceneChangeIndex(Config cfg, SitePaths sitePaths,
|
||||
ListeningScheduledExecutorService executor, FillArgs fillArgs,
|
||||
boolean readOnly) throws IOException {
|
||||
Schema<ChangeData> fields, boolean readOnly) throws IOException {
|
||||
this.sitePaths = sitePaths;
|
||||
this.fillArgs = fillArgs;
|
||||
this.executor = executor;
|
||||
this.readOnly = readOnly;
|
||||
openIndex = new SubIndex(new File(sitePaths.index_dir, CHANGES_OPEN),
|
||||
this.fields = fields;
|
||||
|
||||
File dir = new File(sitePaths.index_dir, "changes_" + fields.getVersion());
|
||||
openIndex = new SubIndex(new File(dir, CHANGES_OPEN),
|
||||
getIndexWriterConfig(cfg, "changes_open"));
|
||||
closedIndex = new SubIndex(new File(sitePaths.index_dir, CHANGES_CLOSED),
|
||||
closedIndex = new SubIndex(new File(dir, CHANGES_CLOSED),
|
||||
getIndexWriterConfig(cfg, "changes_closed"));
|
||||
}
|
||||
|
||||
@@ -323,7 +328,7 @@ public class LuceneChangeIndex implements ChangeIndex, LifecycleListener {
|
||||
private Document toDocument(ChangeData cd) throws IOException {
|
||||
try {
|
||||
Document result = new Document();
|
||||
for (FieldDef<ChangeData, ?> f : ChangeField.ALL.values()) {
|
||||
for (FieldDef<ChangeData, ?> f : fields.getFields().values()) {
|
||||
if (f.isRepeatable()) {
|
||||
add(result, f, (Iterable<?>) f.get(cd, fillArgs));
|
||||
} else {
|
||||
|
@@ -19,6 +19,7 @@ import com.google.gerrit.lifecycle.LifecycleModule;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.config.SitePaths;
|
||||
import com.google.gerrit.server.index.ChangeIndex;
|
||||
import com.google.gerrit.server.index.ChangeSchemas;
|
||||
import com.google.gerrit.server.index.FieldDef.FillArgs;
|
||||
import com.google.gerrit.server.index.IndexExecutor;
|
||||
import com.google.gerrit.server.index.IndexModule;
|
||||
@@ -61,6 +62,7 @@ public class LuceneIndexModule extends LifecycleModule {
|
||||
SitePaths sitePaths,
|
||||
@IndexExecutor ListeningScheduledExecutorService executor,
|
||||
FillArgs fillArgs) throws IOException {
|
||||
return new LuceneChangeIndex(cfg, sitePaths, executor, fillArgs, readOnly);
|
||||
return new LuceneChangeIndex(cfg, sitePaths, executor, fillArgs,
|
||||
ChangeSchemas.getLatestRelease(), readOnly);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user