Make CodecService a simple per shard registry.
This commit is contained in:
parent
f974d5e470
commit
45f7844948
|
@ -24,7 +24,6 @@ import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.util.BigArrays;
|
import org.elasticsearch.common.util.BigArrays;
|
||||||
import org.elasticsearch.index.cache.IndexCache;
|
import org.elasticsearch.index.cache.IndexCache;
|
||||||
import org.elasticsearch.index.codec.CodecService;
|
|
||||||
import org.elasticsearch.index.engine.EngineFactory;
|
import org.elasticsearch.index.engine.EngineFactory;
|
||||||
import org.elasticsearch.index.fielddata.IndexFieldDataService;
|
import org.elasticsearch.index.fielddata.IndexFieldDataService;
|
||||||
import org.elasticsearch.index.mapper.MapperService;
|
import org.elasticsearch.index.mapper.MapperService;
|
||||||
|
@ -49,7 +48,6 @@ public final class IndexServicesProvider {
|
||||||
private final MapperService mapperService;
|
private final MapperService mapperService;
|
||||||
private final IndexCache indexCache;
|
private final IndexCache indexCache;
|
||||||
private final IndicesQueryCache indicesQueryCache;
|
private final IndicesQueryCache indicesQueryCache;
|
||||||
private final CodecService codecService;
|
|
||||||
private final TermVectorsService termVectorsService;
|
private final TermVectorsService termVectorsService;
|
||||||
private final IndexFieldDataService indexFieldDataService;
|
private final IndexFieldDataService indexFieldDataService;
|
||||||
private final IndicesWarmer warmer;
|
private final IndicesWarmer warmer;
|
||||||
|
@ -63,13 +61,12 @@ public final class IndexServicesProvider {
|
||||||
private final ScriptService scriptService;
|
private final ScriptService scriptService;
|
||||||
|
|
||||||
@Inject
|
@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.listener = listener;
|
||||||
this.threadPool = threadPool;
|
this.threadPool = threadPool;
|
||||||
this.mapperService = mapperService;
|
this.mapperService = mapperService;
|
||||||
this.indexCache = indexCache;
|
this.indexCache = indexCache;
|
||||||
this.indicesQueryCache = indicesQueryCache;
|
this.indicesQueryCache = indicesQueryCache;
|
||||||
this.codecService = codecService;
|
|
||||||
this.termVectorsService = termVectorsService;
|
this.termVectorsService = termVectorsService;
|
||||||
this.indexFieldDataService = indexFieldDataService;
|
this.indexFieldDataService = indexFieldDataService;
|
||||||
this.warmer = warmer;
|
this.warmer = warmer;
|
||||||
|
@ -101,10 +98,6 @@ public final class IndexServicesProvider {
|
||||||
return indicesQueryCache;
|
return indicesQueryCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CodecService getCodecService() {
|
|
||||||
return codecService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TermVectorsService getTermVectorsService() {
|
public TermVectorsService getTermVectorsService() {
|
||||||
return termVectorsService;
|
return termVectorsService;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,15 +22,10 @@ package org.elasticsearch.index.codec;
|
||||||
import org.apache.lucene.codecs.Codec;
|
import org.apache.lucene.codecs.Codec;
|
||||||
import org.apache.lucene.codecs.lucene50.Lucene50StoredFieldsFormat.Mode;
|
import org.apache.lucene.codecs.lucene50.Lucene50StoredFieldsFormat.Mode;
|
||||||
import org.apache.lucene.codecs.lucene54.Lucene54Codec;
|
import org.apache.lucene.codecs.lucene54.Lucene54Codec;
|
||||||
|
import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.collect.MapBuilder;
|
import org.elasticsearch.common.collect.MapBuilder;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.logging.ESLogger;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
|
||||||
import org.elasticsearch.index.AbstractIndexComponent;
|
|
||||||
import org.elasticsearch.index.Index;
|
|
||||||
import org.elasticsearch.index.IndexSettings;
|
|
||||||
import org.elasticsearch.index.mapper.MapperService;
|
import org.elasticsearch.index.mapper.MapperService;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -38,11 +33,9 @@ import java.util.Map;
|
||||||
* codec layer that allows to use use-case specific file formats &
|
* codec layer that allows to use use-case specific file formats &
|
||||||
* data-structures per field. Elasticsearch exposes the full
|
* data-structures per field. Elasticsearch exposes the full
|
||||||
* {@link Codec} capabilities through this {@link CodecService}.
|
* {@link Codec} capabilities through this {@link CodecService}.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class CodecService extends AbstractIndexComponent {
|
public class CodecService {
|
||||||
|
|
||||||
private final MapperService mapperService;
|
|
||||||
private final Map<String, Codec> codecs;
|
private final Map<String, Codec> codecs;
|
||||||
|
|
||||||
public final static String DEFAULT_CODEC = "default";
|
public final static String DEFAULT_CODEC = "default";
|
||||||
|
@ -50,11 +43,8 @@ public class CodecService extends AbstractIndexComponent {
|
||||||
/** the raw unfiltered lucene default. useful for testing */
|
/** the raw unfiltered lucene default. useful for testing */
|
||||||
public final static String LUCENE_DEFAULT_CODEC = "lucene_default";
|
public final static String LUCENE_DEFAULT_CODEC = "lucene_default";
|
||||||
|
|
||||||
@Inject
|
public CodecService(@Nullable MapperService mapperService, ESLogger logger) {
|
||||||
public CodecService(IndexSettings indexSettings, MapperService mapperService) {
|
final MapBuilder<String, Codec> codecs = MapBuilder.<String, Codec>newMapBuilder();
|
||||||
super(indexSettings);
|
|
||||||
this.mapperService = mapperService;
|
|
||||||
MapBuilder<String, Codec> codecs = MapBuilder.<String, Codec>newMapBuilder();
|
|
||||||
if (mapperService == null) {
|
if (mapperService == null) {
|
||||||
codecs.put(DEFAULT_CODEC, new Lucene54Codec());
|
codecs.put(DEFAULT_CODEC, new Lucene54Codec());
|
||||||
codecs.put(BEST_COMPRESSION_CODEC, new Lucene54Codec(Mode.BEST_COMPRESSION));
|
codecs.put(BEST_COMPRESSION_CODEC, new Lucene54Codec(Mode.BEST_COMPRESSION));
|
||||||
|
@ -71,10 +61,6 @@ public class CodecService extends AbstractIndexComponent {
|
||||||
this.codecs = codecs.immutableMap();
|
this.codecs = codecs.immutableMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MapperService mapperService() {
|
|
||||||
return mapperService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Codec codec(String name) {
|
public Codec codec(String name) {
|
||||||
Codec codec = codecs.get(name);
|
Codec codec = codecs.get(name);
|
||||||
if (codec == null) {
|
if (codec == null) {
|
||||||
|
|
|
@ -62,7 +62,6 @@ import org.elasticsearch.gateway.MetaDataStateFormat;
|
||||||
import org.elasticsearch.index.IndexModule;
|
import org.elasticsearch.index.IndexModule;
|
||||||
import org.elasticsearch.index.IndexSettings;
|
import org.elasticsearch.index.IndexSettings;
|
||||||
import org.elasticsearch.index.IndexServicesProvider;
|
import org.elasticsearch.index.IndexServicesProvider;
|
||||||
import org.elasticsearch.index.IndexSettings;
|
|
||||||
import org.elasticsearch.index.VersionType;
|
import org.elasticsearch.index.VersionType;
|
||||||
import org.elasticsearch.index.cache.IndexCache;
|
import org.elasticsearch.index.cache.IndexCache;
|
||||||
import org.elasticsearch.index.cache.bitset.ShardBitsetFilterCache;
|
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) {
|
public IndexShard(ShardId shardId, IndexSettings indexSettings, ShardPath path, Store store, IndexSearcherWrapper indexSearcherWrapper, IndexServicesProvider provider) {
|
||||||
super(shardId, indexSettings);
|
super(shardId, indexSettings);
|
||||||
this.idxSettings = indexSettings;
|
this.idxSettings = indexSettings;
|
||||||
this.codecService = provider.getCodecService();
|
this.codecService = new CodecService(provider.getMapperService(), logger);
|
||||||
this.warmer = provider.getWarmer();
|
this.warmer = provider.getWarmer();
|
||||||
this.deletionPolicy = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());
|
this.deletionPolicy = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());
|
||||||
this.similarityService = provider.getSimilarityService();
|
this.similarityService = provider.getSimilarityService();
|
||||||
|
|
|
@ -39,14 +39,30 @@ import org.apache.lucene.index.IndexWriterConfig;
|
||||||
import org.apache.lucene.index.SegmentReader;
|
import org.apache.lucene.index.SegmentReader;
|
||||||
import org.apache.lucene.store.Directory;
|
import org.apache.lucene.store.Directory;
|
||||||
import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
|
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.common.settings.Settings;
|
||||||
|
import org.elasticsearch.env.Environment;
|
||||||
|
import org.elasticsearch.index.Index;
|
||||||
import org.elasticsearch.index.IndexService;
|
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.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;
|
import static org.hamcrest.Matchers.instanceOf;
|
||||||
|
|
||||||
@SuppressCodecs("*") // we test against default codec so never get a random one here!
|
@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 {
|
public void testResolveDefaultCodecs() throws Exception {
|
||||||
CodecService codecService = createCodecService();
|
CodecService codecService = createCodecService();
|
||||||
assertThat(codecService.codec("default"), instanceOf(PerFieldMappingPostingFormatCodec.class));
|
assertThat(codecService.codec("default"), instanceOf(PerFieldMappingPostingFormatCodec.class));
|
||||||
|
@ -90,13 +106,15 @@ public class CodecTests extends ESSingleNodeTestCase {
|
||||||
dir.close();
|
dir.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CodecService createCodecService() {
|
private static CodecService createCodecService() throws IOException {
|
||||||
return createCodecService(Settings.Builder.EMPTY_SETTINGS);
|
Settings nodeSettings = settingsBuilder()
|
||||||
}
|
.put("path.home", createTempDir())
|
||||||
|
.build();
|
||||||
private static CodecService createCodecService(Settings settings) {
|
IndexSettings settings = IndexSettingsModule.newIndexSettings(new Index("_na"), nodeSettings, Collections.emptyList());
|
||||||
IndexService indexService = createIndex("test", settings);
|
SimilarityService similarityService = new SimilarityService(settings, Collections.EMPTY_MAP);
|
||||||
return indexService.getIndexServices().getCodecService();
|
AnalysisService analysisService = new AnalysisRegistry(null, new Environment(nodeSettings)).build(settings);
|
||||||
|
MapperService service = new MapperService(settings, analysisService, similarityService);
|
||||||
|
return new CodecService(service, ESLoggerFactory.getLogger("test"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,7 +148,7 @@ public class InternalEngineTests extends ESTestCase {
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
CodecService codecService = new CodecService(INDEX_SETTINGS, null);
|
CodecService codecService = new CodecService(null, logger);
|
||||||
String name = Codec.getDefault().getName();
|
String name = Codec.getDefault().getName();
|
||||||
if (Arrays.asList(codecService.availableCodecs()).contains(name)) {
|
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
|
// 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
|
EngineConfig config = new EngineConfig(shardId, threadPool, new ShardIndexingService(shardId, INDEX_SETTINGS), indexSettings
|
||||||
, null, store, createSnapshotDeletionPolicy(), mergePolicy, mergeSchedulerConfig,
|
, 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
|
@Override
|
||||||
public void onFailedEngine(String reason, @Nullable Throwable t) {
|
public void onFailedEngine(String reason, @Nullable Throwable t) {
|
||||||
// we don't need to notify anybody in this test
|
// we don't need to notify anybody in this test
|
||||||
|
@ -1576,7 +1576,7 @@ public class InternalEngineTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSettings() {
|
public void testSettings() {
|
||||||
CodecService codecService = new CodecService(INDEX_SETTINGS, null);
|
CodecService codecService = new CodecService(null, logger);
|
||||||
LiveIndexWriterConfig currentIndexWriterConfig = engine.getCurrentIndexWriterConfig();
|
LiveIndexWriterConfig currentIndexWriterConfig = engine.getCurrentIndexWriterConfig();
|
||||||
|
|
||||||
assertEquals(engine.config().getCodec().getName(), codecService.codec(codecName).getName());
|
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()
|
EngineConfig brokenConfig = new EngineConfig(shardId, threadPool, config.getIndexingService(), config.getIndexSettings()
|
||||||
, null, store, createSnapshotDeletionPolicy(), newMergePolicy(), config.getMergeSchedulerConfig(),
|
, 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));
|
, config.getTranslogRecoveryPerformer(), IndexSearcher.getDefaultQueryCache(), IndexSearcher.getDefaultQueryCachingPolicy(), translogConfig, TimeValue.timeValueMinutes(5));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -111,7 +111,7 @@ public class ShadowEngineTests extends ESTestCase {
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
CodecService codecService = new CodecService(INDEX_SETTINGS, null);
|
CodecService codecService = new CodecService(null, logger);
|
||||||
String name = Codec.getDefault().getName();
|
String name = Codec.getDefault().getName();
|
||||||
if (Arrays.asList(codecService.availableCodecs()).contains(name)) {
|
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
|
// 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);
|
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
|
EngineConfig config = new EngineConfig(shardId, threadPool, new ShardIndexingService(shardId, IndexSettingsModule.newIndexSettings(shardId.index(), indexSettings, Collections.EMPTY_LIST)), indexSettings
|
||||||
, null, store, createSnapshotDeletionPolicy(), mergePolicy, mergeSchedulerConfig,
|
, 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
|
@Override
|
||||||
public void onFailedEngine(String reason, @Nullable Throwable t) {
|
public void onFailedEngine(String reason, @Nullable Throwable t) {
|
||||||
// we don't need to notify anybody in this test
|
// we don't need to notify anybody in this test
|
||||||
|
@ -919,7 +919,7 @@ public class ShadowEngineTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSettings() {
|
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());
|
assertEquals(replicaEngine.config().getCodec().getName(), codecService.codec(codecName).getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue