Bind index versions dynamically
We want to support a single index version for reading and multiple index versions for writing. Wrap these in an IndexCollection with getSearchIndex and getWriteIndexes methods. Still bind a single implementation at startup. Change-Id: Ibc4dbbeba064cde68f2585126d7708db5a2b3410
This commit is contained in:
@@ -28,12 +28,15 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.common.util.concurrent.ListeningScheduledExecutorService;
|
||||
import com.google.gerrit.extensions.events.LifecycleListener;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.config.SitePaths;
|
||||
import com.google.gerrit.server.index.ChangeField;
|
||||
import com.google.gerrit.server.index.ChangeIndex;
|
||||
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.IndexCollection;
|
||||
import com.google.gerrit.server.index.IndexExecutor;
|
||||
import com.google.gerrit.server.index.IndexRewriteImpl;
|
||||
import com.google.gerrit.server.index.Schema;
|
||||
import com.google.gerrit.server.query.Predicate;
|
||||
@@ -112,30 +115,38 @@ public class LuceneChangeIndex implements ChangeIndex, LifecycleListener {
|
||||
|
||||
private final SitePaths sitePaths;
|
||||
private final FillArgs fillArgs;
|
||||
private final IndexCollection indexes;
|
||||
private final ExecutorService executor;
|
||||
private final boolean readOnly;
|
||||
private final Schema<ChangeData> fields;
|
||||
private final Schema<ChangeData> schema;
|
||||
private final SubIndex openIndex;
|
||||
private final SubIndex closedIndex;
|
||||
private final boolean readOnly;
|
||||
|
||||
LuceneChangeIndex(Config cfg, SitePaths sitePaths,
|
||||
ListeningScheduledExecutorService executor, FillArgs fillArgs,
|
||||
Schema<ChangeData> fields, boolean readOnly) throws IOException {
|
||||
LuceneChangeIndex(@GerritServerConfig Config cfg,
|
||||
SitePaths sitePaths,
|
||||
IndexCollection indexes,
|
||||
@IndexExecutor ListeningScheduledExecutorService executor,
|
||||
FillArgs fillArgs,
|
||||
Schema<ChangeData> schema,
|
||||
boolean readOnly) throws IOException {
|
||||
this.indexes = indexes;
|
||||
this.sitePaths = sitePaths;
|
||||
this.fillArgs = fillArgs;
|
||||
this.executor = executor;
|
||||
this.schema = schema;
|
||||
this.readOnly = readOnly;
|
||||
this.fields = fields;
|
||||
|
||||
File dir = new File(sitePaths.index_dir, "changes_" + fields.getVersion());
|
||||
File dir = new File(sitePaths.index_dir, "changes_" + schema.getVersion());
|
||||
openIndex = new SubIndex(new File(dir, CHANGES_OPEN),
|
||||
getIndexWriterConfig(cfg, "changes_open"));
|
||||
closedIndex = new SubIndex(new File(dir, CHANGES_CLOSED),
|
||||
getIndexWriterConfig(cfg, "changes_closed"));
|
||||
getIndexWriterConfig(cfg, "changes_closed"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
indexes.setSearchIndex(this);
|
||||
indexes.addWriteIndex(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -158,6 +169,11 @@ public class LuceneChangeIndex implements ChangeIndex, LifecycleListener {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Schema<ChangeData> getSchema() {
|
||||
return schema;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public ListenableFuture<Void> insert(ChangeData cd) throws IOException {
|
||||
@@ -328,7 +344,7 @@ public class LuceneChangeIndex implements ChangeIndex, LifecycleListener {
|
||||
private Document toDocument(ChangeData cd) throws IOException {
|
||||
try {
|
||||
Document result = new Document();
|
||||
for (FieldDef<ChangeData, ?> f : fields.getFields().values()) {
|
||||
for (FieldDef<ChangeData, ?> f : schema.getFields().values()) {
|
||||
if (f.isRepeatable()) {
|
||||
add(result, f, (Iterable<?>) f.get(cd, fillArgs));
|
||||
} else {
|
||||
|
@@ -21,6 +21,7 @@ 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.IndexCollection;
|
||||
import com.google.gerrit.server.index.IndexExecutor;
|
||||
import com.google.gerrit.server.index.IndexModule;
|
||||
import com.google.inject.Provides;
|
||||
@@ -60,9 +61,10 @@ public class LuceneIndexModule extends LifecycleModule {
|
||||
@Singleton
|
||||
public LuceneChangeIndex getChangeIndex(@GerritServerConfig Config cfg,
|
||||
SitePaths sitePaths,
|
||||
IndexCollection indexes,
|
||||
@IndexExecutor ListeningScheduledExecutorService executor,
|
||||
FillArgs fillArgs) throws IOException {
|
||||
return new LuceneChangeIndex(cfg, sitePaths, executor, fillArgs,
|
||||
return new LuceneChangeIndex(cfg, sitePaths, indexes, executor, fillArgs,
|
||||
ChangeSchemas.getLatestRelease(), readOnly);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user