From e94f242456bc9022c6fcde1e1bb6e8eb441702d5 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Fri, 2 Oct 2015 15:51:42 +0200 Subject: [PATCH] more index level cleanups --- .../org/elasticsearch/index/IndexService.java | 78 ++++++------------- .../index/IndexServicesProvider.java | 3 - .../elasticsearch/index/shard/IndexShard.java | 2 - .../indices/IndicesLifecycle.java | 11 --- .../indices/InternalIndicesLifecycle.java | 22 ------ .../cluster/IndicesClusterStateService.java | 2 +- .../elasticsearch/index/codec/CodecTests.java | 2 +- .../fielddata/AbstractFieldDataTestCase.java | 2 +- .../test/ESSingleNodeTestCase.java | 10 ++- .../test/InternalTestCluster.java | 2 +- .../elasticsearch/test/TestSearchContext.java | 7 +- 11 files changed, 40 insertions(+), 101 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/IndexService.java b/core/src/main/java/org/elasticsearch/index/IndexService.java index 574e4551ba6..0493559b417 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexService.java +++ b/core/src/main/java/org/elasticsearch/index/IndexService.java @@ -26,9 +26,7 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.inject.Injector; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.env.ShardLock; @@ -48,11 +46,8 @@ import org.elasticsearch.index.shard.*; import org.elasticsearch.index.similarity.SimilarityService; import org.elasticsearch.index.store.IndexStore; import org.elasticsearch.index.store.Store; -import org.elasticsearch.indices.IndicesLifecycle; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.indices.InternalIndicesLifecycle; -import org.elasticsearch.indices.cache.query.IndicesQueryCache; -import org.elasticsearch.plugins.PluginsService; import java.io.Closeable; import java.io.IOException; @@ -71,69 +66,48 @@ import static org.elasticsearch.common.collect.MapBuilder.newMapBuilder; */ public class IndexService extends AbstractIndexComponent implements IndexComponent, Iterable { - private final Injector injector; - private final Settings indexSettings; - private final PluginsService pluginsService; - private final InternalIndicesLifecycle indicesLifecycle; private final AnalysisService analysisService; - private final MapperService mapperService; - - private final IndexQueryParserService queryParserService; - - private final SimilarityService similarityService; - - private final IndexAliasesService aliasesService; - - private final IndexCache indexCache; - private final IndexFieldDataService indexFieldData; private final BitsetFilterCache bitsetFilterCache; private final IndexSettingsService settingsService; - private final NodeEnvironment nodeEnv; private final IndicesService indicesServices; + private final IndexServicesProvider indexServicesProvider; + private final IndexStore indexStore; private volatile ImmutableMap shards = ImmutableMap.of(); - - private final AtomicBoolean closed = new AtomicBoolean(false); private final AtomicBoolean deleted = new AtomicBoolean(false); @Inject - public IndexService(Injector injector, Index index, @IndexSettings Settings indexSettings, NodeEnvironment nodeEnv, - AnalysisService analysisService, MapperService mapperService, IndexQueryParserService queryParserService, - SimilarityService similarityService, IndexAliasesService aliasesService, IndexCache indexCache, + public IndexService(Index index, @IndexSettings Settings indexSettings, NodeEnvironment nodeEnv, + AnalysisService analysisService, IndexSettingsService settingsService, - IndexFieldDataService indexFieldData, BitsetFilterCache bitSetFilterCache, IndicesService indicesServices) { - + IndexFieldDataService indexFieldData, + BitsetFilterCache bitSetFilterCache, + IndicesService indicesServices, + IndexServicesProvider indexServicesProvider, + IndexStore indexStore) { super(index, indexSettings); - this.injector = injector; this.indexSettings = indexSettings; this.analysisService = analysisService; - this.mapperService = mapperService; - this.queryParserService = queryParserService; - this.similarityService = similarityService; - this.aliasesService = aliasesService; - this.indexCache = indexCache; this.indexFieldData = indexFieldData; this.settingsService = settingsService; this.bitsetFilterCache = bitSetFilterCache; - - this.pluginsService = injector.getInstance(PluginsService.class); this.indicesServices = indicesServices; - this.indicesLifecycle = (InternalIndicesLifecycle) injector.getInstance(IndicesLifecycle.class); - - // inject workarounds for cyclic dep + this.indicesLifecycle = (InternalIndicesLifecycle) indexServicesProvider.getIndicesLifecycle(); + this.nodeEnv = nodeEnv; + this.indexServicesProvider = indexServicesProvider; + this.indexStore = indexStore; indexFieldData.setListener(new FieldDataCacheListener(this)); bitSetFilterCache.setListener(new BitsetCacheListener(this)); - this.nodeEnv = nodeEnv; } public int numberOfShards() { @@ -176,16 +150,12 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone return shards.keySet(); } - public Injector injector() { - return injector; - } - public IndexSettingsService settingsService() { return this.settingsService; } public IndexCache cache() { - return indexCache; + return indexServicesProvider.getIndexCache(); } public IndexFieldDataService fieldData() { @@ -201,19 +171,19 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone } public MapperService mapperService() { - return mapperService; + return indexServicesProvider.getMapperService(); } public IndexQueryParserService queryParserService() { - return queryParserService; + return indexServicesProvider.getQueryParserService(); } public SimilarityService similarityService() { - return similarityService; + return indexServicesProvider.getSimilarityService(); } public IndexAliasesService aliasesService() { - return aliasesService; + return indexServicesProvider.getIndexAliasesService(); } public synchronized void close(final String reason, boolean delete) { @@ -288,7 +258,6 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone if (path == null) { // TODO: we should, instead, hold a "bytes reserved" of how large we anticipate this shard will be, e.g. for a shard // that's being relocated/replicated we know how large it will become once it's done copying: - // Count up how many shards are currently on each data path: Map dataPathToShardCount = new HashMap<>(); for(IndexShard shard : this) { @@ -314,12 +283,11 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone // if we are on a shared FS we only own the shard (ie. we can safely delete it) if we are the primary. final boolean canDeleteShardContent = IndexMetaData.isOnSharedFilesystem(indexSettings) == false || (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))); + store = new Store(shardId, indexSettings, indexStore.newDirectoryService(path), lock, new StoreCloseListener(shardId, canDeleteShardContent, () -> indexServicesProvider.getIndicesQueryCache().onClose(shardId))); if (useShadowEngine(primary, indexSettings)) { - indexShard = new ShadowIndexShard(shardId, indexSettings, path, store, injector.getInstance(IndexServicesProvider.class)); + indexShard = new ShadowIndexShard(shardId, indexSettings, path, store, indexServicesProvider); } else { - indexShard = new IndexShard(shardId, indexSettings, path, store, injector.getInstance(IndexServicesProvider.class)); + indexShard = new IndexShard(shardId, indexSettings, path, store, indexServicesProvider); } indicesLifecycle.indexShardStateChanged(indexShard, null, "shard created"); @@ -407,6 +375,10 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone } } + public IndexServicesProvider getIndexServices() { + return indexServicesProvider; + } + private class StoreCloseListener implements Store.OnClose { private final ShardId shardId; private final boolean ownsShard; diff --git a/core/src/main/java/org/elasticsearch/index/IndexServicesProvider.java b/core/src/main/java/org/elasticsearch/index/IndexServicesProvider.java index 0a34fabd7b1..fe8428425e2 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexServicesProvider.java +++ b/core/src/main/java/org/elasticsearch/index/IndexServicesProvider.java @@ -57,9 +57,6 @@ public final class IndexServicesProvider { private final SimilarityService similarityService; private final EngineFactory factory; private final BigArrays bigArrays; - - - private final IndexSearcherWrapper indexSearcherWrapper; @Inject diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java b/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java index 3270463ed9c..42f7a78dda4 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java +++ b/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java @@ -767,7 +767,6 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett public IndexShard postRecovery(String reason) throws IndexShardStartedException, IndexShardRelocatedException, IndexShardClosedException { - indicesLifecycle.beforeIndexShardPostRecovery(this); if (mapperService.hasMapping(PercolatorService.TYPE_NAME)) { refresh("percolator_load_queries"); try (Engine.Searcher searcher = engine().acquireSearcher("percolator_load_queries")) { @@ -787,7 +786,6 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett recoveryState.setStage(RecoveryState.Stage.DONE); changeState(IndexShardState.POST_RECOVERY, reason); } - indicesLifecycle.afterIndexShardPostRecovery(this); return this; } diff --git a/core/src/main/java/org/elasticsearch/indices/IndicesLifecycle.java b/core/src/main/java/org/elasticsearch/indices/IndicesLifecycle.java index 211b6d4869d..8c761dfe898 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndicesLifecycle.java +++ b/core/src/main/java/org/elasticsearch/indices/IndicesLifecycle.java @@ -97,17 +97,6 @@ public interface IndicesLifecycle { } - /** - * Called right after the shard is moved into POST_RECOVERY mode - */ - public void afterIndexShardPostRecovery(IndexShard indexShard) {} - - /** - * Called right before the shard is moved into POST_RECOVERY mode. - * The shard is ready to be used but not yet marked as POST_RECOVERY. - */ - public void beforeIndexShardPostRecovery(IndexShard indexShard) {} - /** * Called after the index shard has been started. */ diff --git a/core/src/main/java/org/elasticsearch/indices/InternalIndicesLifecycle.java b/core/src/main/java/org/elasticsearch/indices/InternalIndicesLifecycle.java index 77050714db2..16c0c362c42 100644 --- a/core/src/main/java/org/elasticsearch/indices/InternalIndicesLifecycle.java +++ b/core/src/main/java/org/elasticsearch/indices/InternalIndicesLifecycle.java @@ -121,28 +121,6 @@ public class InternalIndicesLifecycle extends AbstractComponent implements Indic } } - public void beforeIndexShardPostRecovery(IndexShard indexShard) { - for (Listener listener : listeners) { - try { - listener.beforeIndexShardPostRecovery(indexShard); - } catch (Throwable t) { - logger.warn("{} failed to invoke before shard post recovery callback", t, indexShard.shardId()); - throw t; - } - } - } - - - public void afterIndexShardPostRecovery(IndexShard indexShard) { - for (Listener listener : listeners) { - try { - listener.afterIndexShardPostRecovery(indexShard); - } catch (Throwable t) { - logger.warn("{} failed to invoke after shard post recovery callback", t, indexShard.shardId()); - throw t; - } - } - } public void afterIndexShardStarted(IndexShard indexShard) { for (Listener listener : listeners) { diff --git a/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java b/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java index eb2bc242a6c..f2d39e1ac80 100644 --- a/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java +++ b/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java @@ -327,7 +327,7 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent subPhaseContexts = new HashMap<>(); - public TestSearchContext(ThreadPool threadPool,PageCacheRecycler pageCacheRecycler, BigArrays bigArrays, IndexService indexService) { + public TestSearchContext(ThreadPool threadPool,PageCacheRecycler pageCacheRecycler, BigArrays bigArrays, ScriptService scriptService, IndexService indexService) { super(ParseFieldMatcher.STRICT, null); this.pageCacheRecycler = pageCacheRecycler; this.bigArrays = bigArrays.withCircuitBreaking(); @@ -108,6 +109,7 @@ public class TestSearchContext extends SearchContext { this.fixedBitSetFilterCache = indexService.bitsetFilterCache(); this.threadPool = threadPool; this.indexShard = indexService.shard(0); + this.scriptService = scriptService; } public TestSearchContext() { @@ -119,6 +121,7 @@ public class TestSearchContext extends SearchContext { this.threadPool = null; this.fixedBitSetFilterCache = null; this.indexShard = null; + scriptService = null; } public void setTypes(String... types) { @@ -325,7 +328,7 @@ public class TestSearchContext extends SearchContext { @Override public ScriptService scriptService() { - return indexService.injector().getInstance(ScriptService.class); + return scriptService; } @Override