Merge pull request #14279 from s1monw/no_guice_on_store

Remove guice injection from IndexStore and friends
This commit is contained in:
Simon Willnauer 2015-10-26 14:08:31 +01:00
commit 21f3cb09c2
17 changed files with 136 additions and 181 deletions

View File

@ -19,7 +19,6 @@
package org.elasticsearch.index;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.inject.util.Providers;
import org.elasticsearch.common.settings.Settings;
@ -29,9 +28,11 @@ import org.elasticsearch.index.fielddata.IndexFieldDataService;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.shard.IndexEventListener;
import org.elasticsearch.index.shard.IndexSearcherWrapper;
import org.elasticsearch.index.store.IndexStore;
import org.elasticsearch.indices.store.IndicesStore;
import java.util.HashSet;
import java.util.Set;
import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Consumer;
/**
@ -39,16 +40,20 @@ import java.util.function.Consumer;
*/
public class IndexModule extends AbstractModule {
public static final String STORE_TYPE = "index.store.type";
private final IndexSettings indexSettings;
private final IndicesStore indicesStore;
// pkg private so tests can mock
Class<? extends EngineFactory> engineFactoryImpl = InternalEngineFactory.class;
Class<? extends IndexSearcherWrapper> indexSearcherWrapper = null;
private final Set<Consumer<Settings>> settingsConsumers = new HashSet<>();
private final Set<IndexEventListener> indexEventListeners = new HashSet<>();
private IndexEventListener listener;
private final Map<String, BiFunction<IndexSettings, IndicesStore, IndexStore>> storeTypes = new HashMap<>();
public IndexModule(IndexSettings indexSettings) {
public IndexModule(IndexSettings indexSettings, IndicesStore indicesStore) {
this.indicesStore = indicesStore;
this.indexSettings = indexSettings;
}
@ -105,6 +110,23 @@ public class IndexModule extends AbstractModule {
this.indexEventListeners.add(listener);
}
/**
* Adds an {@link IndexStore} type to this index module. Typically stores are registered with a refrence 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, BiFunction<IndexSettings, IndicesStore, IndexStore> provider) {
if (storeTypes.containsKey(type)) {
throw new IllegalArgumentException("key [" + type +"] already registerd");
}
storeTypes.put(type, provider);
}
public IndexEventListener freeze() {
// TODO somehow we need to make this pkg private...
if (listener == null) {
@ -113,6 +135,15 @@ public class IndexModule extends AbstractModule {
return listener;
}
private static boolean isBuiltinType(String storeType) {
for (Type type : Type.values()) {
if (type.match(storeType)) {
return true;
}
}
return false;
}
@Override
protected void configure() {
bind(EngineFactory.class).to(engineFactoryImpl).asEagerSingleton();
@ -126,7 +157,41 @@ public class IndexModule extends AbstractModule {
bind(IndexServicesProvider.class).asEagerSingleton();
bind(MapperService.class).asEagerSingleton();
bind(IndexFieldDataService.class).asEagerSingleton();
bind(IndexSettings.class).toInstance(new IndexSettings(indexSettings.getIndexMetaData(), indexSettings.getNodeSettings(), settingsConsumers));
final IndexSettings settings = new IndexSettings(indexSettings.getIndexMetaData(), indexSettings.getNodeSettings(), settingsConsumers);
bind(IndexSettings.class).toInstance(settings);
final String storeType = settings.getSettings().get(STORE_TYPE);
final IndexStore store;
if (storeType == null || isBuiltinType(storeType)) {
store = new IndexStore(settings, indicesStore);
} else {
BiFunction<IndexSettings, IndicesStore, IndexStore> factory = storeTypes.get(storeType);
if (factory == null) {
throw new IllegalArgumentException("Unknown store type [" + storeType + "]");
}
store = factory.apply(settings, indicesStore);
if (store == null) {
throw new IllegalStateException("store must not be null");
}
}
bind(IndexStore.class).toInstance(store);
}
public enum Type {
NIOFS,
MMAPFS,
SIMPLEFS,
FS,
DEFAULT;
public String getSettingsKey() {
return this.name().toLowerCase(Locale.ROOT);
}
/**
* Returns true iff this settings matches the type.
*/
public boolean match(String setting) {
return getSettingsKey().equals(setting);
}
}
}

View File

@ -25,6 +25,7 @@ import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.metrics.CounterMetric;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.set.Sets;
import org.elasticsearch.index.IndexModule;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.shard.ShardPath;
@ -100,18 +101,18 @@ public class FsDirectoryService extends DirectoryService implements StoreRateLim
protected Directory newFSDirectory(Path location, LockFactory lockFactory) throws IOException {
final String storeType = indexSettings.get(IndexStoreModule.STORE_TYPE, IndexStoreModule.Type.DEFAULT.getSettingsKey());
if (IndexStoreModule.Type.FS.match(storeType) || IndexStoreModule.Type.DEFAULT.match(storeType)) {
final String storeType = indexSettings.get(IndexModule.STORE_TYPE, IndexModule.Type.DEFAULT.getSettingsKey());
if (IndexModule.Type.FS.match(storeType) || IndexModule.Type.DEFAULT.match(storeType)) {
final FSDirectory open = FSDirectory.open(location, lockFactory); // use lucene defaults
if (open instanceof MMapDirectory && Constants.WINDOWS == false) {
return newDefaultDir(location, (MMapDirectory) open, lockFactory);
}
return open;
} else if (IndexStoreModule.Type.SIMPLEFS.match(storeType)) {
} else if (IndexModule.Type.SIMPLEFS.match(storeType)) {
return new SimpleFSDirectory(location, lockFactory);
} else if (IndexStoreModule.Type.NIOFS.match(storeType)) {
} else if (IndexModule.Type.NIOFS.match(storeType)) {
return new NIOFSDirectory(location, lockFactory);
} else if (IndexStoreModule.Type.MMAPFS.match(storeType)) {
} else if (IndexModule.Type.MMAPFS.match(storeType)) {
return new MMapDirectory(location, lockFactory);
}
throw new IllegalArgumentException("No directory found for type [" + storeType + "]");

View File

@ -20,7 +20,6 @@
package org.elasticsearch.index.store;
import org.apache.lucene.store.StoreRateLimiting;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.index.AbstractIndexComponent;
@ -43,7 +42,6 @@ public class IndexStore extends AbstractIndexComponent {
private final StoreRateLimiting rateLimiting = new StoreRateLimiting();
@Inject
public IndexStore(IndexSettings indexSettings, IndicesStore indicesStore) {
super(indexSettings);
this.indicesStore = indicesStore;

View File

@ -1,87 +0,0 @@
/*
* 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.index.store;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.settings.Settings;
import java.util.HashMap;
import java.util.Map;
import java.util.Locale;
/**
*
*/
public class IndexStoreModule extends AbstractModule {
public static final String STORE_TYPE = "index.store.type";
private final Settings settings;
private final Map<String, Class<? extends IndexStore>> storeTypes = new HashMap<>();
public enum Type {
NIOFS,
MMAPFS,
SIMPLEFS,
FS,
DEFAULT;
public String getSettingsKey() {
return this.name().toLowerCase(Locale.ROOT);
}
/**
* Returns true iff this settings matches the type.
*/
public boolean match(String setting) {
return getSettingsKey().equals(setting);
}
}
public IndexStoreModule(Settings settings) {
this.settings = settings;
}
public void addIndexStore(String type, Class<? extends IndexStore> clazz) {
storeTypes.put(type, clazz);
}
private static boolean isBuiltinType(String storeType) {
for (Type type : Type.values()) {
if (type.match(storeType)) {
return true;
}
}
return false;
}
@Override
protected void configure() {
final String storeType = settings.get(STORE_TYPE);
if (storeType == null || isBuiltinType(storeType)) {
bind(IndexStore.class).asEagerSingleton();
} else {
Class<? extends IndexStore> clazz = storeTypes.get(storeType);
if (clazz == null) {
throw new IllegalArgumentException("Unknown store type [" + storeType + "]");
}
bind(IndexStore.class).to(clazz).asEagerSingleton();
}
}
}

View File

@ -60,9 +60,9 @@ import org.elasticsearch.index.shard.IndexShard;
import org.elasticsearch.index.shard.IndexEventListener;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.index.similarity.SimilarityModule;
import org.elasticsearch.index.store.IndexStoreModule;
import org.elasticsearch.indices.analysis.IndicesAnalysisService;
import org.elasticsearch.indices.recovery.RecoverySettings;
import org.elasticsearch.indices.store.IndicesStore;
import org.elasticsearch.plugins.PluginsService;
import java.io.Closeable;
@ -77,8 +77,6 @@ import java.util.stream.Stream;
import static java.util.Collections.emptyMap;
import static java.util.Collections.unmodifiableMap;
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS;
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS;
import static org.elasticsearch.common.collect.MapBuilder.newMapBuilder;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.elasticsearch.common.util.CollectionUtils.arrayAsArrayList;
@ -290,6 +288,8 @@ public class IndicesService extends AbstractLifecycleComponent<IndicesService> i
if (!lifecycle.started()) {
throw new IllegalStateException("Can't create an index [" + indexMetaData.getIndex() + "], node is closed");
}
final IndicesStore indicesStore = injector.getInstance(IndicesStore.class); // TODO remove this circular dep!!
final IndexSettings idxSettings = new IndexSettings(indexMetaData, this.settings, Collections.EMPTY_LIST);
Index index = new Index(indexMetaData.getIndex());
if (indices.containsKey(index.name())) {
@ -307,12 +307,11 @@ public class IndicesService extends AbstractLifecycleComponent<IndicesService> i
for (Module pluginModule : pluginsService.indexModules(idxSettings.getSettings())) {
modules.add(pluginModule);
}
final IndexModule indexModule = new IndexModule(idxSettings);
final IndexModule indexModule = new IndexModule(idxSettings, indicesStore);
for (IndexEventListener listener : builtInListeners) {
indexModule.addIndexEventListener(listener);
}
indexModule.addIndexEventListener(oldShardsStats);
modules.add(new IndexStoreModule(idxSettings.getSettings()));
modules.add(new AnalysisModule(idxSettings.getSettings(), indicesAnalysisService));
modules.add(new SimilarityModule(idxSettings));
modules.add(new IndexCacheModule(idxSettings.getSettings()));

View File

@ -42,13 +42,12 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.gateway.AsyncShardFetch;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexModule;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.shard.IndexShard;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.index.shard.ShardPath;
import org.elasticsearch.index.store.IndexStoreModule;
import org.elasticsearch.index.store.Store;
import org.elasticsearch.index.store.StoreFileMetaData;
import org.elasticsearch.indices.IndicesService;
@ -168,7 +167,7 @@ public class TransportNodesListShardStoreMetaData extends TransportNodesAction<T
if (metaData == null) {
return new StoreFilesMetaData(false, shardId, Store.MetadataSnapshot.EMPTY);
}
String storeType = metaData.getSettings().get(IndexStoreModule.STORE_TYPE, "fs");
String storeType = metaData.getSettings().get(IndexModule.STORE_TYPE, "fs");
if (!storeType.contains("fs")) {
return new StoreFilesMetaData(false, shardId, Store.MetadataSnapshot.EMPTY);
}

View File

@ -30,6 +30,8 @@ import org.elasticsearch.index.engine.EngineFactory;
import org.elasticsearch.index.engine.InternalEngineFactory;
import org.elasticsearch.index.shard.IndexEventListener;
import org.elasticsearch.index.shard.IndexSearcherWrapper;
import org.elasticsearch.index.store.IndexStore;
import org.elasticsearch.indices.store.IndicesStore;
import org.elasticsearch.test.IndexSettingsModule;
import org.elasticsearch.test.engine.MockEngineFactory;
@ -43,7 +45,7 @@ public class IndexModuleTests extends ModuleTestCase {
final Index index = new Index("foo");
final Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings, Collections.EMPTY_LIST);
IndexModule module = new IndexModule(indexSettings);
IndexModule module = new IndexModule(indexSettings, null);
assertInstanceBinding(module, IndexSearcherWrapper.class,(x) -> x == null);
module.indexSearcherWrapper = Wrapper.class;
assertBinding(module, IndexSearcherWrapper.class, Wrapper.class);
@ -53,12 +55,27 @@ public class IndexModuleTests extends ModuleTestCase {
final Index index = new Index("foo");
final Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings, Collections.EMPTY_LIST);
IndexModule module = new IndexModule(indexSettings);
IndexModule module = new IndexModule(indexSettings, null);
assertBinding(module, EngineFactory.class, InternalEngineFactory.class);
module.engineFactoryImpl = MockEngineFactory.class;
assertBinding(module, EngineFactory.class, MockEngineFactory.class);
}
public void testRegisterIndexStore() {
final Index index = new Index("foo");
final Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexModule.STORE_TYPE, "foo_store").build();
IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings, Collections.EMPTY_LIST);
IndexModule module = new IndexModule(indexSettings, null);
module.addIndexStore("foo_store", FooStore::new);
assertInstanceBinding(module, IndexStore.class, (x) -> x.getClass() == FooStore.class);
try {
module.addIndexStore("foo_store", FooStore::new);
fail("already registered");
} catch (IllegalArgumentException ex) {
// fine
}
}
public void testOtherServiceBound() {
final AtomicBoolean atomicBoolean = new AtomicBoolean(false);
final IndexEventListener eventListener = new IndexEventListener() {
@ -70,16 +87,20 @@ public class IndexModuleTests extends ModuleTestCase {
final Index index = new Index("foo");
final Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings, Collections.EMPTY_LIST);
IndexModule module = new IndexModule(indexSettings);
IndexModule module = new IndexModule(indexSettings, null);
Consumer<Settings> listener = (s) -> {};
module.addIndexSettingsListener(listener);
module.addIndexEventListener(eventListener);
assertBinding(module, IndexService.class, IndexService.class);
assertBinding(module, IndexServicesProvider.class, IndexServicesProvider.class);
assertInstanceBinding(module, IndexEventListener.class, (x) -> {x.beforeIndexDeleted(null); return atomicBoolean.get();});
assertInstanceBinding(module, IndexEventListener.class, (x) -> {
x.beforeIndexDeleted(null);
return atomicBoolean.get();
});
assertInstanceBinding(module, IndexSettings.class, (x) -> x.getSettings().getAsMap().equals(indexSettings.getSettings().getAsMap()));
assertInstanceBinding(module, IndexSettings.class, (x) -> x.getIndex().equals(indexSettings.getIndex()));
assertInstanceBinding(module, IndexSettings.class, (x) -> x.getUpdateListeners().get(0) == listener);
assertInstanceBinding(module, IndexStore.class, (x) -> x.getClass() == IndexStore.class);
}
@ -87,7 +108,7 @@ public class IndexModuleTests extends ModuleTestCase {
final Index index = new Index("foo");
final Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings, Collections.EMPTY_LIST);
IndexModule module = new IndexModule(indexSettings);
IndexModule module = new IndexModule(indexSettings, null);
Consumer<Settings> listener = (s) -> {
};
module.addIndexSettingsListener(listener);
@ -124,4 +145,11 @@ public class IndexModuleTests extends ModuleTestCase {
}
}
public static final class FooStore extends IndexStore {
public FooStore(IndexSettings indexSettings, IndicesStore indicesStore) {
super(indexSettings, indicesStore);
}
}
}

View File

@ -25,6 +25,7 @@ import org.elasticsearch.Version;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexModule;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.index.shard.ShardPath;
@ -42,9 +43,9 @@ public class IndexStoreTests extends ESTestCase {
public void testStoreDirectory() throws IOException {
final Path tempDir = createTempDir().resolve("foo").resolve("0");
final IndexStoreModule.Type[] values = IndexStoreModule.Type.values();
final IndexStoreModule.Type type = RandomPicks.randomFrom(random(), values);
Settings settings = Settings.settingsBuilder().put(IndexStoreModule.STORE_TYPE, type.name().toLowerCase(Locale.ROOT))
final IndexModule.Type[] values = IndexModule.Type.values();
final IndexModule.Type type = RandomPicks.randomFrom(random(), values);
Settings settings = Settings.settingsBuilder().put(IndexModule.STORE_TYPE, type.name().toLowerCase(Locale.ROOT))
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(new Index("foo"), settings, Collections.EMPTY_LIST);
FsDirectoryService service = new FsDirectoryService(indexSettings, null, new ShardPath(false, tempDir, tempDir, "foo", new ShardId("foo", 0)));

View File

@ -21,7 +21,7 @@ package org.elasticsearch.plugins;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.store.IndexStoreModule;
import org.elasticsearch.index.IndexModule;
import org.elasticsearch.test.ESTestCase;
import java.util.Arrays;
@ -38,7 +38,7 @@ public class PluginsServiceTests extends ESTestCase {
}
@Override
public Settings additionalSettings() {
return Settings.builder().put("foo.bar", "1").put(IndexStoreModule.STORE_TYPE, IndexStoreModule.Type.MMAPFS.getSettingsKey()).build();
return Settings.builder().put("foo.bar", "1").put(IndexModule.STORE_TYPE, IndexModule.Type.MMAPFS.getSettingsKey()).build();
}
}
public static class AdditionalSettingsPlugin2 extends Plugin {
@ -64,12 +64,12 @@ public class PluginsServiceTests extends ESTestCase {
Settings settings = Settings.builder()
.put("path.home", createTempDir())
.put("my.setting", "test")
.put(IndexStoreModule.STORE_TYPE, IndexStoreModule.Type.SIMPLEFS.getSettingsKey()).build();
.put(IndexModule.STORE_TYPE, IndexModule.Type.SIMPLEFS.getSettingsKey()).build();
PluginsService service = newPluginsService(settings, AdditionalSettingsPlugin1.class);
Settings newSettings = service.updatedSettings();
assertEquals("test", newSettings.get("my.setting")); // previous settings still exist
assertEquals("1", newSettings.get("foo.bar")); // added setting exists
assertEquals(IndexStoreModule.Type.SIMPLEFS.getSettingsKey(), newSettings.get(IndexStoreModule.STORE_TYPE)); // does not override pre existing settings
assertEquals(IndexModule.Type.SIMPLEFS.getSettingsKey(), newSettings.get(IndexModule.STORE_TYPE)); // does not override pre existing settings
}
public void testAdditionalSettingsClash() {

View File

@ -33,16 +33,15 @@ import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexModule;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.shard.*;
import org.elasticsearch.index.store.FsDirectoryService;
import org.elasticsearch.index.store.IndexStore;
import org.elasticsearch.index.store.IndexStoreModule;
import org.elasticsearch.index.store.Store;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.IndexSettingsModule;
import org.junit.Assert;
import java.io.Closeable;
@ -63,13 +62,12 @@ public class MockFSDirectoryService extends FsDirectoryService {
private final double randomIOExceptionRate;
private final double randomIOExceptionRateOnOpen;
private final MockDirectoryWrapper.Throttling throttle;
private final Settings indexSettings;
private final boolean preventDoubleWrite;
private final boolean noDeleteOpenFile;
private final boolean crashIndex;
@Inject
public MockFSDirectoryService(IndexSettings idxSettings, IndexStore indexStore, final IndicesService service, final ShardPath path) {
public MockFSDirectoryService(IndexSettings idxSettings, IndexStore indexStore, final ShardPath path) {
super(idxSettings, indexStore, path);
Settings indexSettings = idxSettings.getSettings();
final long seed = indexSettings.getAsLong(ESIntegTestCase.SETTING_INDEX_SEED, 0l);
@ -87,7 +85,6 @@ public class MockFSDirectoryService extends FsDirectoryService {
logger.debug("Using MockDirWrapper with seed [{}] throttle: [{}] crashIndex: [{}]", SeedUtils.formatSeed(seed),
throttle, crashIndex);
}
this.indexSettings = indexSettings;
delegateService = randomDirectorService(indexStore, path);
}
@ -175,7 +172,7 @@ public class MockFSDirectoryService extends FsDirectoryService {
private FsDirectoryService randomDirectorService(IndexStore indexStore, ShardPath path) {
final IndexSettings indexSettings = indexStore.getIndexSettings();
final IndexMetaData build = IndexMetaData.builder(indexSettings.getIndexMetaData()).settings(Settings.builder().put(indexSettings.getSettings()).put(IndexStoreModule.STORE_TYPE, RandomPicks.randomFrom(random, IndexStoreModule.Type.values()).getSettingsKey())).build();
final IndexMetaData build = IndexMetaData.builder(indexSettings.getIndexMetaData()).settings(Settings.builder().put(indexSettings.getSettings()).put(IndexModule.STORE_TYPE, RandomPicks.randomFrom(random, IndexModule.Type.values()).getSettingsKey())).build();
final IndexSettings newIndexSettings = new IndexSettings(build, indexSettings.getNodeSettings(), Collections.EMPTY_LIST);
return new FsDirectoryService(newIndexSettings, indexStore, path);
}

View File

@ -21,7 +21,6 @@ package org.elasticsearch.test.store;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
@ -30,8 +29,6 @@ import org.elasticsearch.index.IndexModule;
import org.elasticsearch.index.shard.*;
import org.elasticsearch.index.store.DirectoryService;
import org.elasticsearch.index.store.IndexStore;
import org.elasticsearch.index.store.IndexStoreModule;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.indices.store.IndicesStore;
import org.elasticsearch.plugins.Plugin;
@ -40,7 +37,6 @@ import java.util.*;
public class MockFSIndexStore extends IndexStore {
public static final String CHECK_INDEX_ON_CLOSE = "index.store.mock.check_index_on_close";
private final IndicesService indicesService;
public static class TestPlugin extends Plugin {
@Override
@ -51,33 +47,29 @@ public class MockFSIndexStore extends IndexStore {
public String description() {
return "a mock index store for testing";
}
public void onModule(IndexStoreModule indexStoreModule) {
indexStoreModule.addIndexStore("mock", MockFSIndexStore.class);
}
@Override
public Settings additionalSettings() {
return Settings.builder().put(IndexStoreModule.STORE_TYPE, "mock").build();
return Settings.builder().put(IndexModule.STORE_TYPE, "mock").build();
}
public void onModule(IndexModule module) {
Settings indexSettings = module.getSettings();
if ("mock".equals(indexSettings.get(IndexStoreModule.STORE_TYPE))) {
if ("mock".equals(indexSettings.get(IndexModule.STORE_TYPE))) {
if (indexSettings.getAsBoolean(CHECK_INDEX_ON_CLOSE, true)) {
module.addIndexEventListener(new Listener());
}
module.addIndexStore("mock", MockFSIndexStore::new);
}
}
}
@Inject
public MockFSIndexStore(IndexSettings indexSettings,
IndicesStore indicesStore, IndicesService indicesService) {
MockFSIndexStore(IndexSettings indexSettings,
IndicesStore indicesStore) {
super(indexSettings, indicesStore);
this.indicesService = indicesService;
}
public DirectoryService newDirectoryService(ShardPath path) {
return new MockFSDirectoryService(indexSettings, this, indicesService, path);
return new MockFSDirectoryService(indexSettings, this, path);
}
private static final EnumSet<IndexShardState> validCheckIndexStates = EnumSet.of(

View File

@ -1,32 +0,0 @@
/*
* 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.test.store;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.index.store.IndexStore;
public class MockFSIndexStoreModule extends AbstractModule {
@Override
protected void configure() {
bind(IndexStore.class).to(MockFSIndexStore.class).asEagerSingleton();
}
}

View File

@ -34,7 +34,6 @@ import java.nio.file.Path;
public class SmbMmapFsDirectoryService extends FsDirectoryService {
@Inject
public SmbMmapFsDirectoryService(IndexSettings indexSettings, IndexStore indexStore, ShardPath path) {
super(indexSettings, indexStore, path);
}

View File

@ -19,7 +19,6 @@
package org.elasticsearch.index.store.smbmmapfs;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.shard.ShardPath;
import org.elasticsearch.index.store.DirectoryService;
@ -28,7 +27,6 @@ import org.elasticsearch.indices.store.IndicesStore;
public class SmbMmapFsIndexStore extends IndexStore {
@Inject
public SmbMmapFsIndexStore(IndexSettings indexSettings, IndicesStore indicesStore) {
super(indexSettings, indicesStore);
}

View File

@ -23,7 +23,6 @@ import org.apache.lucene.store.Directory;
import org.apache.lucene.store.LockFactory;
import org.apache.lucene.store.SimpleFSDirectory;
import org.apache.lucene.store.SmbDirectoryWrapper;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.shard.ShardPath;
import org.elasticsearch.index.store.FsDirectoryService;
@ -34,7 +33,6 @@ import java.nio.file.Path;
public class SmbSimpleFsDirectoryService extends FsDirectoryService {
@Inject
public SmbSimpleFsDirectoryService(IndexSettings indexSettings, IndexStore indexStore, ShardPath path) {
super(indexSettings, indexStore, path);
}

View File

@ -19,7 +19,6 @@
package org.elasticsearch.index.store.smbsimplefs;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.shard.ShardPath;
import org.elasticsearch.index.store.DirectoryService;
@ -28,7 +27,6 @@ import org.elasticsearch.indices.store.IndicesStore;
public class SmbSimpleFsIndexStore extends IndexStore {
@Inject
public SmbSimpleFsIndexStore(IndexSettings indexSettings, IndicesStore indicesStore) {
super(indexSettings, indicesStore);
}

View File

@ -19,6 +19,7 @@
package org.elasticsearch.plugin.store.smb;
import org.elasticsearch.index.IndexModule;
import org.elasticsearch.index.store.IndexStoreModule;
import org.elasticsearch.index.store.smbmmapfs.SmbMmapFsIndexStore;
import org.elasticsearch.index.store.smbsimplefs.SmbSimpleFsIndexStore;
@ -36,8 +37,8 @@ public class SMBStorePlugin extends Plugin {
return "SMB Store Plugin";
}
public void onModule(IndexStoreModule storeModule) {
storeModule.addIndexStore("smb_mmap_fs", SmbMmapFsIndexStore.class);
storeModule.addIndexStore("smb_simple_fs", SmbSimpleFsIndexStore.class);
public void onModule(IndexModule storeModule) {
storeModule.addIndexStore("smb_mmap_fs", SmbMmapFsIndexStore::new);
storeModule.addIndexStore("smb_simple_fs", SmbSimpleFsIndexStore::new);
}
}