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:
@@ -17,7 +17,7 @@ package com.google.gerrit.solr;
|
||||
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;
|
||||
|
||||
@@ -31,8 +31,8 @@ import java.util.Map;
|
||||
|
||||
class IndexVersionCheck implements LifecycleListener {
|
||||
public static final Map<String, Integer> SCHEMA_VERSIONS = ImmutableMap.of(
|
||||
SolrChangeIndex.CHANGES_OPEN, ChangeField.SCHEMA_VERSION,
|
||||
SolrChangeIndex.CHANGES_CLOSED, ChangeField.SCHEMA_VERSION);
|
||||
SolrChangeIndex.CHANGES_OPEN, ChangeSchemas.getLatestRelease().getVersion(),
|
||||
SolrChangeIndex.CHANGES_CLOSED, ChangeSchemas.getLatestRelease().getVersion());
|
||||
|
||||
public static File solrIndexConfig(SitePaths sitePaths) {
|
||||
return new File(sitePaths.index_dir, "gerrit_index.config");
|
||||
|
||||
@@ -35,13 +35,13 @@ 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;
|
||||
import com.google.gerrit.server.query.change.ChangeDataSource;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.ResultSet;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import org.apache.lucene.search.Query;
|
||||
@@ -76,14 +76,16 @@ class SolrChangeIndex implements ChangeIndex, LifecycleListener {
|
||||
private final SitePaths sitePaths;
|
||||
private final CloudSolrServer openIndex;
|
||||
private final CloudSolrServer closedIndex;
|
||||
private final Schema<ChangeData> schema;
|
||||
|
||||
@Inject
|
||||
SolrChangeIndex(
|
||||
@GerritServerConfig Config cfg,
|
||||
FillArgs fillArgs,
|
||||
SitePaths sitePaths) throws IOException {
|
||||
SitePaths sitePaths,
|
||||
Schema<ChangeData> schema) throws IOException {
|
||||
this.fillArgs = fillArgs;
|
||||
this.sitePaths = sitePaths;
|
||||
this.schema = schema;
|
||||
|
||||
String url = cfg.getString("index", "solr", "url");
|
||||
if (Strings.isNullOrEmpty(url)) {
|
||||
@@ -270,7 +272,7 @@ class SolrChangeIndex implements ChangeIndex, LifecycleListener {
|
||||
private SolrInputDocument toDocument(ChangeData cd) throws IOException {
|
||||
try {
|
||||
SolrInputDocument result = new SolrInputDocument();
|
||||
for (FieldDef<ChangeData, ?> f : ChangeField.ALL.values()) {
|
||||
for (FieldDef<ChangeData, ?> f : schema.getFields().values()) {
|
||||
if (f.isRepeatable()) {
|
||||
add(result, f, (Iterable<?>) f.get(cd, fillArgs));
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user