IndexType: Add tested support for custom index type

As custom index types are supported -and required by, e.g., Google. Not
covering that case used to break the latter, thus required urgent fixes.
Before this change, breaking that case sometimes went unnoticed at code
review hence merge time. Make IndexType consider any non-lucene and
(non-)elasticsearch index type as "custom".

Custom only means that the index type has a String value that differs
from both of the two explicitly known type values ("lucene" and
"elasticsearch"). Google is likely configuring a specific index type
String value, albeit undisclosed externally. This is treated here as a
(the) 'custom' index type.

Adapt Daemon to not throw IllegalStateException anymore if such a custom
index type gets configured, by, e.g., the added CustomIndexIT test. This
test fails otherwise, indeed. The value of this added test is deemed
superior to the potential loss of Daemon's initIndexType() robustness.

Use lucene as default "custom" index type module for testing purposes.

Change-Id: I805222fb3c40917b294e78b1110d0f45e9878f7c
This commit is contained in:
Marco Miller
2019-09-30 15:12:57 -04:00
parent 7f59a74905
commit 4c2c9ea113
4 changed files with 46 additions and 11 deletions

View File

@@ -18,6 +18,15 @@ import com.google.common.collect.ImmutableSet;
import com.google.gerrit.common.Nullable;
import org.eclipse.jgit.lib.Config;
/**
* Index types supported by the secondary index.
*
* <p>The explicitly known index types are Lucene (the default) and Elasticsearch.
*
* <p>The third supported index type is any other type String value, deemed as custom. This is for
* configuring index types that are internal or not to be disclosed. Supporting custom index types
* allows to not break that case upon core implementation changes.
*/
public class IndexType {
private static final String LUCENE = "lucene";
private static final String ELASTICSEARCH = "elasticsearch";

View File

@@ -327,7 +327,7 @@ public class Daemon extends SiteProgram {
}
cfgInjector = createCfgInjector();
config = cfgInjector.getInstance(Key.get(Config.class, GerritServerConfig.class));
initIndexType();
indexType = IndexModule.getIndexType(cfgInjector);
sysInjector = createSysInjector();
sysInjector.getInstance(PluginGuiceEnvironment.class).setDbCfgInjector(dbInjector, cfgInjector);
manager.add(dbInjector, cfgInjector, sysInjector);
@@ -498,13 +498,6 @@ public class Daemon extends SiteProgram {
throw new IllegalStateException("unsupported index.type = " + indexType);
}
private void initIndexType() {
indexType = IndexModule.getIndexType(cfgInjector);
if (!indexType.isLucene() && !indexType.isElasticsearch()) {
throw new IllegalStateException("unsupported index.type = " + indexType);
}
}
private void initSshd() {
sshInjector = createSshInjector();
sysInjector.getInstance(PluginGuiceEnvironment.class).setSshInjector(sshInjector);

View File

@@ -227,10 +227,11 @@ public class InMemoryModule extends FactoryModule {
IndexType indexType = new IndexType(cfg.getString("index", null, "type"));
// For custom index types, callers must provide their own module.
if (indexType.isLucene()) {
install(luceneIndexModule());
} else if (indexType.isElasticsearch()) {
if (indexType.isElasticsearch()) {
install(elasticIndexModule());
} else {
// Also the default "custom" module for testing.
install(luceneIndexModule());
}
bind(ServerInformationImpl.class);
bind(ServerInformation.class).to(ServerInformationImpl.class);

View File

@@ -0,0 +1,32 @@
// Copyright (C) 2019 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.acceptance.ssh;
import com.google.gerrit.testing.ConfigSuite;
import com.google.inject.Injector;
import org.eclipse.jgit.lib.Config;
public class CustomIndexIT extends AbstractIndexTests {
@ConfigSuite.Default
public static Config customIndexType() {
Config config = new Config();
config.setString("index", null, "type", "custom");
return config;
}
@Override
public void configureIndex(Injector injector) throws Exception {}
}