Name Elasticsearch indexes the same way it's done for Lucene
Change index is now named 'changes_0001' instead of 'gerrit'. This will enable to have other indexes like the accounts index and multiple versions to support online reindexing. The only difference is Elasticsearch allows to prefix the index name to allow to have use more than one Gerrit server in the same Elasticsearch server. Prefix 'gerrit1_' would result in a change index named 'gerrit1_changes_0001'. Change-Id: I9d089b6a0ce0e708a59e1f322ea1c011f78ffd31
This commit is contained in:
@@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.elasticsearch;
|
||||
|
||||
import static com.google.common.base.MoreObjects.firstNonNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
|
||||
@@ -47,7 +46,6 @@ import io.searchbox.indices.DeleteIndex;
|
||||
import io.searchbox.indices.IndicesExists;
|
||||
|
||||
abstract class AbstractElasticIndex<K, V> implements Index<K, V> {
|
||||
private static final String DEFAULT_INDEX_NAME = "gerrit";
|
||||
|
||||
private final Schema<V> schema;
|
||||
private final FillArgs fillArgs;
|
||||
@@ -61,7 +59,8 @@ abstract class AbstractElasticIndex<K, V> implements Index<K, V> {
|
||||
AbstractElasticIndex(@GerritServerConfig Config cfg,
|
||||
FillArgs fillArgs,
|
||||
SitePaths sitePaths,
|
||||
Schema<V> schema) {
|
||||
Schema<V> schema,
|
||||
String indexName) {
|
||||
this.fillArgs = fillArgs;
|
||||
this.sitePaths = sitePaths;
|
||||
this.schema = schema;
|
||||
@@ -69,8 +68,10 @@ abstract class AbstractElasticIndex<K, V> implements Index<K, V> {
|
||||
String hostname = getRequiredConfigOption(cfg, "hostname");
|
||||
String port = getRequiredConfigOption(cfg, "port");
|
||||
|
||||
this.indexName =
|
||||
firstNonNull(cfg.getString("index", null, "name"), DEFAULT_INDEX_NAME);
|
||||
this.indexName = String.format("%s%s%04d",
|
||||
Strings.nullToEmpty(cfg.getString("index", null, "prefix")),
|
||||
indexName,
|
||||
schema.getVersion());
|
||||
|
||||
// By default Elasticsearch has a 1s delay before changes are available in
|
||||
// the index. Setting refresh(true) on calls to the index makes the index
|
||||
|
||||
@@ -121,6 +121,7 @@ class ElasticChangeIndex extends AbstractElasticIndex<Change.Id, ChangeData>
|
||||
}
|
||||
}
|
||||
|
||||
static final String CHANGES_PREFIX = "changes_";
|
||||
static final String OPEN_CHANGES = "open_changes";
|
||||
static final String CLOSED_CHANGES = "closed_changes";
|
||||
|
||||
@@ -138,7 +139,7 @@ class ElasticChangeIndex extends AbstractElasticIndex<Change.Id, ChangeData>
|
||||
FillArgs fillArgs,
|
||||
SitePaths sitePaths,
|
||||
@Assisted Schema<ChangeData> schema) {
|
||||
super(cfg, fillArgs, sitePaths, schema);
|
||||
super(cfg, fillArgs, sitePaths, schema, CHANGES_PREFIX);
|
||||
this.db = db;
|
||||
this.changeDataFactory = changeDataFactory;
|
||||
mapping = new ChangeMapping(schema);
|
||||
|
||||
Reference in New Issue
Block a user