Merge branch 'stable-2.14' into stable-2.15
* stable-2.14: ElasticTestUtils: also reuse index name constants Change default elasticsearch prefix to gerrit_ Fix init with elasticsearch and companion reindex ElasticChangeIndex: reuse change index name string Change-Id: Ic36572111501cae21a09dde364342d14a177fdfc
This commit is contained in:
@@ -60,6 +60,7 @@ abstract class AbstractElasticIndex<K, V> implements Index<K, V> {
|
||||
|
||||
private final Schema<V> schema;
|
||||
private final SitePaths sitePaths;
|
||||
private final String indexNameRaw;
|
||||
|
||||
protected final String indexName;
|
||||
protected final JestHttpClient client;
|
||||
@@ -78,10 +79,11 @@ abstract class AbstractElasticIndex<K, V> implements Index<K, V> {
|
||||
this.queryBuilder = new ElasticQueryBuilder();
|
||||
this.indexName =
|
||||
String.format(
|
||||
"%s%s%04d",
|
||||
"%s%s_%04d",
|
||||
Strings.nullToEmpty(cfg.getString("elasticsearch", null, "prefix")),
|
||||
indexName,
|
||||
schema.getVersion());
|
||||
this.indexNameRaw = indexName;
|
||||
this.client = clientBuilder.build();
|
||||
}
|
||||
|
||||
@@ -97,7 +99,7 @@ abstract class AbstractElasticIndex<K, V> implements Index<K, V> {
|
||||
|
||||
@Override
|
||||
public void markReady(boolean ready) throws IOException {
|
||||
IndexUtils.setReady(sitePaths, indexName, schema.getVersion(), ready);
|
||||
IndexUtils.setReady(sitePaths, indexNameRaw, schema.getVersion(), ready);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -69,7 +69,6 @@ public class ElasticAccountIndex extends AbstractElasticIndex<Account.Id, Accoun
|
||||
}
|
||||
|
||||
static final String ACCOUNTS = "accounts";
|
||||
static final String ACCOUNTS_PREFIX = ACCOUNTS + "_";
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ElasticAccountIndex.class);
|
||||
|
||||
@@ -83,7 +82,7 @@ public class ElasticAccountIndex extends AbstractElasticIndex<Account.Id, Accoun
|
||||
Provider<AccountCache> accountCache,
|
||||
JestClientBuilder clientBuilder,
|
||||
@Assisted Schema<AccountState> schema) {
|
||||
super(cfg, sitePaths, schema, clientBuilder, ACCOUNTS_PREFIX);
|
||||
super(cfg, sitePaths, schema, clientBuilder, ACCOUNTS);
|
||||
this.accountCache = accountCache;
|
||||
this.mapping = new AccountMapping(schema);
|
||||
}
|
||||
|
@@ -92,9 +92,9 @@ 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";
|
||||
static final String CHANGES = "changes";
|
||||
static final String OPEN_CHANGES = "open_" + CHANGES;
|
||||
static final String CLOSED_CHANGES = "closed_" + CHANGES;
|
||||
|
||||
private final ChangeMapping mapping;
|
||||
private final Provider<ReviewDb> db;
|
||||
@@ -108,7 +108,7 @@ class ElasticChangeIndex extends AbstractElasticIndex<Change.Id, ChangeData>
|
||||
SitePaths sitePaths,
|
||||
JestClientBuilder clientBuilder,
|
||||
@Assisted Schema<ChangeData> schema) {
|
||||
super(cfg, sitePaths, schema, clientBuilder, CHANGES_PREFIX);
|
||||
super(cfg, sitePaths, schema, clientBuilder, CHANGES);
|
||||
this.db = db;
|
||||
this.changeDataFactory = changeDataFactory;
|
||||
mapping = new ChangeMapping(schema);
|
||||
@@ -134,7 +134,7 @@ class ElasticChangeIndex extends AbstractElasticIndex<Change.Id, ChangeData>
|
||||
Bulk bulk =
|
||||
new Bulk.Builder()
|
||||
.defaultIndex(indexName)
|
||||
.defaultType("changes")
|
||||
.defaultType(CHANGES)
|
||||
.addAction(insert(insertIndex, cd))
|
||||
.addAction(delete(deleteIndex, cd.getId()))
|
||||
.refresh(true)
|
||||
|
@@ -68,7 +68,6 @@ public class ElasticGroupIndex extends AbstractElasticIndex<AccountGroup.UUID, I
|
||||
}
|
||||
|
||||
static final String GROUPS = "groups";
|
||||
static final String GROUPS_PREFIX = GROUPS + "_";
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ElasticGroupIndex.class);
|
||||
|
||||
@@ -82,7 +81,7 @@ public class ElasticGroupIndex extends AbstractElasticIndex<AccountGroup.UUID, I
|
||||
Provider<GroupCache> groupCache,
|
||||
JestClientBuilder clientBuilder,
|
||||
@Assisted Schema<InternalGroup> schema) {
|
||||
super(cfg, sitePaths, schema, clientBuilder, GROUPS_PREFIX);
|
||||
super(cfg, sitePaths, schema, clientBuilder, GROUPS);
|
||||
this.groupCache = groupCache;
|
||||
this.mapping = new GroupMapping(schema);
|
||||
}
|
||||
|
@@ -53,20 +53,10 @@ public class ElasticVersionManager extends VersionManager {
|
||||
prefix = MoreObjects.firstNonNull(cfg.getString("index", null, "prefix"), "gerrit");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <V> boolean isDirty(Collection<Version<V>> inUse, Version<V> v) {
|
||||
return !inUse.contains(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <K, V, I extends Index<K, V>> TreeMap<Integer, Version<V>> scanVersions(
|
||||
IndexDefinition<K, V, I> def, GerritIndexStatus cfg) {
|
||||
TreeMap<Integer, Version<V>> versions = new TreeMap<>();
|
||||
for (Schema<V> schema : def.getSchemas().values()) {
|
||||
int v = schema.getVersion();
|
||||
versions.put(v, new Version<>(schema, v, cfg.getReady(def.getName(), v)));
|
||||
}
|
||||
|
||||
try {
|
||||
for (String version : versionDiscovery.discover(prefix, def.getName())) {
|
||||
Integer v = Ints.tryParse(version);
|
||||
@@ -74,13 +64,17 @@ public class ElasticVersionManager extends VersionManager {
|
||||
log.warn("Unrecognized version in index {}: {}", def.getName(), version);
|
||||
continue;
|
||||
}
|
||||
if (!versions.containsKey(v)) {
|
||||
versions.put(v, new Version<V>(null, v, cfg.getReady(def.getName(), v)));
|
||||
}
|
||||
versions.put(v, new Version<V>(null, v, true, cfg.getReady(def.getName(), v)));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("Error scanning index: " + def.getName(), e);
|
||||
}
|
||||
|
||||
for (Schema<V> schema : def.getSchemas().values()) {
|
||||
int v = schema.getVersion();
|
||||
boolean exists = versions.containsKey(v);
|
||||
versions.put(v, new Version<>(schema, v, exists, cfg.getReady(def.getName(), v)));
|
||||
}
|
||||
return versions;
|
||||
}
|
||||
}
|
||||
|
@@ -15,11 +15,11 @@
|
||||
package com.google.gerrit.elasticsearch;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.gerrit.elasticsearch.ElasticAccountIndex.ACCOUNTS_PREFIX;
|
||||
import static com.google.gerrit.elasticsearch.ElasticChangeIndex.CHANGES_PREFIX;
|
||||
import static com.google.gerrit.elasticsearch.ElasticAccountIndex.ACCOUNTS;
|
||||
import static com.google.gerrit.elasticsearch.ElasticChangeIndex.CHANGES;
|
||||
import static com.google.gerrit.elasticsearch.ElasticChangeIndex.CLOSED_CHANGES;
|
||||
import static com.google.gerrit.elasticsearch.ElasticChangeIndex.OPEN_CHANGES;
|
||||
import static com.google.gerrit.elasticsearch.ElasticGroupIndex.GROUPS_PREFIX;
|
||||
import static com.google.gerrit.elasticsearch.ElasticGroupIndex.GROUPS;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.io.Files;
|
||||
@@ -128,7 +128,7 @@ final class ElasticTestUtils {
|
||||
.client()
|
||||
.admin()
|
||||
.indices()
|
||||
.prepareCreate(String.format("%s%04d", CHANGES_PREFIX, changeSchema.getVersion()))
|
||||
.prepareCreate(String.format("%s_%04d", CHANGES, changeSchema.getVersion()))
|
||||
.addMapping(OPEN_CHANGES, gson.toJson(openChangesMapping))
|
||||
.addMapping(CLOSED_CHANGES, gson.toJson(closedChangesMapping))
|
||||
.execute()
|
||||
@@ -141,7 +141,7 @@ final class ElasticTestUtils {
|
||||
.client()
|
||||
.admin()
|
||||
.indices()
|
||||
.prepareCreate(String.format("%s%04d", ACCOUNTS_PREFIX, accountSchema.getVersion()))
|
||||
.prepareCreate(String.format("%s_%04d", ACCOUNTS, accountSchema.getVersion()))
|
||||
.addMapping(ElasticAccountIndex.ACCOUNTS, gson.toJson(accountMapping))
|
||||
.execute()
|
||||
.actionGet();
|
||||
@@ -153,7 +153,7 @@ final class ElasticTestUtils {
|
||||
.client()
|
||||
.admin()
|
||||
.indices()
|
||||
.prepareCreate(String.format("%s%04d", GROUPS_PREFIX, groupSchema.getVersion()))
|
||||
.prepareCreate(String.format("%s_%04d", GROUPS, groupSchema.getVersion()))
|
||||
.addMapping(ElasticGroupIndex.GROUPS, gson.toJson(groupMapping))
|
||||
.execute()
|
||||
.actionGet();
|
||||
|
Reference in New Issue
Block a user