diff --git a/core/src/main/java/org/elasticsearch/index/IndexServicesProvider.java b/core/src/main/java/org/elasticsearch/index/IndexServicesProvider.java index 14cb3e7a446..cce325e93fd 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexServicesProvider.java +++ b/core/src/main/java/org/elasticsearch/index/IndexServicesProvider.java @@ -24,7 +24,6 @@ import org.elasticsearch.common.Nullable; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.index.cache.IndexCache; -import org.elasticsearch.index.codec.CodecService; import org.elasticsearch.index.engine.EngineFactory; import org.elasticsearch.index.fielddata.IndexFieldDataService; import org.elasticsearch.index.mapper.MapperService; @@ -49,7 +48,6 @@ public final class IndexServicesProvider { private final MapperService mapperService; private final IndexCache indexCache; private final IndicesQueryCache indicesQueryCache; - private final CodecService codecService; private final TermVectorsService termVectorsService; private final IndexFieldDataService indexFieldDataService; private final IndicesWarmer warmer; @@ -63,13 +61,12 @@ public final class IndexServicesProvider { private final ScriptService scriptService; @Inject - public IndexServicesProvider(IndexEventListener listener, ThreadPool threadPool, MapperService mapperService, IndexCache indexCache, IndicesQueryCache indicesQueryCache, CodecService codecService, TermVectorsService termVectorsService, IndexFieldDataService indexFieldDataService, @Nullable IndicesWarmer warmer, SimilarityService similarityService, EngineFactory factory, BigArrays bigArrays, IndexingMemoryController indexingMemoryController, Client client, ScriptService scriptService, IndicesQueriesRegistry indicesQueriesRegistry) { + public IndexServicesProvider(IndexEventListener listener, ThreadPool threadPool, MapperService mapperService, IndexCache indexCache, IndicesQueryCache indicesQueryCache, TermVectorsService termVectorsService, IndexFieldDataService indexFieldDataService, @Nullable IndicesWarmer warmer, SimilarityService similarityService, EngineFactory factory, BigArrays bigArrays, IndexingMemoryController indexingMemoryController, Client client, ScriptService scriptService, IndicesQueriesRegistry indicesQueriesRegistry) { this.listener = listener; this.threadPool = threadPool; this.mapperService = mapperService; this.indexCache = indexCache; this.indicesQueryCache = indicesQueryCache; - this.codecService = codecService; this.termVectorsService = termVectorsService; this.indexFieldDataService = indexFieldDataService; this.warmer = warmer; @@ -101,10 +98,6 @@ public final class IndexServicesProvider { return indicesQueryCache; } - public CodecService getCodecService() { - return codecService; - } - public TermVectorsService getTermVectorsService() { return termVectorsService; } diff --git a/core/src/main/java/org/elasticsearch/index/codec/CodecService.java b/core/src/main/java/org/elasticsearch/index/codec/CodecService.java index f7c53cf20f0..e4d86be1bda 100644 --- a/core/src/main/java/org/elasticsearch/index/codec/CodecService.java +++ b/core/src/main/java/org/elasticsearch/index/codec/CodecService.java @@ -22,15 +22,10 @@ package org.elasticsearch.index.codec; import org.apache.lucene.codecs.Codec; import org.apache.lucene.codecs.lucene50.Lucene50StoredFieldsFormat.Mode; import org.apache.lucene.codecs.lucene54.Lucene54Codec; +import org.elasticsearch.common.Nullable; import org.elasticsearch.common.collect.MapBuilder; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.AbstractIndexComponent; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexSettings; +import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.index.mapper.MapperService; - -import java.util.Collections; import java.util.Map; /** @@ -38,11 +33,9 @@ import java.util.Map; * codec layer that allows to use use-case specific file formats & * data-structures per field. Elasticsearch exposes the full * {@link Codec} capabilities through this {@link CodecService}. - * */ -public class CodecService extends AbstractIndexComponent { +public class CodecService { - private final MapperService mapperService; private final Map codecs; public final static String DEFAULT_CODEC = "default"; @@ -50,11 +43,8 @@ public class CodecService extends AbstractIndexComponent { /** the raw unfiltered lucene default. useful for testing */ public final static String LUCENE_DEFAULT_CODEC = "lucene_default"; - @Inject - public CodecService(IndexSettings indexSettings, MapperService mapperService) { - super(indexSettings); - this.mapperService = mapperService; - MapBuilder codecs = MapBuilder.newMapBuilder(); + public CodecService(@Nullable MapperService mapperService, ESLogger logger) { + final MapBuilder codecs = MapBuilder.newMapBuilder(); if (mapperService == null) { codecs.put(DEFAULT_CODEC, new Lucene54Codec()); codecs.put(BEST_COMPRESSION_CODEC, new Lucene54Codec(Mode.BEST_COMPRESSION)); @@ -71,10 +61,6 @@ public class CodecService extends AbstractIndexComponent { this.codecs = codecs.immutableMap(); } - public MapperService mapperService() { - return mapperService; - } - public Codec codec(String name) { Codec codec = codecs.get(name); if (codec == null) { 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 02c26f10087..50a19584a8d 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java +++ b/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java @@ -62,7 +62,6 @@ import org.elasticsearch.gateway.MetaDataStateFormat; import org.elasticsearch.index.IndexModule; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.IndexServicesProvider; -import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.VersionType; import org.elasticsearch.index.cache.IndexCache; import org.elasticsearch.index.cache.bitset.ShardBitsetFilterCache; @@ -206,7 +205,7 @@ public class IndexShard extends AbstractIndexShardComponent { public IndexShard(ShardId shardId, IndexSettings indexSettings, ShardPath path, Store store, IndexSearcherWrapper indexSearcherWrapper, IndexServicesProvider provider) { super(shardId, indexSettings); this.idxSettings = indexSettings; - this.codecService = provider.getCodecService(); + this.codecService = new CodecService(provider.getMapperService(), logger); this.warmer = provider.getWarmer(); this.deletionPolicy = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy()); this.similarityService = provider.getSimilarityService(); diff --git a/core/src/test/java/org/elasticsearch/index/codec/CodecTests.java b/core/src/test/java/org/elasticsearch/index/codec/CodecTests.java index 5d6f83b2d47..b54c7806d62 100644 --- a/core/src/test/java/org/elasticsearch/index/codec/CodecTests.java +++ b/core/src/test/java/org/elasticsearch/index/codec/CodecTests.java @@ -39,14 +39,30 @@ import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.SegmentReader; import org.apache.lucene.store.Directory; import org.apache.lucene.util.LuceneTestCase.SuppressCodecs; +import org.elasticsearch.Version; +import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.common.logging.ESLoggerFactory; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.env.Environment; +import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexService; +import org.elasticsearch.index.IndexSettings; +import org.elasticsearch.index.analysis.AnalysisRegistry; +import org.elasticsearch.index.analysis.AnalysisService; +import org.elasticsearch.index.mapper.MapperService; +import org.elasticsearch.index.similarity.SimilarityService; import org.elasticsearch.test.ESSingleNodeTestCase; +import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.IndexSettingsModule; +import java.io.IOException; +import java.util.Collections; + +import static org.elasticsearch.common.settings.Settings.settingsBuilder; import static org.hamcrest.Matchers.instanceOf; @SuppressCodecs("*") // we test against default codec so never get a random one here! -public class CodecTests extends ESSingleNodeTestCase { +public class CodecTests extends ESTestCase { public void testResolveDefaultCodecs() throws Exception { CodecService codecService = createCodecService(); assertThat(codecService.codec("default"), instanceOf(PerFieldMappingPostingFormatCodec.class)); @@ -90,13 +106,15 @@ public class CodecTests extends ESSingleNodeTestCase { dir.close(); } - private static CodecService createCodecService() { - return createCodecService(Settings.Builder.EMPTY_SETTINGS); - } - - private static CodecService createCodecService(Settings settings) { - IndexService indexService = createIndex("test", settings); - return indexService.getIndexServices().getCodecService(); + private static CodecService createCodecService() throws IOException { + Settings nodeSettings = settingsBuilder() + .put("path.home", createTempDir()) + .build(); + IndexSettings settings = IndexSettingsModule.newIndexSettings(new Index("_na"), nodeSettings, Collections.emptyList()); + SimilarityService similarityService = new SimilarityService(settings, Collections.EMPTY_MAP); + AnalysisService analysisService = new AnalysisRegistry(null, new Environment(nodeSettings)).build(settings); + MapperService service = new MapperService(settings, analysisService, similarityService); + return new CodecService(service, ESLoggerFactory.getLogger("test")); } } diff --git a/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java b/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java index 2d4948da3a4..eeb3b41dabe 100644 --- a/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java +++ b/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java @@ -148,7 +148,7 @@ public class InternalEngineTests extends ESTestCase { public void setUp() throws Exception { super.setUp(); - CodecService codecService = new CodecService(INDEX_SETTINGS, null); + CodecService codecService = new CodecService(null, logger); String name = Codec.getDefault().getName(); if (Arrays.asList(codecService.availableCodecs()).contains(name)) { // some codecs are read only so we only take the ones that we have in the service and randomly @@ -264,7 +264,7 @@ public class InternalEngineTests extends ESTestCase { EngineConfig config = new EngineConfig(shardId, threadPool, new ShardIndexingService(shardId, INDEX_SETTINGS), indexSettings , null, store, createSnapshotDeletionPolicy(), mergePolicy, mergeSchedulerConfig, - iwc.getAnalyzer(), iwc.getSimilarity(), new CodecService(INDEX_SETTINGS, null), new Engine.EventListener() { + iwc.getAnalyzer(), iwc.getSimilarity(), new CodecService(null, logger), new Engine.EventListener() { @Override public void onFailedEngine(String reason, @Nullable Throwable t) { // we don't need to notify anybody in this test @@ -1576,7 +1576,7 @@ public class InternalEngineTests extends ESTestCase { } public void testSettings() { - CodecService codecService = new CodecService(INDEX_SETTINGS, null); + CodecService codecService = new CodecService(null, logger); LiveIndexWriterConfig currentIndexWriterConfig = engine.getCurrentIndexWriterConfig(); assertEquals(engine.config().getCodec().getName(), codecService.codec(codecName).getName()); @@ -1972,7 +1972,7 @@ public class InternalEngineTests extends ESTestCase { EngineConfig brokenConfig = new EngineConfig(shardId, threadPool, config.getIndexingService(), config.getIndexSettings() , null, store, createSnapshotDeletionPolicy(), newMergePolicy(), config.getMergeSchedulerConfig(), - config.getAnalyzer(), config.getSimilarity(), new CodecService(INDEX_SETTINGS, null), config.getEventListener() + config.getAnalyzer(), config.getSimilarity(), new CodecService(null, logger), config.getEventListener() , config.getTranslogRecoveryPerformer(), IndexSearcher.getDefaultQueryCache(), IndexSearcher.getDefaultQueryCachingPolicy(), translogConfig, TimeValue.timeValueMinutes(5)); try { diff --git a/core/src/test/java/org/elasticsearch/index/engine/ShadowEngineTests.java b/core/src/test/java/org/elasticsearch/index/engine/ShadowEngineTests.java index 9f208d73910..4ab3b81b599 100644 --- a/core/src/test/java/org/elasticsearch/index/engine/ShadowEngineTests.java +++ b/core/src/test/java/org/elasticsearch/index/engine/ShadowEngineTests.java @@ -111,7 +111,7 @@ public class ShadowEngineTests extends ESTestCase { @Before public void setUp() throws Exception { super.setUp(); - CodecService codecService = new CodecService(INDEX_SETTINGS, null); + CodecService codecService = new CodecService(null, logger); String name = Codec.getDefault().getName(); if (Arrays.asList(codecService.availableCodecs()).contains(name)) { // some codecs are read only so we only take the ones that we have in the service and randomly @@ -229,7 +229,7 @@ public class ShadowEngineTests extends ESTestCase { TranslogConfig translogConfig = new TranslogConfig(shardId, translogPath, IndexSettingsModule.newIndexSettings(shardId.index(), indexSettings, Collections.EMPTY_LIST), Translog.Durabilty.REQUEST, BigArrays.NON_RECYCLING_INSTANCE, threadPool); EngineConfig config = new EngineConfig(shardId, threadPool, new ShardIndexingService(shardId, IndexSettingsModule.newIndexSettings(shardId.index(), indexSettings, Collections.EMPTY_LIST)), indexSettings , null, store, createSnapshotDeletionPolicy(), mergePolicy, mergeSchedulerConfig, - iwc.getAnalyzer(), iwc.getSimilarity() , new CodecService(INDEX_SETTINGS, null), new Engine.EventListener() { + iwc.getAnalyzer(), iwc.getSimilarity() , new CodecService(null, logger), new Engine.EventListener() { @Override public void onFailedEngine(String reason, @Nullable Throwable t) { // we don't need to notify anybody in this test @@ -919,7 +919,7 @@ public class ShadowEngineTests extends ESTestCase { } public void testSettings() { - CodecService codecService = new CodecService(INDEX_SETTINGS, null); + CodecService codecService = new CodecService(null, logger); assertEquals(replicaEngine.config().getCodec().getName(), codecService.codec(codecName).getName()); }