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:
@@ -34,6 +34,7 @@ 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.IndexRewriteImpl;
|
||||
import com.google.gerrit.server.index.Schema;
|
||||
import com.google.gerrit.server.query.Predicate;
|
||||
@@ -74,6 +75,7 @@ class SolrChangeIndex implements ChangeIndex, LifecycleListener {
|
||||
|
||||
private final FillArgs fillArgs;
|
||||
private final SitePaths sitePaths;
|
||||
private final IndexCollection indexes;
|
||||
private final CloudSolrServer openIndex;
|
||||
private final CloudSolrServer closedIndex;
|
||||
private final Schema<ChangeData> schema;
|
||||
@@ -82,9 +84,11 @@ class SolrChangeIndex implements ChangeIndex, LifecycleListener {
|
||||
@GerritServerConfig Config cfg,
|
||||
FillArgs fillArgs,
|
||||
SitePaths sitePaths,
|
||||
IndexCollection indexes,
|
||||
Schema<ChangeData> schema) throws IOException {
|
||||
this.fillArgs = fillArgs;
|
||||
this.sitePaths = sitePaths;
|
||||
this.indexes = indexes;
|
||||
this.schema = schema;
|
||||
|
||||
String url = cfg.getString("index", "solr", "url");
|
||||
@@ -101,7 +105,8 @@ class SolrChangeIndex implements ChangeIndex, LifecycleListener {
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
// Do nothing.
|
||||
indexes.setSearchIndex(this);
|
||||
indexes.addWriteIndex(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -110,6 +115,11 @@ class SolrChangeIndex implements ChangeIndex, LifecycleListener {
|
||||
closedIndex.shutdown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Schema<ChangeData> getSchema() {
|
||||
return schema;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListenableFuture<Void> insert(ChangeData cd) throws IOException {
|
||||
String id = cd.getId().toString();
|
||||
|
||||
@@ -15,8 +15,19 @@
|
||||
package com.google.gerrit.solr;
|
||||
|
||||
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.IndexCollection;
|
||||
import com.google.gerrit.server.index.IndexModule;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class SolrIndexModule extends LifecycleModule {
|
||||
private final boolean checkVersion;
|
||||
@@ -40,4 +51,14 @@ public class SolrIndexModule extends LifecycleModule {
|
||||
listener().to(IndexVersionCheck.class);
|
||||
}
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public SolrChangeIndex getChangeIndex(@GerritServerConfig Config cfg,
|
||||
SitePaths sitePaths,
|
||||
IndexCollection indexes,
|
||||
FillArgs fillArgs) throws IOException {
|
||||
return new SolrChangeIndex(cfg, fillArgs, sitePaths, indexes,
|
||||
ChangeSchemas.getLatestRelease());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user