Introduce index store plugins (#32375)
Today we allow plugins to add index store implementations yet we are not doing this in our new way of managing plugins as pull versus push. That is, today we still allow plugins to push index store providers via an on index module call where they can turn around and add an index store. Aside from being inconsistent with how we manage plugins today where we would look to pull such implementations from plugins at node creation time, it also means that we do not know at a top-level (for example, in the indices service) which index stores are available. This commit addresses this by adding a dedicated plugin type for index store plugins, removing the index module hook for adding index stores, and by aggregating these into the top-level of the indices service.
This commit is contained in:
parent
bec888fa78
commit
eb675a1c4d
|
@ -19,16 +19,26 @@
|
|||
|
||||
package org.elasticsearch.plugin.store.smb;
|
||||
|
||||
import org.elasticsearch.index.IndexModule;
|
||||
import org.elasticsearch.index.IndexSettings;
|
||||
import org.elasticsearch.index.store.IndexStore;
|
||||
import org.elasticsearch.index.store.smbmmapfs.SmbMmapFsIndexStore;
|
||||
import org.elasticsearch.index.store.smbsimplefs.SmbSimpleFsIndexStore;
|
||||
import org.elasticsearch.plugins.IndexStorePlugin;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
|
||||
public class SMBStorePlugin extends Plugin {
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class SMBStorePlugin extends Plugin implements IndexStorePlugin {
|
||||
|
||||
@Override
|
||||
public void onIndexModule(IndexModule indexModule) {
|
||||
indexModule.addIndexStore("smb_mmap_fs", SmbMmapFsIndexStore::new);
|
||||
indexModule.addIndexStore("smb_simple_fs", SmbSimpleFsIndexStore::new);
|
||||
public Map<String, Function<IndexSettings, IndexStore>> getIndexStoreFactories() {
|
||||
final Map<String, Function<IndexSettings, IndexStore>> indexStoreFactories = new HashMap<>(2);
|
||||
indexStoreFactories.put("smb_mmap_fs", SmbMmapFsIndexStore::new);
|
||||
indexStoreFactories.put("smb_simple_fs", SmbSimpleFsIndexStore::new);
|
||||
return Collections.unmodifiableMap(indexStoreFactories);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ import org.elasticsearch.indices.IndicesQueryCache;
|
|||
import org.elasticsearch.indices.breaker.CircuitBreakerService;
|
||||
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
|
||||
import org.elasticsearch.indices.mapper.MapperRegistry;
|
||||
import org.elasticsearch.plugins.IndexStorePlugin;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
|
||||
|
@ -74,7 +75,7 @@ import java.util.function.Function;
|
|||
* {@link #addSimilarity(String, TriFunction)} while existing Providers can be referenced through Settings under the
|
||||
* {@link IndexModule#SIMILARITY_SETTINGS_PREFIX} prefix along with the "type" value. For example, to reference the
|
||||
* {@link BM25Similarity}, the configuration {@code "index.similarity.my_similarity.type : "BM25"} can be used.</li>
|
||||
* <li>{@link IndexStore} - Custom {@link IndexStore} instances can be registered via {@link #addIndexStore(String, Function)}</li>
|
||||
* <li>{@link IndexStore} - Custom {@link IndexStore} instances can be registered via {@link IndexStorePlugin}</li>
|
||||
* <li>{@link IndexEventListener} - Custom {@link IndexEventListener} instances can be registered via
|
||||
* {@link #addIndexEventListener(IndexEventListener)}</li>
|
||||
* <li>Settings update listener - Custom settings update listener can be registered via
|
||||
|
@ -109,7 +110,7 @@ public final class IndexModule {
|
|||
private SetOnce<IndexSearcherWrapperFactory> indexSearcherWrapper = new SetOnce<>();
|
||||
private final Set<IndexEventListener> indexEventListeners = new HashSet<>();
|
||||
private final Map<String, TriFunction<Settings, Version, ScriptService, Similarity>> similarities = new HashMap<>();
|
||||
private final Map<String, Function<IndexSettings, IndexStore>> storeTypes = new HashMap<>();
|
||||
private final Map<String, Function<IndexSettings, IndexStore>> indexStoreFactories;
|
||||
private final SetOnce<BiFunction<IndexSettings, IndicesQueryCache, QueryCache>> forceQueryCacheProvider = new SetOnce<>();
|
||||
private final List<SearchOperationListener> searchOperationListeners = new ArrayList<>();
|
||||
private final List<IndexingOperationListener> indexOperationListeners = new ArrayList<>();
|
||||
|
@ -119,16 +120,22 @@ public final class IndexModule {
|
|||
* Construct the index module for the index with the specified index settings. The index module contains extension points for plugins
|
||||
* via {@link org.elasticsearch.plugins.PluginsService#onIndexModule(IndexModule)}.
|
||||
*
|
||||
* @param indexSettings the index settings
|
||||
* @param analysisRegistry the analysis registry
|
||||
* @param engineFactory the engine factory
|
||||
* @param indexSettings the index settings
|
||||
* @param analysisRegistry the analysis registry
|
||||
* @param engineFactory the engine factory
|
||||
* @param indexStoreFactories the available store types
|
||||
*/
|
||||
public IndexModule(final IndexSettings indexSettings, final AnalysisRegistry analysisRegistry, final EngineFactory engineFactory) {
|
||||
public IndexModule(
|
||||
final IndexSettings indexSettings,
|
||||
final AnalysisRegistry analysisRegistry,
|
||||
final EngineFactory engineFactory,
|
||||
final Map<String, Function<IndexSettings, IndexStore>> indexStoreFactories) {
|
||||
this.indexSettings = indexSettings;
|
||||
this.analysisRegistry = analysisRegistry;
|
||||
this.engineFactory = Objects.requireNonNull(engineFactory);
|
||||
this.searchOperationListeners.add(new SearchSlowLog(indexSettings));
|
||||
this.indexOperationListeners.add(new IndexingSlowLog(indexSettings));
|
||||
this.indexStoreFactories = Collections.unmodifiableMap(indexStoreFactories);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -245,25 +252,6 @@ public final class IndexModule {
|
|||
this.indexOperationListeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an {@link IndexStore} type to this index module. Typically stores are registered with a reference to
|
||||
* it's constructor:
|
||||
* <pre>
|
||||
* indexModule.addIndexStore("my_store_type", MyStore::new);
|
||||
* </pre>
|
||||
*
|
||||
* @param type the type to register
|
||||
* @param provider the instance provider / factory method
|
||||
*/
|
||||
public void addIndexStore(String type, Function<IndexSettings, IndexStore> provider) {
|
||||
ensureNotFrozen();
|
||||
if (storeTypes.containsKey(type)) {
|
||||
throw new IllegalArgumentException("key [" + type +"] already registered");
|
||||
}
|
||||
storeTypes.put(type, provider);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Registers the given {@link Similarity} with the given name.
|
||||
* The function takes as parameters:<ul>
|
||||
|
@ -360,7 +348,7 @@ public final class IndexModule {
|
|||
if (Strings.isEmpty(storeType) || isBuiltinType(storeType)) {
|
||||
store = new IndexStore(indexSettings);
|
||||
} else {
|
||||
Function<IndexSettings, IndexStore> factory = storeTypes.get(storeType);
|
||||
Function<IndexSettings, IndexStore> factory = indexStoreFactories.get(storeType);
|
||||
if (factory == null) {
|
||||
throw new IllegalArgumentException("Unknown store type [" + storeType + "]");
|
||||
}
|
||||
|
|
|
@ -100,6 +100,7 @@ import org.elasticsearch.index.shard.IndexShardState;
|
|||
import org.elasticsearch.index.shard.IndexingOperationListener;
|
||||
import org.elasticsearch.index.shard.IndexingStats;
|
||||
import org.elasticsearch.index.shard.ShardId;
|
||||
import org.elasticsearch.index.store.IndexStore;
|
||||
import org.elasticsearch.indices.breaker.CircuitBreakerService;
|
||||
import org.elasticsearch.indices.cluster.IndicesClusterStateService;
|
||||
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
|
||||
|
@ -181,6 +182,7 @@ public class IndicesService extends AbstractLifecycleComponent
|
|||
private final IndicesQueryCache indicesQueryCache;
|
||||
private final MetaStateService metaStateService;
|
||||
private final Collection<Function<IndexSettings, Optional<EngineFactory>>> engineFactoryProviders;
|
||||
private final Map<String, Function<IndexSettings, IndexStore>> indexStoreFactories;
|
||||
|
||||
@Override
|
||||
protected void doStart() {
|
||||
|
@ -193,7 +195,8 @@ public class IndicesService extends AbstractLifecycleComponent
|
|||
MapperRegistry mapperRegistry, NamedWriteableRegistry namedWriteableRegistry, ThreadPool threadPool,
|
||||
IndexScopedSettings indexScopedSettings, CircuitBreakerService circuitBreakerService, BigArrays bigArrays,
|
||||
ScriptService scriptService, Client client, MetaStateService metaStateService,
|
||||
Collection<Function<IndexSettings, Optional<EngineFactory>>> engineFactoryProviders) {
|
||||
Collection<Function<IndexSettings, Optional<EngineFactory>>> engineFactoryProviders,
|
||||
Map<String, Function<IndexSettings, IndexStore>> indexStoreFactories) {
|
||||
super(settings);
|
||||
this.threadPool = threadPool;
|
||||
this.pluginsService = pluginsService;
|
||||
|
@ -225,6 +228,7 @@ public class IndicesService extends AbstractLifecycleComponent
|
|||
this.cacheCleaner = new CacheCleaner(indicesFieldDataCache, indicesRequestCache, logger, threadPool, this.cleanInterval);
|
||||
this.metaStateService = metaStateService;
|
||||
this.engineFactoryProviders = engineFactoryProviders;
|
||||
this.indexStoreFactories = indexStoreFactories;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -464,7 +468,7 @@ public class IndicesService extends AbstractLifecycleComponent
|
|||
idxSettings.getNumberOfReplicas(),
|
||||
reason);
|
||||
|
||||
final IndexModule indexModule = new IndexModule(idxSettings, analysisRegistry, getEngineFactory(idxSettings));
|
||||
final IndexModule indexModule = new IndexModule(idxSettings, analysisRegistry, getEngineFactory(idxSettings), indexStoreFactories);
|
||||
for (IndexingOperationListener operationListener : indexingOperationListeners) {
|
||||
indexModule.addIndexOperationListener(operationListener);
|
||||
}
|
||||
|
@ -524,7 +528,7 @@ public class IndicesService extends AbstractLifecycleComponent
|
|||
*/
|
||||
public synchronized MapperService createIndexMapperService(IndexMetaData indexMetaData) throws IOException {
|
||||
final IndexSettings idxSettings = new IndexSettings(indexMetaData, this.settings, indexScopedSettings);
|
||||
final IndexModule indexModule = new IndexModule(idxSettings, analysisRegistry, getEngineFactory(idxSettings));
|
||||
final IndexModule indexModule = new IndexModule(idxSettings, analysisRegistry, getEngineFactory(idxSettings), indexStoreFactories);
|
||||
pluginsService.onIndexModule(indexModule);
|
||||
return indexModule.newIndexMapperService(xContentRegistry, mapperRegistry, scriptService);
|
||||
}
|
||||
|
|
|
@ -26,8 +26,8 @@ import org.elasticsearch.Build;
|
|||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.ElasticsearchTimeoutException;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.ActionModule;
|
||||
import org.elasticsearch.action.Action;
|
||||
import org.elasticsearch.action.ActionModule;
|
||||
import org.elasticsearch.action.search.SearchExecutionStatsCollector;
|
||||
import org.elasticsearch.action.search.SearchPhaseController;
|
||||
import org.elasticsearch.action.search.SearchTransportService;
|
||||
|
@ -94,6 +94,7 @@ import org.elasticsearch.http.HttpServerTransport;
|
|||
import org.elasticsearch.index.IndexSettings;
|
||||
import org.elasticsearch.index.analysis.AnalysisRegistry;
|
||||
import org.elasticsearch.index.engine.EngineFactory;
|
||||
import org.elasticsearch.index.store.IndexStore;
|
||||
import org.elasticsearch.indices.IndicesModule;
|
||||
import org.elasticsearch.indices.IndicesService;
|
||||
import org.elasticsearch.indices.analysis.AnalysisModule;
|
||||
|
@ -117,6 +118,7 @@ import org.elasticsearch.plugins.AnalysisPlugin;
|
|||
import org.elasticsearch.plugins.ClusterPlugin;
|
||||
import org.elasticsearch.plugins.DiscoveryPlugin;
|
||||
import org.elasticsearch.plugins.EnginePlugin;
|
||||
import org.elasticsearch.plugins.IndexStorePlugin;
|
||||
import org.elasticsearch.plugins.IngestPlugin;
|
||||
import org.elasticsearch.plugins.MapperPlugin;
|
||||
import org.elasticsearch.plugins.MetaDataUpgrader;
|
||||
|
@ -407,11 +409,19 @@ public class Node implements Closeable {
|
|||
enginePlugins.stream().map(plugin -> plugin::getEngineFactory))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
||||
final Map<String, Function<IndexSettings, IndexStore>> indexStoreFactories =
|
||||
pluginsService.filterPlugins(IndexStorePlugin.class)
|
||||
.stream()
|
||||
.map(IndexStorePlugin::getIndexStoreFactories)
|
||||
.flatMap(m -> m.entrySet().stream())
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
|
||||
final IndicesService indicesService =
|
||||
new IndicesService(settings, pluginsService, nodeEnvironment, xContentRegistry, analysisModule.getAnalysisRegistry(),
|
||||
clusterModule.getIndexNameExpressionResolver(), indicesModule.getMapperRegistry(), namedWriteableRegistry,
|
||||
threadPool, settingsModule.getIndexScopedSettings(), circuitBreakerService, bigArrays,
|
||||
scriptModule.getScriptService(), client, metaStateService, engineFactoryProviders);
|
||||
scriptModule.getScriptService(), client, metaStateService, engineFactoryProviders, indexStoreFactories);
|
||||
|
||||
|
||||
Collection<Object> pluginComponents = pluginsService.filterPlugins(Plugin.class).stream()
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you 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 org.elasticsearch.plugins;
|
||||
|
||||
import org.elasticsearch.index.IndexSettings;
|
||||
import org.elasticsearch.index.store.IndexStore;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* A plugin that provides alternative index store implementations.
|
||||
*/
|
||||
public interface IndexStorePlugin {
|
||||
|
||||
/**
|
||||
* The index store factories for this plugin. When an index is created the store type setting
|
||||
* {@link org.elasticsearch.index.IndexModule#INDEX_STORE_TYPE_SETTING} on the index will be examined and either use the default or a
|
||||
* built-in type, or looked up among all the index store factories from {@link IndexStore} plugins.
|
||||
*
|
||||
* @return a map from store type to an index store factory
|
||||
*/
|
||||
Map<String, Function<IndexSettings, IndexStore>> getIndexStoreFactories();
|
||||
|
||||
}
|
|
@ -81,10 +81,13 @@ import org.elasticsearch.threadpool.ThreadPool;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
|
||||
public class IndexModuleTests extends ESTestCase {
|
||||
private Index index;
|
||||
|
@ -147,7 +150,8 @@ public class IndexModuleTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testWrapperIsBound() throws IOException {
|
||||
IndexModule module = new IndexModule(indexSettings, emptyAnalysisRegistry, new MockEngineFactory(AssertingDirectoryReader.class));
|
||||
final MockEngineFactory engineFactory = new MockEngineFactory(AssertingDirectoryReader.class);
|
||||
IndexModule module = new IndexModule(indexSettings, emptyAnalysisRegistry, engineFactory, Collections.emptyMap());
|
||||
module.setSearcherWrapper((s) -> new Wrapper());
|
||||
|
||||
IndexService indexService = newIndexService(module);
|
||||
|
@ -164,18 +168,12 @@ public class IndexModuleTests extends ESTestCase {
|
|||
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
|
||||
.put(IndexModule.INDEX_STORE_TYPE_SETTING.getKey(), "foo_store")
|
||||
.build();
|
||||
IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings);
|
||||
IndexModule module = new IndexModule(indexSettings, emptyAnalysisRegistry, new InternalEngineFactory());
|
||||
module.addIndexStore("foo_store", FooStore::new);
|
||||
try {
|
||||
module.addIndexStore("foo_store", FooStore::new);
|
||||
fail("already registered");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// fine
|
||||
}
|
||||
final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings);
|
||||
final Map<String, Function<IndexSettings, IndexStore>> indexStoreFactories = Collections.singletonMap("foo_store", FooStore::new);
|
||||
final IndexModule module = new IndexModule(indexSettings, emptyAnalysisRegistry, new InternalEngineFactory(), indexStoreFactories);
|
||||
|
||||
IndexService indexService = newIndexService(module);
|
||||
assertTrue(indexService.getIndexStore() instanceof FooStore);
|
||||
final IndexService indexService = newIndexService(module);
|
||||
assertThat(indexService.getIndexStore(), instanceOf(FooStore.class));
|
||||
|
||||
indexService.close("simon says", false);
|
||||
}
|
||||
|
@ -189,7 +187,7 @@ public class IndexModuleTests extends ESTestCase {
|
|||
}
|
||||
};
|
||||
IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings);
|
||||
IndexModule module = new IndexModule(indexSettings, emptyAnalysisRegistry, new InternalEngineFactory());
|
||||
IndexModule module = new IndexModule(indexSettings, emptyAnalysisRegistry, new InternalEngineFactory(), Collections.emptyMap());
|
||||
module.addIndexEventListener(eventListener);
|
||||
IndexService indexService = newIndexService(module);
|
||||
IndexSettings x = indexService.getIndexSettings();
|
||||
|
@ -204,7 +202,7 @@ public class IndexModuleTests extends ESTestCase {
|
|||
public void testListener() throws IOException {
|
||||
Setting<Boolean> booleanSetting = Setting.boolSetting("index.foo.bar", false, Property.Dynamic, Property.IndexScope);
|
||||
final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings, booleanSetting);
|
||||
IndexModule module = new IndexModule(indexSettings, emptyAnalysisRegistry, new InternalEngineFactory());
|
||||
IndexModule module = new IndexModule(indexSettings, emptyAnalysisRegistry, new InternalEngineFactory(), Collections.emptyMap());
|
||||
Setting<Boolean> booleanSetting2 = Setting.boolSetting("index.foo.bar.baz", false, Property.Dynamic, Property.IndexScope);
|
||||
AtomicBoolean atomicBoolean = new AtomicBoolean(false);
|
||||
module.addSettingsUpdateConsumer(booleanSetting, atomicBoolean::set);
|
||||
|
@ -223,8 +221,8 @@ public class IndexModuleTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testAddIndexOperationListener() throws IOException {
|
||||
IndexModule module =
|
||||
new IndexModule(IndexSettingsModule.newIndexSettings(index, settings), emptyAnalysisRegistry, new InternalEngineFactory());
|
||||
final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings);
|
||||
IndexModule module = new IndexModule(indexSettings, emptyAnalysisRegistry, new InternalEngineFactory(), Collections.emptyMap());
|
||||
AtomicBoolean executed = new AtomicBoolean(false);
|
||||
IndexingOperationListener listener = new IndexingOperationListener() {
|
||||
@Override
|
||||
|
@ -254,8 +252,8 @@ public class IndexModuleTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testAddSearchOperationListener() throws IOException {
|
||||
IndexModule module =
|
||||
new IndexModule(IndexSettingsModule.newIndexSettings(index, settings), emptyAnalysisRegistry, new InternalEngineFactory());
|
||||
final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings);
|
||||
IndexModule module = new IndexModule(indexSettings, emptyAnalysisRegistry, new InternalEngineFactory(), Collections.emptyMap());
|
||||
AtomicBoolean executed = new AtomicBoolean(false);
|
||||
SearchOperationListener listener = new SearchOperationListener() {
|
||||
|
||||
|
@ -288,8 +286,9 @@ public class IndexModuleTests extends ESTestCase {
|
|||
.put("index.similarity.my_similarity.key", "there is a key")
|
||||
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
|
||||
.build();
|
||||
final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("foo", settings);
|
||||
IndexModule module =
|
||||
new IndexModule(IndexSettingsModule.newIndexSettings("foo", settings), emptyAnalysisRegistry, new InternalEngineFactory());
|
||||
new IndexModule(indexSettings, emptyAnalysisRegistry, new InternalEngineFactory(), Collections.emptyMap());
|
||||
module.addSimilarity("test_similarity",
|
||||
(providerSettings, indexCreatedVersion, scriptService) -> new TestSimilarity(providerSettings.get("key")));
|
||||
|
||||
|
@ -303,8 +302,8 @@ public class IndexModuleTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testFrozen() {
|
||||
IndexModule module =
|
||||
new IndexModule(IndexSettingsModule.newIndexSettings(index, settings), emptyAnalysisRegistry, new InternalEngineFactory());
|
||||
final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings);
|
||||
IndexModule module = new IndexModule(indexSettings, emptyAnalysisRegistry, new InternalEngineFactory(), Collections.emptyMap());
|
||||
module.freeze();
|
||||
String msg = "Can't modify IndexModule once the index service has been created";
|
||||
assertEquals(msg, expectThrows(IllegalStateException.class, () -> module.addSearchOperationListener(null)).getMessage());
|
||||
|
@ -313,7 +312,6 @@ public class IndexModuleTests extends ESTestCase {
|
|||
assertEquals(msg, expectThrows(IllegalStateException.class, () -> module.addSimilarity(null, null)).getMessage());
|
||||
assertEquals(msg, expectThrows(IllegalStateException.class, () -> module.setSearcherWrapper(null)).getMessage());
|
||||
assertEquals(msg, expectThrows(IllegalStateException.class, () -> module.forceQueryCacheProvider(null)).getMessage());
|
||||
assertEquals(msg, expectThrows(IllegalStateException.class, () -> module.addIndexStore("foo", null)).getMessage());
|
||||
}
|
||||
|
||||
public void testSetupUnknownSimilarity() throws IOException {
|
||||
|
@ -322,8 +320,9 @@ public class IndexModuleTests extends ESTestCase {
|
|||
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
|
||||
.build();
|
||||
final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("foo", settings);
|
||||
IndexModule module =
|
||||
new IndexModule(IndexSettingsModule.newIndexSettings("foo", settings), emptyAnalysisRegistry, new InternalEngineFactory());
|
||||
new IndexModule(indexSettings, emptyAnalysisRegistry, new InternalEngineFactory(), Collections.emptyMap());
|
||||
Exception ex = expectThrows(IllegalArgumentException.class, () -> newIndexService(module));
|
||||
assertEquals("Unknown Similarity type [test_similarity] for [my_similarity]", ex.getMessage());
|
||||
}
|
||||
|
@ -334,8 +333,8 @@ public class IndexModuleTests extends ESTestCase {
|
|||
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
|
||||
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||
.build();
|
||||
IndexModule module =
|
||||
new IndexModule(IndexSettingsModule.newIndexSettings("foo", settings), emptyAnalysisRegistry, new InternalEngineFactory());
|
||||
final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("foo", settings);
|
||||
IndexModule module = new IndexModule(indexSettings, emptyAnalysisRegistry, new InternalEngineFactory(), Collections.emptyMap());
|
||||
Exception ex = expectThrows(IllegalArgumentException.class, () -> newIndexService(module));
|
||||
assertEquals("Similarity [my_similarity] must have an associated type", ex.getMessage());
|
||||
}
|
||||
|
@ -344,8 +343,8 @@ public class IndexModuleTests extends ESTestCase {
|
|||
Settings settings = Settings.builder()
|
||||
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
|
||||
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
|
||||
IndexModule module =
|
||||
new IndexModule(IndexSettingsModule.newIndexSettings("foo", settings), emptyAnalysisRegistry, new InternalEngineFactory());
|
||||
final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("foo", settings);
|
||||
IndexModule module = new IndexModule(indexSettings, emptyAnalysisRegistry, new InternalEngineFactory(), Collections.emptyMap());
|
||||
module.forceQueryCacheProvider((a, b) -> new CustomQueryCache());
|
||||
expectThrows(AlreadySetException.class, () -> module.forceQueryCacheProvider((a, b) -> new CustomQueryCache()));
|
||||
IndexService indexService = newIndexService(module);
|
||||
|
@ -357,8 +356,8 @@ public class IndexModuleTests extends ESTestCase {
|
|||
Settings settings = Settings.builder()
|
||||
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
|
||||
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
|
||||
IndexModule module =
|
||||
new IndexModule(IndexSettingsModule.newIndexSettings("foo", settings), emptyAnalysisRegistry, new InternalEngineFactory());
|
||||
final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("foo", settings);
|
||||
IndexModule module = new IndexModule(indexSettings, emptyAnalysisRegistry, new InternalEngineFactory(), Collections.emptyMap());
|
||||
IndexService indexService = newIndexService(module);
|
||||
assertTrue(indexService.cache().query() instanceof IndexQueryCache);
|
||||
indexService.close("simon says", false);
|
||||
|
@ -369,8 +368,8 @@ public class IndexModuleTests extends ESTestCase {
|
|||
.put(IndexModule.INDEX_QUERY_CACHE_ENABLED_SETTING.getKey(), false)
|
||||
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
|
||||
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
|
||||
IndexModule module =
|
||||
new IndexModule(IndexSettingsModule.newIndexSettings("foo", settings), emptyAnalysisRegistry, new InternalEngineFactory());
|
||||
final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("foo", settings);
|
||||
IndexModule module = new IndexModule(indexSettings, emptyAnalysisRegistry, new InternalEngineFactory(), Collections.emptyMap());
|
||||
module.forceQueryCacheProvider((a, b) -> new CustomQueryCache());
|
||||
IndexService indexService = newIndexService(module);
|
||||
assertTrue(indexService.cache().query() instanceof DisabledQueryCache);
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you 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 org.elasticsearch.plugins;
|
||||
|
||||
import org.elasticsearch.bootstrap.JavaVersion;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.IndexSettings;
|
||||
import org.elasticsearch.index.store.IndexStore;
|
||||
import org.elasticsearch.node.MockNode;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static org.elasticsearch.test.hamcrest.RegexMatcher.matches;
|
||||
import static org.hamcrest.Matchers.hasToString;
|
||||
|
||||
public class IndexStorePluginTests extends ESTestCase {
|
||||
|
||||
public static class BarStorePlugin extends Plugin implements IndexStorePlugin {
|
||||
|
||||
@Override
|
||||
public Map<String, Function<IndexSettings, IndexStore>> getIndexStoreFactories() {
|
||||
return Collections.singletonMap("store", IndexStore::new);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class FooStorePlugin extends Plugin implements IndexStorePlugin {
|
||||
|
||||
@Override
|
||||
public Map<String, Function<IndexSettings, IndexStore>> getIndexStoreFactories() {
|
||||
return Collections.singletonMap("store", IndexStore::new);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void testDuplicateIndexStoreProviders() {
|
||||
final Settings settings = Settings.builder().put("path.home", createTempDir()).build();
|
||||
final IllegalStateException e = expectThrows(
|
||||
IllegalStateException.class, () -> new MockNode(settings, Arrays.asList(BarStorePlugin.class, FooStorePlugin.class)));
|
||||
if (JavaVersion.current().compareTo(JavaVersion.parse("9")) >= 0) {
|
||||
assertThat(e, hasToString(matches(
|
||||
"java.lang.IllegalStateException: Duplicate key store \\(attempted merging values " +
|
||||
"org.elasticsearch.plugins.IndexStorePluginTests\\$BarStorePlugin.* " +
|
||||
"and org.elasticsearch.plugins.IndexStorePluginTests\\$FooStorePlugin.*\\)")));
|
||||
} else {
|
||||
assertThat(e, hasToString(matches(
|
||||
"java.lang.IllegalStateException: Duplicate key org.elasticsearch.plugins.IndexStorePluginTests\\$BarStorePlugin.*")));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -34,6 +34,7 @@ import org.elasticsearch.index.shard.ShardId;
|
|||
import org.elasticsearch.index.shard.ShardPath;
|
||||
import org.elasticsearch.index.store.DirectoryService;
|
||||
import org.elasticsearch.index.store.IndexStore;
|
||||
import org.elasticsearch.plugins.IndexStorePlugin;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
@ -42,13 +43,14 @@ import java.util.EnumSet;
|
|||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class MockFSIndexStore extends IndexStore {
|
||||
|
||||
public static final Setting<Boolean> INDEX_CHECK_INDEX_ON_CLOSE_SETTING =
|
||||
Setting.boolSetting("index.store.mock.check_index_on_close", true, Property.IndexScope, Property.NodeScope);
|
||||
|
||||
public static class TestPlugin extends Plugin {
|
||||
public static class TestPlugin extends Plugin implements IndexStorePlugin {
|
||||
@Override
|
||||
public Settings additionalSettings() {
|
||||
return Settings.builder().put(IndexModule.INDEX_STORE_TYPE_SETTING.getKey(), "mock").build();
|
||||
|
@ -64,6 +66,11 @@ public class MockFSIndexStore extends IndexStore {
|
|||
MockFSDirectoryService.RANDOM_IO_EXCEPTION_RATE_ON_OPEN_SETTING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Function<IndexSettings, IndexStore>> getIndexStoreFactories() {
|
||||
return Collections.singletonMap("mock", MockFSIndexStore::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onIndexModule(IndexModule indexModule) {
|
||||
Settings indexSettings = indexModule.getSettings();
|
||||
|
@ -71,7 +78,6 @@ public class MockFSIndexStore extends IndexStore {
|
|||
if (INDEX_CHECK_INDEX_ON_CLOSE_SETTING.get(indexSettings)) {
|
||||
indexModule.addIndexEventListener(new Listener());
|
||||
}
|
||||
indexModule.addIndexStore("mock", MockFSIndexStore::new);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.elasticsearch.threadpool.ExecutorBuilder;
|
|||
import org.elasticsearch.xpack.core.watcher.watch.Watch;
|
||||
import org.elasticsearch.xpack.watcher.notification.NotificationService;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Collections.emptyMap;
|
||||
|
@ -74,7 +75,7 @@ public class WatcherPluginTests extends ESTestCase {
|
|||
IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(Watch.INDEX, settings);
|
||||
AnalysisRegistry registry = new AnalysisRegistry(TestEnvironment.newEnvironment(settings), emptyMap(), emptyMap(), emptyMap(),
|
||||
emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap());
|
||||
IndexModule indexModule = new IndexModule(indexSettings, registry, new InternalEngineFactory());
|
||||
IndexModule indexModule = new IndexModule(indexSettings, registry, new InternalEngineFactory(), Collections.emptyMap());
|
||||
// this will trip an assertion if the watcher indexing operation listener is null (which it is) but we try to add it
|
||||
watcher.onIndexModule(indexModule);
|
||||
|
||||
|
|
Loading…
Reference in New Issue