diff --git a/core/src/main/java/org/elasticsearch/index/IndexService.java b/core/src/main/java/org/elasticsearch/index/IndexService.java index f3c330a182b3..b48b2aedeae2 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexService.java +++ b/core/src/main/java/org/elasticsearch/index/IndexService.java @@ -260,6 +260,9 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone if (closed.get()) { throw new IllegalStateException("Can't create shard [" + index.name() + "][" + sShardId + "], closed"); } + if (indexSettings.get("index.translog.type") != null) { // TODO remove? + throw new IllegalStateException("a custom translog type is no longer supported. got [" + indexSettings.get("index.translog.type") + "]"); + } final ShardId shardId = new ShardId(index, sShardId); ShardLock lock = null; boolean success = false; @@ -313,7 +316,7 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone (primary && IndexMetaData.isOnSharedFilesystem(indexSettings)); IndexStore indexStore = injector.getInstance(IndexStore.class); store = new Store(shardId, indexSettings, indexStore.newDirectoryService(path), lock, new StoreCloseListener(shardId, canDeleteShardContent, () -> injector.getInstance(IndicesQueryCache.class).onClose(shardId))); - if (primary && IndexMetaData.isIndexUsingShadowReplicas(indexSettings)) { + if (useShadowEngine(primary, indexSettings)) { indexShard = new ShadowIndexShard(shardId, indexSettings, path, store, injector.getInstance(IndexServicesProvider.class)); } else { indexShard = new IndexShard(shardId, indexSettings, path, store, injector.getInstance(IndexServicesProvider.class)); @@ -338,6 +341,10 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone } } + static boolean useShadowEngine(boolean primary, Settings indexSettings) { + return primary == false && IndexMetaData.isIndexUsingShadowReplicas(indexSettings); + } + public synchronized void removeShard(int shardId, String reason) { final ShardId sId = new ShardId(index, shardId); final Injector shardInjector; diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexShardModule.java b/core/src/main/java/org/elasticsearch/index/shard/IndexShardModule.java deleted file mode 100644 index 2d97eea08d6b..000000000000 --- a/core/src/main/java/org/elasticsearch/index/shard/IndexShardModule.java +++ /dev/null @@ -1,62 +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.shard; - -import org.elasticsearch.cluster.metadata.IndexMetaData; -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.settings.Settings; - -/** - * The {@code IndexShardModule} module is responsible for binding the correct - * shard id, index shard, engine factory, and warming service for a newly - * created shard. - */ -public class IndexShardModule extends AbstractModule { - - private final ShardId shardId; - private final Settings settings; - private final boolean primary; - - - - public IndexShardModule(ShardId shardId, boolean primary, Settings settings) { - this.settings = settings; - this.shardId = shardId; - this.primary = primary; - if (settings.get("index.translog.type") != null) { - throw new IllegalStateException("a custom translog type is no longer supported. got [" + settings.get("index.translog.type") + "]"); - } - } - - /** Return true if a shadow engine should be used */ - protected boolean useShadowEngine() { - return primary == false && IndexMetaData.isIndexUsingShadowReplicas(settings); - } - - @Override - protected void configure() { - bind(ShardId.class).toInstance(shardId); - if (useShadowEngine()) { - bind(IndexShard.class).to(ShadowIndexShard.class).asEagerSingleton(); - } else { - bind(IndexShard.class).asEagerSingleton(); - } - } -} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/index/store/IndexStore.java b/core/src/main/java/org/elasticsearch/index/store/IndexStore.java index 350eb7a0d81f..3a23a09a6528 100644 --- a/core/src/main/java/org/elasticsearch/index/store/IndexStore.java +++ b/core/src/main/java/org/elasticsearch/index/store/IndexStore.java @@ -116,5 +116,4 @@ public class IndexStore extends AbstractIndexComponent implements Closeable { public DirectoryService newDirectoryService(ShardPath path) { return new FsDirectoryService(indexSettings, this, path); } - } diff --git a/core/src/main/java/org/elasticsearch/plugins/Plugin.java b/core/src/main/java/org/elasticsearch/plugins/Plugin.java index 04f789e5c346..4229c54401ac 100644 --- a/core/src/main/java/org/elasticsearch/plugins/Plugin.java +++ b/core/src/main/java/org/elasticsearch/plugins/Plugin.java @@ -73,13 +73,6 @@ public abstract class Plugin { return Collections.emptyList(); } - /** - * Per index shard service that will be automatically closed. - */ - public Collection> shardServices() { - return Collections.emptyList(); - } - /** * Additional node settings loaded by the plugin. Note that settings that are explicit in the nodes settings can't be * overwritten with the additional settings. These settings added if they don't exist. diff --git a/core/src/main/java/org/elasticsearch/plugins/PluginsService.java b/core/src/main/java/org/elasticsearch/plugins/PluginsService.java index cd71fdbc7859..9582d3f1714a 100644 --- a/core/src/main/java/org/elasticsearch/plugins/PluginsService.java +++ b/core/src/main/java/org/elasticsearch/plugins/PluginsService.java @@ -250,14 +250,6 @@ public class PluginsService extends AbstractComponent { return services; } - public Collection> shardServices() { - List> services = new ArrayList<>(); - for (Tuple plugin : plugins) { - services.addAll(plugin.v2().shardServices()); - } - return services; - } - /** * Get information about plugins (jvm and site plugins). */ diff --git a/core/src/test/java/org/elasticsearch/index/shard/IndexShardModuleTests.java b/core/src/test/java/org/elasticsearch/index/IndexServiceTests.java similarity index 67% rename from core/src/test/java/org/elasticsearch/index/shard/IndexShardModuleTests.java rename to core/src/test/java/org/elasticsearch/index/IndexServiceTests.java index e488905710a6..7d66382440a9 100644 --- a/core/src/test/java/org/elasticsearch/index/shard/IndexShardModuleTests.java +++ b/core/src/test/java/org/elasticsearch/index/IndexServiceTests.java @@ -17,19 +17,19 @@ * under the License. */ -package org.elasticsearch.index.shard; +package org.elasticsearch.index; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.test.ESTestCase; import org.junit.Test; -/** Unit test(s) for IndexShardModule */ -public class IndexShardModuleTests extends ESTestCase { +/** Unit test(s) for IndexService */ +public class IndexServiceTests extends ESTestCase { @Test public void testDetermineShadowEngineShouldBeUsed() { - ShardId shardId = new ShardId("myindex", 0); Settings regularSettings = Settings.builder() .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 2) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1) @@ -41,14 +41,9 @@ public class IndexShardModuleTests extends ESTestCase { .put(IndexMetaData.SETTING_SHADOW_REPLICAS, true) .build(); - IndexShardModule ism1 = new IndexShardModule(shardId, true, regularSettings); - IndexShardModule ism2 = new IndexShardModule(shardId, false, regularSettings); - IndexShardModule ism3 = new IndexShardModule(shardId, true, shadowSettings); - IndexShardModule ism4 = new IndexShardModule(shardId, false, shadowSettings); - - assertFalse("no shadow replicas for normal settings", ism1.useShadowEngine()); - assertFalse("no shadow replicas for normal settings", ism2.useShadowEngine()); - assertFalse("no shadow replicas for primary shard with shadow settings", ism3.useShadowEngine()); - assertTrue("shadow replicas for replica shards with shadow settings", ism4.useShadowEngine()); + assertFalse("no shadow replicas for normal settings", IndexService.useShadowEngine(true, regularSettings)); + assertFalse("no shadow replicas for normal settings", IndexService.useShadowEngine(false, regularSettings)); + assertFalse("no shadow replicas for primary shard with shadow settings", IndexService.useShadowEngine(true, shadowSettings)); + assertTrue("shadow replicas for replica shards with shadow settings",IndexService.useShadowEngine(false, shadowSettings)); } } diff --git a/plugins/jvm-example/src/main/java/org/elasticsearch/plugin/example/JvmExamplePlugin.java b/plugins/jvm-example/src/main/java/org/elasticsearch/plugin/example/JvmExamplePlugin.java index fc9de8912d6a..9c4ec733a9f6 100644 --- a/plugins/jvm-example/src/main/java/org/elasticsearch/plugin/example/JvmExamplePlugin.java +++ b/plugins/jvm-example/src/main/java/org/elasticsearch/plugin/example/JvmExamplePlugin.java @@ -66,24 +66,10 @@ public class JvmExamplePlugin extends Plugin { } @Override - public Collection indexModules(Settings indexSettings) { - return Collections.emptyList(); - } + public Collection indexModules(Settings indexSettings) { return Collections.emptyList();} @Override - public Collection> indexServices() { - return Collections.emptyList(); - } - - @Override - public Collection shardModules(Settings indexSettings) { - return Collections.emptyList(); - } - - @Override - public Collection> shardServices() { - return Collections.emptyList(); - } + public Collection> indexServices() { return Collections.emptyList();} @Override public Settings additionalSettings() { diff --git a/plugins/store-smb/src/main/java/org/elasticsearch/index/store/smbmmapfs/SmbMmapFsIndexStore.java b/plugins/store-smb/src/main/java/org/elasticsearch/index/store/smbmmapfs/SmbMmapFsIndexStore.java index 04229756e1ba..1d1592dcf323 100644 --- a/plugins/store-smb/src/main/java/org/elasticsearch/index/store/smbmmapfs/SmbMmapFsIndexStore.java +++ b/plugins/store-smb/src/main/java/org/elasticsearch/index/store/smbmmapfs/SmbMmapFsIndexStore.java @@ -24,6 +24,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.settings.IndexSettingsService; +import org.elasticsearch.index.shard.ShardPath; import org.elasticsearch.index.store.DirectoryService; import org.elasticsearch.index.store.IndexStore; import org.elasticsearch.indices.store.IndicesStore; @@ -37,7 +38,7 @@ public class SmbMmapFsIndexStore extends IndexStore { } @Override - public Class shardDirectory() { - return SmbMmapFsDirectoryService.class; + public DirectoryService newDirectoryService(ShardPath path) { + return new SmbMmapFsDirectoryService(indexSettings(), this, path); } } diff --git a/plugins/store-smb/src/main/java/org/elasticsearch/index/store/smbsimplefs/SmbSimpleFsIndexStore.java b/plugins/store-smb/src/main/java/org/elasticsearch/index/store/smbsimplefs/SmbSimpleFsIndexStore.java index 48133440f6d7..67d396a80a53 100644 --- a/plugins/store-smb/src/main/java/org/elasticsearch/index/store/smbsimplefs/SmbSimpleFsIndexStore.java +++ b/plugins/store-smb/src/main/java/org/elasticsearch/index/store/smbsimplefs/SmbSimpleFsIndexStore.java @@ -24,6 +24,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.settings.IndexSettingsService; +import org.elasticsearch.index.shard.ShardPath; import org.elasticsearch.index.store.DirectoryService; import org.elasticsearch.index.store.IndexStore; import org.elasticsearch.indices.store.IndicesStore; @@ -36,9 +37,13 @@ public class SmbSimpleFsIndexStore extends IndexStore { super(index, indexSettings, indexSettingsService, indicesStore); } - @Override public Class shardDirectory() { return SmbSimpleFsDirectoryService.class; } + + @Override + public DirectoryService newDirectoryService(ShardPath path) { + return new SmbSimpleFsDirectoryService(indexSettings(), this, path); + } }