From 66d5d0c4f2de78371ccb5447e503d9d30b6b51c4 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Wed, 21 Oct 2015 14:02:10 +0200 Subject: [PATCH 01/11] Replace IndexSettings annotation with a full-fledged class The @IndexSettings annoationat has been used to differentiate between node-level and index level settings. It was also decoupled from realtime-updates such that the settings object that a class got injected when it was created was static and not subject to change when an update was applied. This change removes the annoation and replaces it with a full-fledged class that adds type-safety and encapsulates additional functionality as well as checks on the settings. --- .../metadata/MetaDataIndexUpgradeService.java | 15 ++- .../common/settings/Settings.java | 1 + .../elasticsearch/env/NodeEnvironment.java | 21 ++-- .../gateway/PrimaryShardAllocator.java | 14 +-- ...ransportNodesListGatewayStartedShards.java | 6 +- .../index/AbstractIndexComponent.java | 22 ++-- .../index/CompositeIndexEventListener.java | 17 ++- .../org/elasticsearch/index/IndexModule.java | 26 +++-- .../elasticsearch/index/IndexNameModule.java | 39 ------- .../org/elasticsearch/index/IndexService.java | 80 +++++++------- .../elasticsearch/index/IndexSettings.java | 101 ++++++++++++++++++ .../ASCIIFoldingTokenFilterFactory.java | 7 +- .../analysis/AbstractCharFilterFactory.java | 8 +- .../AbstractIndexAnalyzerProvider.java | 12 +-- .../analysis/AbstractTokenFilterFactory.java | 9 +- .../analysis/AbstractTokenizerFactory.java | 9 +- .../index/analysis/Analysis.java | 12 +-- .../index/analysis/AnalysisService.java | 37 ++++--- .../analysis/ApostropheFilterFactory.java | 7 +- .../analysis/ArabicAnalyzerProvider.java | 7 +- .../ArabicNormalizationFilterFactory.java | 7 +- .../ArabicStemTokenFilterFactory.java | 7 +- .../analysis/ArmenianAnalyzerProvider.java | 7 +- .../analysis/BasqueAnalyzerProvider.java | 7 +- .../analysis/BrazilianAnalyzerProvider.java | 7 +- .../BrazilianStemTokenFilterFactory.java | 7 +- .../analysis/BulgarianAnalyzerProvider.java | 7 +- .../analysis/CJKBigramFilterFactory.java | 7 +- .../index/analysis/CJKWidthFilterFactory.java | 6 +- .../analysis/CatalanAnalyzerProvider.java | 7 +- .../analysis/ChineseAnalyzerProvider.java | 7 +- .../index/analysis/CjkAnalyzerProvider.java | 7 +- .../index/analysis/ClassicFilterFactory.java | 7 +- .../analysis/ClassicTokenizerFactory.java | 7 +- .../CommonGramsTokenFilterFactory.java | 9 +- .../analysis/CustomAnalyzerProvider.java | 11 +- .../index/analysis/CzechAnalyzerProvider.java | 7 +- .../analysis/CzechStemTokenFilterFactory.java | 7 +- .../analysis/DanishAnalyzerProvider.java | 7 +- .../analysis/DecimalDigitFilterFactory.java | 6 +- .../DelimitedPayloadTokenFilterFactory.java | 7 +- .../index/analysis/DutchAnalyzerProvider.java | 7 +- .../analysis/DutchStemTokenFilterFactory.java | 7 +- .../analysis/EdgeNGramTokenFilterFactory.java | 9 +- .../analysis/EdgeNGramTokenizerFactory.java | 10 +- .../analysis/ElisionTokenFilterFactory.java | 7 +- .../analysis/EnglishAnalyzerProvider.java | 7 +- .../analysis/FinnishAnalyzerProvider.java | 7 +- .../analysis/FrenchAnalyzerProvider.java | 7 +- .../FrenchStemTokenFilterFactory.java | 13 ++- .../analysis/GalicianAnalyzerProvider.java | 7 +- .../analysis/GermanAnalyzerProvider.java | 7 +- .../GermanNormalizationFilterFactory.java | 7 +- .../GermanStemTokenFilterFactory.java | 7 +- .../index/analysis/GreekAnalyzerProvider.java | 7 +- .../index/analysis/HindiAnalyzerProvider.java | 7 +- .../HindiNormalizationFilterFactory.java | 7 +- .../analysis/HtmlStripCharFilterFactory.java | 7 +- .../analysis/HungarianAnalyzerProvider.java | 7 +- .../analysis/HunspellTokenFilterFactory.java | 7 +- .../IndicNormalizationFilterFactory.java | 7 +- .../analysis/IndonesianAnalyzerProvider.java | 7 +- .../index/analysis/IrishAnalyzerProvider.java | 7 +- .../analysis/ItalianAnalyzerProvider.java | 7 +- .../analysis/KStemTokenFilterFactory.java | 7 +- .../analysis/KeepTypesFilterFactory.java | 7 +- .../index/analysis/KeepWordFilterFactory.java | 7 +- .../analysis/KeywordAnalyzerProvider.java | 7 +- .../KeywordMarkerTokenFilterFactory.java | 11 +- .../analysis/KeywordTokenizerFactory.java | 7 +- .../analysis/LatvianAnalyzerProvider.java | 7 +- .../analysis/LengthTokenFilterFactory.java | 7 +- .../analysis/LetterTokenizerFactory.java | 7 +- .../LimitTokenCountFilterFactory.java | 7 +- .../analysis/LithuanianAnalyzerProvider.java | 7 +- .../analysis/LowerCaseTokenFilterFactory.java | 7 +- .../analysis/LowerCaseTokenizerFactory.java | 7 +- .../analysis/MappingCharFilterFactory.java | 7 +- .../analysis/NGramTokenFilterFactory.java | 9 +- .../index/analysis/NGramTokenizerFactory.java | 9 +- .../analysis/NorwegianAnalyzerProvider.java | 7 +- .../PathHierarchyTokenizerFactory.java | 7 +- .../analysis/PatternAnalyzerProvider.java | 9 +- ...PatternCaptureGroupTokenFilterFactory.java | 7 +- .../PatternReplaceCharFilterFactory.java | 7 +- .../PatternReplaceTokenFilterFactory.java | 7 +- .../analysis/PatternTokenizerFactory.java | 7 +- .../analysis/PersianAnalyzerProvider.java | 7 +- .../PersianNormalizationFilterFactory.java | 7 +- .../PorterStemTokenFilterFactory.java | 7 +- .../analysis/PortugueseAnalyzerProvider.java | 7 +- .../analysis/ReverseTokenFilterFactory.java | 7 +- .../analysis/RomanianAnalyzerProvider.java | 7 +- .../analysis/RussianAnalyzerProvider.java | 7 +- .../RussianStemTokenFilterFactory.java | 7 +- .../ScandinavianFoldingFilterFactory.java | 7 +- ...candinavianNormalizationFilterFactory.java | 7 +- .../SerbianNormalizationFilterFactory.java | 7 +- .../analysis/ShingleTokenFilterFactory.java | 7 +- .../analysis/SimpleAnalyzerProvider.java | 7 +- .../analysis/SnowballAnalyzerProvider.java | 7 +- .../analysis/SnowballTokenFilterFactory.java | 7 +- .../analysis/SoraniAnalyzerProvider.java | 7 +- .../SoraniNormalizationFilterFactory.java | 7 +- .../analysis/SpanishAnalyzerProvider.java | 7 +- .../analysis/StandardAnalyzerProvider.java | 9 +- .../StandardHtmlStripAnalyzerProvider.java | 9 +- .../analysis/StandardTokenFilterFactory.java | 7 +- .../analysis/StandardTokenizerFactory.java | 7 +- .../StemmerOverrideTokenFilterFactory.java | 7 +- .../analysis/StemmerTokenFilterFactory.java | 9 +- .../index/analysis/StopAnalyzerProvider.java | 7 +- .../analysis/StopTokenFilterFactory.java | 7 +- .../analysis/SwedishAnalyzerProvider.java | 7 +- .../analysis/SynonymTokenFilterFactory.java | 9 +- .../index/analysis/ThaiAnalyzerProvider.java | 7 +- .../index/analysis/ThaiTokenizerFactory.java | 7 +- .../analysis/TrimTokenFilterFactory.java | 12 +-- .../analysis/TruncateTokenFilterFactory.java | 7 +- .../analysis/TurkishAnalyzerProvider.java | 7 +- .../UAX29URLEmailTokenizerFactory.java | 7 +- .../analysis/UniqueTokenFilterFactory.java | 7 +- .../analysis/UpperCaseTokenFilterFactory.java | 7 +- .../analysis/WhitespaceAnalyzerProvider.java | 7 +- .../analysis/WhitespaceTokenizerFactory.java | 7 +- .../WordDelimiterTokenFilterFactory.java | 7 +- ...bstractCompoundWordTokenFilterFactory.java | 7 +- ...tionaryCompoundWordTokenFilterFactory.java | 8 +- ...enationCompoundWordTokenFilterFactory.java | 9 +- .../elasticsearch/index/cache/IndexCache.java | 8 +- .../index/cache/bitset/BitsetFilterCache.java | 10 +- .../cache/bitset/ShardBitsetFilterCache.java | 5 +- .../cache/query/index/IndexQueryCache.java | 10 +- .../cache/query/none/NoneQueryCache.java | 8 +- .../cache/request/ShardRequestCache.java | 5 +- .../index/codec/CodecService.java | 15 +-- .../index/fielddata/IndexFieldData.java | 6 +- .../fielddata/IndexFieldDataService.java | 28 +++-- .../index/fielddata/ShardFieldData.java | 4 - .../ordinals/GlobalOrdinalsBuilder.java | 6 +- .../GlobalOrdinalsIndexFieldData.java | 9 +- .../InternalGlobalOrdinalsIndexFieldData.java | 8 +- .../plain/AbstractIndexFieldData.java | 9 +- .../plain/AbstractIndexGeoPointFieldData.java | 7 +- .../plain/AbstractIndexOrdinalsFieldData.java | 6 +- .../plain/BytesBinaryDVIndexFieldData.java | 7 +- .../plain/DisabledIndexFieldData.java | 12 +-- .../plain/DocValuesIndexFieldData.java | 9 +- .../plain/GeoPointBinaryDVIndexFieldData.java | 7 +- .../GeoPointDoubleArrayIndexFieldData.java | 13 +-- .../fielddata/plain/IndexIndexFieldData.java | 12 +-- .../plain/PagedBytesIndexFieldData.java | 13 +-- .../plain/ParentChildIndexFieldData.java | 12 +-- .../SortedSetDVOrdinalsIndexFieldData.java | 10 +- .../index/get/ShardGetService.java | 5 +- .../index/indexing/ShardIndexingService.java | 5 +- .../index/mapper/DocumentMapperParser.java | 45 ++------ .../index/mapper/MapperService.java | 44 +++----- .../index/mapper/object/ObjectMapper.java | 3 +- .../index/mapper/object/RootObjectMapper.java | 17 +-- .../percolator/PercolatorQueriesRegistry.java | 7 +- .../index/query/IndexQueryParserService.java | 26 +++-- .../index/query/QueryShardContext.java | 9 +- .../index/query/TemplateQueryBuilder.java | 2 +- .../index/query/WrapperQueryBuilder.java | 2 +- .../index/settings/IndexSettings.java | 41 ------- .../index/settings/IndexSettingsProvider.java | 44 -------- .../index/settings/IndexSettingsService.java | 85 --------------- .../shard/AbstractIndexShardComponent.java | 8 +- .../elasticsearch/index/shard/IndexShard.java | 34 +++--- .../index/shard/MergePolicyConfig.java | 4 +- .../index/shard/ShadowIndexShard.java | 5 +- .../elasticsearch/index/shard/ShardPath.java | 31 +++--- .../index/similarity/SimilarityModule.java | 13 +-- .../index/similarity/SimilarityService.java | 16 +-- .../index/store/DirectoryService.java | 5 +- .../index/store/FsDirectoryService.java | 18 +--- .../elasticsearch/index/store/IndexStore.java | 78 ++++++-------- .../org/elasticsearch/index/store/Store.java | 53 ++------- .../suggest/stats/ShardSuggestMetric.java | 5 - .../index/translog/TranslogConfig.java | 17 ++- .../index/warmer/ShardIndexWarmerService.java | 6 +- .../elasticsearch/indices/IndicesService.java | 54 +++------- .../cluster/IndicesClusterStateService.java | 27 +---- .../indices/recovery/RecoverySource.java | 10 +- .../indices/recovery/RecoveryTarget.java | 5 +- .../TransportNodesListShardStoreMetaData.java | 10 +- .../elasticsearch/search/SearchService.java | 25 +---- .../search/internal/DefaultSearchContext.java | 2 +- .../elasticsearch/index/IndexModuleTests.java | 58 ++++++++-- .../index/analysis/AnalysisModuleTests.java | 6 +- .../index/analysis/AnalysisServiceTests.java | 13 +-- .../index/analysis/AnalysisTestsHelper.java | 7 +- .../index/analysis/CharFilterTests.java | 9 +- .../index/analysis/CompoundAnalysisTests.java | 9 +- .../analysis/NGramTokenizerFactoryTests.java | 37 +++---- .../PatternCaptureTokenFilterTests.java | 11 +- .../index/analysis/StopAnalyzerTests.java | 6 +- .../filter1/MyFilterTokenFilterFactory.java | 7 +- .../synonyms/SynonymsAnalysisTests.java | 6 +- .../cache/bitset/BitSetFilterCacheTests.java | 12 ++- .../index/engine/InternalEngineTests.java | 34 +++--- .../index/engine/ShadowEngineTests.java | 21 ++-- .../fielddata/AbstractFieldDataTestCase.java | 2 +- .../fielddata/IndexFieldDataServiceTests.java | 13 ++- .../externalvalues/RegisterExternalTypes.java | 8 +- .../mapper/multifield/MultiFieldTests.java | 2 +- .../mapper/simple/SimpleMapperTests.java | 4 +- .../string/SimpleStringMappingTests.java | 4 +- .../index/query/AbstractQueryTestCase.java | 11 +- .../index/query/TemplateQueryParserTests.java | 12 +-- .../index/query/WrapperQueryBuilderTests.java | 2 +- .../index/search/MultiMatchQueryTests.java | 2 +- .../index/shard/IndexShardTests.java | 21 +--- .../index/shard/MergePolicySettingsTests.java | 10 +- .../index/shard/NewPathForShardTests.java | 14 ++- .../index/shard/ShardPathTests.java | 24 +++-- .../similarity/SimilarityModuleTests.java | 13 ++- .../index/store/CorruptedFileIT.java | 3 +- .../index/store/IndexStoreTests.java | 14 ++- .../elasticsearch/index/store/StoreTests.java | 63 ++++++----- .../index/translog/BufferedTranslogTests.java | 6 +- .../index/translog/TranslogTests.java | 8 +- .../indices/IndicesLifecycleListenerIT.java | 12 +-- ...dicesLifecycleListenerSingleNodeTests.java | 5 +- .../indices/IndicesServiceTests.java | 18 ++-- .../recovery/RecoverySourceHandlerTests.java | 11 +- .../test/ESTokenStreamTestCase.java | 1 + .../test/IndexNameAndSettingsModule.java} | 22 ++-- .../test/InternalTestCluster.java | 2 +- .../test/store/MockFSDirectoryService.java | 11 +- .../test/store/MockFSIndexStore.java | 26 +++-- .../IcuCollationTokenFilterFactory.java | 7 +- .../IcuFoldingTokenFilterFactory.java | 7 +- .../IcuNormalizerCharFilterFactory.java | 7 +- .../IcuNormalizerTokenFilterFactory.java | 7 +- .../index/analysis/IcuTokenizerFactory.java | 9 +- .../IcuTransformTokenFilterFactory.java | 7 +- .../index/analysis/AnalysisTestUtils.java | 6 +- .../JapaneseStopTokenFilterFactory.java | 7 +- .../analysis/KuromojiAnalyzerProvider.java | 7 +- .../KuromojiBaseFormFilterFactory.java | 7 +- ...uromojiIterationMarkCharFilterFactory.java | 7 +- .../KuromojiKatakanaStemmerFactory.java | 7 +- .../KuromojiPartOfSpeechFilterFactory.java | 7 +- .../KuromojiReadingFormFilterFactory.java | 7 +- .../analysis/KuromojiTokenizerFactory.java | 7 +- .../index/analysis/KuromojiAnalysisTests.java | 6 +- .../analysis/PhoneticTokenFilterFactory.java | 7 +- .../analysis/SimplePhoneticAnalysisTests.java | 6 +- .../SmartChineseAnalyzerProvider.java | 8 +- .../SmartChineseNoOpTokenFilterFactory.java | 7 +- ...SmartChineseTokenizerTokenizerFactory.java | 9 +- .../SimpleSmartChineseAnalysisTests.java | 6 +- .../analysis/pl/PolishAnalyzerProvider.java | 8 +- .../pl/PolishStemTokenFilterFactory.java | 7 +- .../index/analysis/PolishAnalysisTests.java | 6 +- .../SimplePolishTokenFilterTests.java | 6 +- .../murmur3/RegisterMurmur3FieldMapper.java | 7 +- .../mapper/size/RegisterSizeFieldMapper.java | 7 +- .../smbmmapfs/SmbMmapFsDirectoryService.java | 5 +- .../store/smbmmapfs/SmbMmapFsIndexStore.java | 12 +-- .../SmbSimpleFsDirectoryService.java | 5 +- .../smbsimplefs/SmbSimpleFsIndexStore.java | 16 +-- 264 files changed, 1290 insertions(+), 1778 deletions(-) delete mode 100644 core/src/main/java/org/elasticsearch/index/IndexNameModule.java create mode 100644 core/src/main/java/org/elasticsearch/index/IndexSettings.java delete mode 100644 core/src/main/java/org/elasticsearch/index/settings/IndexSettings.java delete mode 100644 core/src/main/java/org/elasticsearch/index/settings/IndexSettingsProvider.java delete mode 100644 core/src/main/java/org/elasticsearch/index/settings/IndexSettingsService.java rename core/src/{main/java/org/elasticsearch/index/settings/IndexSettingsModule.java => test/java/org/elasticsearch/test/IndexNameAndSettingsModule.java} (70%) diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java index 9defa79f2f8..6860b937554 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java @@ -27,12 +27,14 @@ import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.analysis.AnalysisService; import org.elasticsearch.index.analysis.NamedAnalyzer; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.similarity.SimilarityService; import org.elasticsearch.script.ScriptService; +import java.util.Collections; import java.util.Set; import static java.util.Collections.unmodifiableSet; @@ -216,11 +218,14 @@ public class MetaDataIndexUpgradeService extends AbstractComponent { Index index = new Index(indexMetaData.getIndex()); Settings settings = indexMetaData.getSettings(); try { - SimilarityService similarityService = new SimilarityService(index, settings); // We cannot instantiate real analysis server at this point because the node might not have // been started yet. However, we don't really need real analyzers at this stage - so we can fake it - try (AnalysisService analysisService = new FakeAnalysisService(index, settings)) { - try (MapperService mapperService = new MapperService(index, settings, analysisService, similarityService, scriptService)) { + IndexSettings indexSettings = new IndexSettings(new Index(indexMetaData.getIndex()), Settings.settingsBuilder().put(settings).put(indexMetaData.getSettings()).build(), Collections.EMPTY_LIST); + SimilarityService similarityService = new SimilarityService(indexSettings, Collections.EMPTY_MAP); + + + try (AnalysisService analysisService = new FakeAnalysisService(indexSettings)) { + try (MapperService mapperService = new MapperService(indexSettings, analysisService, similarityService, scriptService)) { for (ObjectCursor cursor : indexMetaData.getMappings().values()) { MappingMetaData mappingMetaData = cursor.value; mapperService.merge(mappingMetaData.type(), mappingMetaData.source(), false, false); @@ -253,8 +258,8 @@ public class MetaDataIndexUpgradeService extends AbstractComponent { } }; - public FakeAnalysisService(Index index, Settings indexSettings) { - super(index, indexSettings); + public FakeAnalysisService(IndexSettings indexSettings) { + super(indexSettings); } @Override diff --git a/core/src/main/java/org/elasticsearch/common/settings/Settings.java b/core/src/main/java/org/elasticsearch/common/settings/Settings.java index 663abd746f0..2a45b6ffc6d 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/Settings.java +++ b/core/src/main/java/org/elasticsearch/common/settings/Settings.java @@ -36,6 +36,7 @@ import org.elasticsearch.common.unit.SizeValue; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.index.IndexSettings; import java.io.IOException; import java.io.InputStream; diff --git a/core/src/main/java/org/elasticsearch/env/NodeEnvironment.java b/core/src/main/java/org/elasticsearch/env/NodeEnvironment.java index 8c599995b9b..288a21a76fb 100644 --- a/core/src/main/java/org/elasticsearch/env/NodeEnvironment.java +++ b/core/src/main/java/org/elasticsearch/env/NodeEnvironment.java @@ -38,7 +38,6 @@ import org.elasticsearch.common.io.FileSystemUtils; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.store.FsDirectoryService; import org.elasticsearch.monitor.fs.FsInfo; @@ -309,7 +308,7 @@ public class NodeEnvironment extends AbstractComponent implements Closeable { * @param shardId the id of the shard to delete to delete * @throws IOException if an IOException occurs */ - public void deleteShardDirectorySafe(ShardId shardId, @IndexSettings Settings indexSettings) throws IOException { + public void deleteShardDirectorySafe(ShardId shardId, Settings indexSettings) throws IOException { // This is to ensure someone doesn't use Settings.EMPTY assert indexSettings != Settings.EMPTY; final Path[] paths = availableShardPaths(shardId); @@ -326,7 +325,7 @@ public class NodeEnvironment extends AbstractComponent implements Closeable { * * @throws LockObtainFailedException if any of the locks could not be acquired */ - public static void acquireFSLockForPaths(@IndexSettings Settings indexSettings, Path... shardPaths) throws IOException { + public static void acquireFSLockForPaths(Settings indexSettings, Path... shardPaths) throws IOException { Lock[] locks = new Lock[shardPaths.length]; Directory[] dirs = new Directory[shardPaths.length]; try { @@ -360,7 +359,7 @@ public class NodeEnvironment extends AbstractComponent implements Closeable { * @throws IOException if an IOException occurs * @throws ElasticsearchException if the write.lock is not acquirable */ - public void deleteShardDirectoryUnderLock(ShardLock lock, @IndexSettings Settings indexSettings) throws IOException { + public void deleteShardDirectoryUnderLock(ShardLock lock, Settings indexSettings) throws IOException { assert indexSettings != Settings.EMPTY; final ShardId shardId = lock.getShardId(); assert isShardLocked(shardId) : "shard " + shardId + " is not locked"; @@ -398,7 +397,7 @@ public class NodeEnvironment extends AbstractComponent implements Closeable { * @param indexSettings settings for the index being deleted * @throws IOException if any of the shards data directories can't be locked or deleted */ - public void deleteIndexDirectorySafe(Index index, long lockTimeoutMS, @IndexSettings Settings indexSettings) throws IOException { + public void deleteIndexDirectorySafe(Index index, long lockTimeoutMS, Settings indexSettings) throws IOException { // This is to ensure someone doesn't use Settings.EMPTY assert indexSettings != Settings.EMPTY; final List locks = lockAllForIndex(index, indexSettings, lockTimeoutMS); @@ -416,7 +415,7 @@ public class NodeEnvironment extends AbstractComponent implements Closeable { * @param index the index to delete * @param indexSettings settings for the index being deleted */ - public void deleteIndexDirectoryUnderLock(Index index, @IndexSettings Settings indexSettings) throws IOException { + public void deleteIndexDirectoryUnderLock(Index index, Settings indexSettings) throws IOException { // This is to ensure someone doesn't use Settings.EMPTY assert indexSettings != Settings.EMPTY; final Path[] indexPaths = indexPaths(index); @@ -439,7 +438,7 @@ public class NodeEnvironment extends AbstractComponent implements Closeable { * @return the {@link ShardLock} instances for this index. * @throws IOException if an IOException occurs. */ - public List lockAllForIndex(Index index, @IndexSettings Settings settings, long lockTimeoutMS) throws IOException { + public List lockAllForIndex(Index index, Settings settings, long lockTimeoutMS) throws IOException { final Integer numShards = settings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_SHARDS, null); if (numShards == null || numShards <= 0) { throw new IllegalArgumentException("settings must contain a non-null > 0 number of shards"); @@ -785,7 +784,7 @@ public class NodeEnvironment extends AbstractComponent implements Closeable { * @param indexSettings settings for an index * @return true if the index has a custom data path */ - public static boolean hasCustomDataPath(@IndexSettings Settings indexSettings) { + public static boolean hasCustomDataPath(Settings indexSettings) { return indexSettings.get(IndexMetaData.SETTING_DATA_PATH) != null; } @@ -796,7 +795,7 @@ public class NodeEnvironment extends AbstractComponent implements Closeable { * * @param indexSettings settings for the index */ - private Path resolveCustomLocation(@IndexSettings Settings indexSettings) { + private Path resolveCustomLocation(Settings indexSettings) { assert indexSettings != Settings.EMPTY; String customDataDir = indexSettings.get(IndexMetaData.SETTING_DATA_PATH); if (customDataDir != null) { @@ -820,7 +819,7 @@ public class NodeEnvironment extends AbstractComponent implements Closeable { * @param indexSettings settings for the index * @param indexName index to resolve the path for */ - private Path resolveCustomLocation(@IndexSettings Settings indexSettings, final String indexName) { + private Path resolveCustomLocation(Settings indexSettings, final String indexName) { return resolveCustomLocation(indexSettings).resolve(indexName); } @@ -832,7 +831,7 @@ public class NodeEnvironment extends AbstractComponent implements Closeable { * @param indexSettings settings for the index * @param shardId shard to resolve the path to */ - public Path resolveCustomLocation(@IndexSettings Settings indexSettings, final ShardId shardId) { + public Path resolveCustomLocation(Settings indexSettings, final ShardId shardId) { return resolveCustomLocation(indexSettings, shardId.index().name()).resolve(Integer.toString(shardId.id())); } diff --git a/core/src/main/java/org/elasticsearch/gateway/PrimaryShardAllocator.java b/core/src/main/java/org/elasticsearch/gateway/PrimaryShardAllocator.java index bf22ad2b2ee..e94102d4623 100644 --- a/core/src/main/java/org/elasticsearch/gateway/PrimaryShardAllocator.java +++ b/core/src/main/java/org/elasticsearch/gateway/PrimaryShardAllocator.java @@ -30,15 +30,8 @@ import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.cluster.routing.allocation.decider.Decision; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.settings.IndexSettings; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; /** * The primary shard allocator allocates primary shard that were not created as @@ -77,8 +70,9 @@ public abstract class PrimaryShardAllocator extends AbstractComponent { } IndexMetaData indexMetaData = metaData.index(shard.getIndex()); + Settings indexSettings = Settings.builder().put(settings).put(indexMetaData.getSettings()).build(); - NodesAndVersions nodesAndVersions = buildNodesAndVersions(shard, recoverOnAnyNode(indexMetaData.getSettings()), allocation.getIgnoreNodes(shard.shardId()), shardState); + NodesAndVersions nodesAndVersions = buildNodesAndVersions(shard, recoverOnAnyNode(indexSettings), allocation.getIgnoreNodes(shard.shardId()), shardState); logger.debug("[{}][{}] found {} allocations of {}, highest version: [{}]", shard.index(), shard.id(), nodesAndVersions.allocationsFound, shard, nodesAndVersions.highestVersion); if (isEnoughAllocationsFound(shard, indexMetaData, nodesAndVersions) == false) { @@ -263,7 +257,7 @@ public abstract class PrimaryShardAllocator extends AbstractComponent { * Return {@code true} if the index is configured to allow shards to be * recovered on any node */ - private boolean recoverOnAnyNode(@IndexSettings Settings idxSettings) { + private boolean recoverOnAnyNode(Settings idxSettings) { return IndexMetaData.isOnSharedFilesystem(idxSettings) && idxSettings.getAsBoolean(IndexMetaData.SETTING_SHARED_FS_ALLOW_RECOVERY_ON_ANY_NODE, false); } diff --git a/core/src/main/java/org/elasticsearch/gateway/TransportNodesListGatewayStartedShards.java b/core/src/main/java/org/elasticsearch/gateway/TransportNodesListGatewayStartedShards.java index 44b889c9b1a..33740d5528a 100644 --- a/core/src/main/java/org/elasticsearch/gateway/TransportNodesListGatewayStartedShards.java +++ b/core/src/main/java/org/elasticsearch/gateway/TransportNodesListGatewayStartedShards.java @@ -39,6 +39,8 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.NodeEnvironment; +import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardPath; import org.elasticsearch.index.shard.ShardStateMetaData; @@ -48,6 +50,7 @@ import org.elasticsearch.transport.TransportService; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.concurrent.atomic.AtomicReferenceArray; @@ -128,7 +131,8 @@ public class TransportNodesListGatewayStartedShards extends TransportNodesAction if (metaData != null) { ShardPath shardPath = null; try { - shardPath = ShardPath.loadShardPath(logger, nodeEnv, shardId, metaData.getSettings()); + IndexSettings indexSettings = new IndexSettings(new Index(metaData.getIndex()), Settings.settingsBuilder().put(settings).put(metaData.getSettings()).build(), Collections.EMPTY_LIST); + shardPath = ShardPath.loadShardPath(logger, nodeEnv, shardId, indexSettings); if (shardPath == null) { throw new IllegalStateException(shardId + " no shard path found"); } diff --git a/core/src/main/java/org/elasticsearch/index/AbstractIndexComponent.java b/core/src/main/java/org/elasticsearch/index/AbstractIndexComponent.java index b229b365665..8244f633939 100644 --- a/core/src/main/java/org/elasticsearch/index/AbstractIndexComponent.java +++ b/core/src/main/java/org/elasticsearch/index/AbstractIndexComponent.java @@ -23,7 +23,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.settings.IndexSettings; /** * @@ -32,32 +31,23 @@ public abstract class AbstractIndexComponent implements IndexComponent { protected final ESLogger logger; protected final DeprecationLogger deprecationLogger; - protected final Index index; - protected final Settings indexSettings; + protected final IndexSettings indexSettings; /** * Constructs a new index component, with the index name and its settings. - * - * @param index The index name - * @param indexSettings The index settings */ - protected AbstractIndexComponent(Index index, @IndexSettings Settings indexSettings) { - this.index = index; - this.indexSettings = indexSettings; - this.logger = Loggers.getLogger(getClass(), indexSettings, index); + protected AbstractIndexComponent(IndexSettings indexSettings) { + this.logger = Loggers.getLogger(getClass(), indexSettings.getSettings(), indexSettings.getIndex()); this.deprecationLogger = new DeprecationLogger(logger); + this.indexSettings = indexSettings; } @Override public Index index() { - return this.index; + return indexSettings.getIndex(); } - public Settings indexSettings() { + public IndexSettings getIndexSettings() { return indexSettings; } - - public String nodeName() { - return indexSettings.get("name", ""); - } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/index/CompositeIndexEventListener.java b/core/src/main/java/org/elasticsearch/index/CompositeIndexEventListener.java index 8165f5a365f..f4ddd75ba85 100644 --- a/core/src/main/java/org/elasticsearch/index/CompositeIndexEventListener.java +++ b/core/src/main/java/org/elasticsearch/index/CompositeIndexEventListener.java @@ -24,7 +24,6 @@ import org.elasticsearch.common.Nullable; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.shard.IndexShard; import org.elasticsearch.index.shard.IndexShardState; import org.elasticsearch.index.shard.IndexEventListener; @@ -43,14 +42,14 @@ final class CompositeIndexEventListener implements IndexEventListener { private final List listeners; private final ESLogger logger; - CompositeIndexEventListener(String index, Settings indexSettings, Collection listeners) { + CompositeIndexEventListener(IndexSettings indexSettings, Collection listeners) { for (IndexEventListener listener : listeners) { if (listener == null) { throw new IllegalArgumentException("listeners must be non-null"); } } this.listeners = Collections.unmodifiableList(new ArrayList<>(listeners)); - this.logger = Loggers.getLogger(getClass(), indexSettings, index); + this.logger = Loggers.getLogger(getClass(), indexSettings.getSettings(), indexSettings.getIndex()); } @Override @@ -139,7 +138,7 @@ final class CompositeIndexEventListener implements IndexEventListener { } @Override - public void beforeIndexCreated(Index index, @IndexSettings Settings indexSettings) { + public void beforeIndexCreated(Index index, Settings indexSettings) { for (IndexEventListener listener : listeners) { try { listener.beforeIndexCreated(index, indexSettings); @@ -199,7 +198,7 @@ final class CompositeIndexEventListener implements IndexEventListener { } @Override - public void afterIndexDeleted(Index index, @IndexSettings Settings indexSettings) { + public void afterIndexDeleted(Index index, Settings indexSettings) { for (IndexEventListener listener : listeners) { try { listener.afterIndexDeleted(index, indexSettings); @@ -211,7 +210,7 @@ final class CompositeIndexEventListener implements IndexEventListener { } @Override - public void afterIndexClosed(Index index, @IndexSettings Settings indexSettings) { + public void afterIndexClosed(Index index, Settings indexSettings) { for (IndexEventListener listener : listeners) { try { listener.afterIndexClosed(index, indexSettings); @@ -224,7 +223,7 @@ final class CompositeIndexEventListener implements IndexEventListener { @Override public void beforeIndexShardDeleted(ShardId shardId, - @IndexSettings Settings indexSettings) { + Settings indexSettings) { for (IndexEventListener listener : listeners) { try { listener.beforeIndexShardDeleted(shardId, indexSettings); @@ -237,7 +236,7 @@ final class CompositeIndexEventListener implements IndexEventListener { @Override public void afterIndexShardDeleted(ShardId shardId, - @IndexSettings Settings indexSettings) { + Settings indexSettings) { for (IndexEventListener listener : listeners) { try { listener.afterIndexShardDeleted(shardId, indexSettings); @@ -249,7 +248,7 @@ final class CompositeIndexEventListener implements IndexEventListener { } @Override - public void beforeIndexAddedToCluster(Index index, @IndexSettings Settings indexSettings) { + public void beforeIndexAddedToCluster(Index index, Settings indexSettings) { for (IndexEventListener listener : listeners) { try { listener.beforeIndexAddedToCluster(index, indexSettings); diff --git a/core/src/main/java/org/elasticsearch/index/IndexModule.java b/core/src/main/java/org/elasticsearch/index/IndexModule.java index a6c6e93fb49..b1148ddbac3 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexModule.java +++ b/core/src/main/java/org/elasticsearch/index/IndexModule.java @@ -31,8 +31,8 @@ import org.elasticsearch.index.shard.IndexEventListener; import org.elasticsearch.index.shard.IndexSearcherWrapper; import java.util.HashSet; -import java.util.List; import java.util.Set; +import java.util.function.Consumer; /** * @@ -40,21 +40,33 @@ import java.util.Set; public class IndexModule extends AbstractModule { private final IndexMetaData indexMetaData; - private final Settings settings; + private final IndexSettings indexSettings; // pkg private so tests can mock Class engineFactoryImpl = InternalEngineFactory.class; Class indexSearcherWrapper = null; + private final Set> settingsConsumers = new HashSet<>(); private final Set indexEventListeners = new HashSet<>(); private IndexEventListener listener; - public IndexModule(Settings settings, IndexMetaData indexMetaData) { + public IndexModule(IndexSettings indexSettings, IndexMetaData indexMetaData) { this.indexMetaData = indexMetaData; - this.settings = settings; + this.indexSettings = indexSettings; + } + + public void addIndexSettingsListener(Consumer listener) { + if (listener == null) { + throw new IllegalArgumentException("listener must not be null"); + } + + if (settingsConsumers.contains(listener)) { + throw new IllegalStateException("listener already registered"); + } + settingsConsumers.add(listener); } public Settings getIndexSettings() { - return settings; + return indexSettings.getSettings(); } public void addIndexEventListener(IndexEventListener listener) { @@ -74,7 +86,7 @@ public class IndexModule extends AbstractModule { public IndexEventListener freeze() { // TODO somehow we need to make this pkg private... if (listener == null) { - listener = new CompositeIndexEventListener(indexMetaData.getIndex(), settings, indexEventListeners); + listener = new CompositeIndexEventListener(indexSettings, indexEventListeners); } return listener; } @@ -93,5 +105,7 @@ public class IndexModule extends AbstractModule { bind(IndexServicesProvider.class).asEagerSingleton(); bind(MapperService.class).asEagerSingleton(); bind(IndexFieldDataService.class).asEagerSingleton(); + bind(IndexSettings.class).toInstance(new IndexSettings(indexSettings.getIndex(), indexSettings.getSettings(), settingsConsumers)); } + } diff --git a/core/src/main/java/org/elasticsearch/index/IndexNameModule.java b/core/src/main/java/org/elasticsearch/index/IndexNameModule.java deleted file mode 100644 index 0a2ee1c1e63..00000000000 --- a/core/src/main/java/org/elasticsearch/index/IndexNameModule.java +++ /dev/null @@ -1,39 +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; - -import org.elasticsearch.common.inject.AbstractModule; - -/** - * - */ -public class IndexNameModule extends AbstractModule { - - private final Index index; - - public IndexNameModule(Index index) { - this.index = index; - } - - @Override - protected void configure() { - bind(Index.class).toInstance(index); - } -} diff --git a/core/src/main/java/org/elasticsearch/index/IndexService.java b/core/src/main/java/org/elasticsearch/index/IndexService.java index f07a37cd220..ec5e52b21b6 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexService.java +++ b/core/src/main/java/org/elasticsearch/index/IndexService.java @@ -24,7 +24,6 @@ import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.Query; import org.apache.lucene.util.Accountable; import org.apache.lucene.util.IOUtils; -import org.elasticsearch.ElasticsearchException; import org.elasticsearch.cluster.metadata.AliasMetaData; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.routing.ShardRouting; @@ -46,7 +45,6 @@ import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.query.IndexQueryParserService; import org.elasticsearch.index.query.ParsedQuery; -import org.elasticsearch.index.settings.IndexSettingsService; import org.elasticsearch.index.shard.*; import org.elasticsearch.index.similarity.SimilarityService; import org.elasticsearch.index.store.IndexStore; @@ -59,6 +57,7 @@ import java.nio.file.Path; import java.util.*; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Consumer; import static java.util.Collections.emptyMap; import static java.util.Collections.unmodifiableMap; @@ -73,7 +72,6 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone private final AnalysisService analysisService; private final IndexFieldDataService indexFieldData; private final BitsetFilterCache bitsetFilterCache; - private final IndexSettingsService settingsService; private final NodeEnvironment nodeEnv; private final IndicesService indicesServices; private final IndexServicesProvider indexServicesProvider; @@ -82,22 +80,22 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone private final AtomicBoolean closed = new AtomicBoolean(false); private final AtomicBoolean deleted = new AtomicBoolean(false); private volatile IndexMetaData indexMetaData; + private final IndexSettings indexSettings; @Inject - public IndexService(Index index, IndexMetaData indexMetaData, NodeEnvironment nodeEnv, + public IndexService(IndexSettings indexSettings, IndexMetaData indexMetaData, NodeEnvironment nodeEnv, AnalysisService analysisService, - IndexSettingsService settingsService, IndexFieldDataService indexFieldData, BitsetFilterCache bitSetFilterCache, IndicesService indicesServices, IndexServicesProvider indexServicesProvider, IndexStore indexStore, IndexEventListener eventListener) { - super(index, settingsService.indexSettings()); + super(indexSettings); assert indexMetaData != null; + this.indexSettings = indexSettings; this.analysisService = analysisService; this.indexFieldData = indexFieldData; - this.settingsService = settingsService; this.bitsetFilterCache = bitSetFilterCache; this.indicesServices = indicesServices; this.eventListener = eventListener; @@ -140,18 +138,12 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone public IndexShard getShard(int shardId) { IndexShard indexShard = getShardOrNull(shardId); if (indexShard == null) { - throw new ShardNotFoundException(new ShardId(index, shardId)); + throw new ShardNotFoundException(new ShardId(index(), shardId)); } return indexShard; } - public Set shardIds() { - return shards.keySet(); - } - - public IndexSettingsService settingsService() { - return this.settingsService; - } + public Set shardIds() { return shards.keySet(); } public IndexCache cache() { return indexServicesProvider.getIndexCache(); @@ -197,7 +189,7 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone public String indexUUID() { - return indexSettings.get(IndexMetaData.SETTING_INDEX_UUID, IndexMetaData.INDEX_UUID_NA_VALUE); + return indexSettings.getUUID(); } // NOTE: O(numShards) cost, but numShards should be smallish? @@ -223,10 +215,10 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone * keep it synced. */ if (closed.get()) { - throw new IllegalStateException("Can't create shard [" + index.name() + "][" + sShardId + "], closed"); + throw new IllegalStateException("Can't create shard [" + index().name() + "][" + sShardId + "], closed"); } - final Settings indexSettings = settingsService.getSettings(); - final ShardId shardId = new ShardId(index, sShardId); + final Settings indexSettings = this.indexSettings.getSettings(); + final ShardId shardId = new ShardId(index(), sShardId); boolean success = false; Store store = null; IndexShard indexShard = null; @@ -235,12 +227,12 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone eventListener.beforeIndexShardCreated(shardId, indexSettings); ShardPath path; try { - path = ShardPath.loadShardPath(logger, nodeEnv, shardId, indexSettings); + path = ShardPath.loadShardPath(logger, nodeEnv, shardId, this.indexSettings); } catch (IllegalStateException ex) { logger.warn("{} failed to load shard path, trying to remove leftover", shardId); try { - ShardPath.deleteLeftoverShardDirectory(logger, nodeEnv, lock, indexSettings); - path = ShardPath.loadShardPath(logger, nodeEnv, shardId, indexSettings); + ShardPath.deleteLeftoverShardDirectory(logger, nodeEnv, lock, this.indexSettings); + path = ShardPath.loadShardPath(logger, nodeEnv, shardId, this.indexSettings); } catch (Throwable t) { t.addSuppressed(ex); throw t; @@ -260,7 +252,7 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone } dataPathToShardCount.put(dataPath, curCount+1); } - path = ShardPath.selectNewPathForShard(nodeEnv, shardId, indexSettings, routing.getExpectedShardSize() == ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE ? getAvgShardSizeInBytes() : routing.getExpectedShardSize(), + path = ShardPath.selectNewPathForShard(nodeEnv, shardId, this.indexSettings, routing.getExpectedShardSize() == ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE ? getAvgShardSizeInBytes() : routing.getExpectedShardSize(), dataPathToShardCount); logger.debug("{} creating using a new path [{}]", shardId, path); } else { @@ -275,16 +267,15 @@ 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)); - store = new Store(shardId, indexSettings, indexStore.newDirectoryService(path), lock, new StoreCloseListener(shardId, canDeleteShardContent, () -> indexServicesProvider.getIndicesQueryCache().onClose(shardId))); + store = new Store(shardId, this.indexSettings, indexStore.newDirectoryService(path), lock, new StoreCloseListener(shardId, canDeleteShardContent, () -> indexServicesProvider.getIndicesQueryCache().onClose(shardId))); if (useShadowEngine(primary, indexSettings)) { - indexShard = new ShadowIndexShard(shardId, indexSettings, path, store, indexServicesProvider); + indexShard = new ShadowIndexShard(shardId, this.indexSettings, path, store, indexServicesProvider); } else { - indexShard = new IndexShard(shardId, indexSettings, path, store, indexServicesProvider); + indexShard = new IndexShard(shardId, this.indexSettings, path, store, indexServicesProvider); } eventListener.indexShardStateChanged(indexShard, null, indexShard.state(), "shard created"); eventListener.afterIndexShardCreated(indexShard); - settingsService.addListener(indexShard); shards = newMapBuilder(shards).put(shardId.id(), indexShard).immutableMap(); success = true; return indexShard; @@ -301,7 +292,7 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone } public synchronized void removeShard(int shardId, String reason) { - final ShardId sId = new ShardId(index, shardId); + final ShardId sId = new ShardId(index(), shardId); final IndexShard indexShard; if (shards.containsKey(shardId) == false) { return; @@ -316,7 +307,7 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone private void closeShard(String reason, ShardId sId, IndexShard indexShard, Store store, IndexEventListener listener) { final int shardId = sId.id(); - final Settings indexSettings = settingsService.getSettings(); + final Settings indexSettings = this.getIndexSettings().getSettings(); try { try { listener.beforeIndexShardClosed(sId, indexShard, indexSettings); @@ -324,7 +315,6 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone // this logic is tricky, we want to close the engine so we rollback the changes done to it // and close the shard so no operations are allowed to it if (indexShard != null) { - settingsService.removeListener(indexShard); try { final boolean flushEngine = deleted.get() == false && closed.get(); // only flush we are we closed (closed index or shutdown) and if we are not deleted indexShard.close(reason, flushEngine); @@ -348,7 +338,7 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone private void onShardClose(ShardLock lock, boolean ownsShard) { if (deleted.get()) { // we remove that shards content if this index has been deleted - final Settings indexSettings = settingsService.getSettings(); + final Settings indexSettings = this.getIndexSettings().getSettings(); try { if (ownsShard) { try { @@ -369,6 +359,10 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone return indexServicesProvider; } + public IndexSettings getIndexSettings() { + return indexSettings; + } + private class StoreCloseListener implements Store.OnClose { private final ShardId shardId; private final boolean ownsShard; @@ -396,10 +390,6 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone } } - public Settings getIndexSettings() { - return settingsService.getSettings(); - } - private static final class BitsetCacheListener implements BitsetFilterCache.Listener { final IndexService indexService; @@ -473,7 +463,7 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone AliasMetaData alias = aliases.get(aliasNames[0]); if (alias == null) { // This shouldn't happen unless alias disappeared after filteringAliases was called. - throw new InvalidAliasNameException(index, aliasNames[0], "Unknown alias name was passed to alias Filter"); + throw new InvalidAliasNameException(index(), aliasNames[0], "Unknown alias name was passed to alias Filter"); } return parse(alias, indexQueryParser); } else { @@ -516,8 +506,22 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone return indexMetaData; } - public void updateMetaData(IndexMetaData metadata) { + public synchronized void updateMetaData(final IndexMetaData metadata) { this.indexMetaData = metadata; + Settings settings = metadata.getSettings(); + if (this.indexSettings.updateSettings(metadata.getSettings())) { + for (final IndexShard shard : this.shards.values()) { + try { + shard.onRefreshSettings(settings); + } catch (Exception e) { + logger.warn("[{}] failed to refresh shard settings", e, shard.shardId().id()); + } + } + try { + indexStore.onRefreshSettings(settings); + } catch (Exception e) { + logger.warn("failed to refresh index store settings", e); + } + } } - } diff --git a/core/src/main/java/org/elasticsearch/index/IndexSettings.java b/core/src/main/java/org/elasticsearch/index/IndexSettings.java new file mode 100644 index 00000000000..71c95436587 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/index/IndexSettings.java @@ -0,0 +1,101 @@ +/* + * 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; + +import org.elasticsearch.Version; +import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.Loggers; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.env.NodeEnvironment; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.function.Consumer; + +// TODO add javadocs - this also needs a dedicated unit test +public final class IndexSettings { + private volatile Settings settings; + private final List> updateListeners; + private final Index index; + private final Version version; + private final ESLogger logger; + + public IndexSettings(Index index) { + this(index, Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(), Collections.EMPTY_LIST); + } + + public IndexSettings(Index index, Settings settings, Collection> updateListeners) { + this.settings = settings; + this.updateListeners = Collections.unmodifiableList(new ArrayList<>(updateListeners)); + this.index = index; + version = Version.indexCreated(settings); + logger = Loggers.getLogger(getClass(), settings, index); + } + + public Settings getSettings() { + return settings; + } + + public Index getIndex() { + return index; + } + + public String getUUID() { + return settings.get(IndexMetaData.SETTING_INDEX_UUID, IndexMetaData.INDEX_UUID_NA_VALUE); + } + + public boolean hasCustomDataPath() { + return NodeEnvironment.hasCustomDataPath(settings); + } + + public Version getVersion() { + return version; + } + + public String getNodeName() { + return settings.get("name", ""); + } + + synchronized boolean updateSettings(Settings settings) { + if (Version.indexCreated(settings) != version) { + throw new IllegalStateException("version mismatch on settings update"); + } + + if (this.settings.getByPrefix(IndexMetaData.INDEX_SETTING_PREFIX).getAsMap().equals(settings.getByPrefix(IndexMetaData.INDEX_SETTING_PREFIX).getAsMap())) { + // nothing to update, same settings + return false; + } + this.settings = Settings.builder().put(this.settings).put(settings).build(); + for (final Consumer consumer : updateListeners) { + try { + consumer.accept(settings); + } catch (Exception e) { + logger.warn("failed to refresh index settings for [{}]", e, settings); + } + } + return true; + } + + List> getUpdateListeners() { // for testing + return updateListeners; + } +} diff --git a/core/src/main/java/org/elasticsearch/index/analysis/ASCIIFoldingTokenFilterFactory.java b/core/src/main/java/org/elasticsearch/index/analysis/ASCIIFoldingTokenFilterFactory.java index 81862618c2f..7e18e461933 100644 --- a/core/src/main/java/org/elasticsearch/index/analysis/ASCIIFoldingTokenFilterFactory.java +++ b/core/src/main/java/org/elasticsearch/index/analysis/ASCIIFoldingTokenFilterFactory.java @@ -24,8 +24,7 @@ import org.apache.lucene.analysis.miscellaneous.ASCIIFoldingFilter; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; /** * Factory for ASCIIFoldingFilter. @@ -34,8 +33,8 @@ public class ASCIIFoldingTokenFilterFactory extends AbstractTokenFilterFactory { private final boolean preserveOriginal; @Inject - public ASCIIFoldingTokenFilterFactory(Index index, @IndexSettings Settings indexSettings, @Assisted String name, @Assisted Settings settings) { - super(index, indexSettings, name, settings); + public ASCIIFoldingTokenFilterFactory(IndexSettings indexSettings, @Assisted String name, @Assisted Settings settings) { + super(indexSettings, name, settings); preserveOriginal = settings.getAsBoolean("preserve_original", false); } diff --git a/core/src/main/java/org/elasticsearch/index/analysis/AbstractCharFilterFactory.java b/core/src/main/java/org/elasticsearch/index/analysis/AbstractCharFilterFactory.java index 29ff6822d02..2e728386ab8 100644 --- a/core/src/main/java/org/elasticsearch/index/analysis/AbstractCharFilterFactory.java +++ b/core/src/main/java/org/elasticsearch/index/analysis/AbstractCharFilterFactory.java @@ -19,10 +19,8 @@ package org.elasticsearch.index.analysis; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.AbstractIndexComponent; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; /** * @@ -31,8 +29,8 @@ public abstract class AbstractCharFilterFactory extends AbstractIndexComponent i private final String name; - public AbstractCharFilterFactory(Index index, @IndexSettings Settings indexSettings, String name) { - super(index, indexSettings); + public AbstractCharFilterFactory(IndexSettings indexSettings, String name) { + super(indexSettings); this.name = name; } diff --git a/core/src/main/java/org/elasticsearch/index/analysis/AbstractIndexAnalyzerProvider.java b/core/src/main/java/org/elasticsearch/index/analysis/AbstractIndexAnalyzerProvider.java index ce050ca2a55..c0406cb806e 100644 --- a/core/src/main/java/org/elasticsearch/index/analysis/AbstractIndexAnalyzerProvider.java +++ b/core/src/main/java/org/elasticsearch/index/analysis/AbstractIndexAnalyzerProvider.java @@ -23,8 +23,7 @@ import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.util.Version; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.AbstractIndexComponent; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; /** * @@ -38,14 +37,13 @@ public abstract class AbstractIndexAnalyzerProvider extends /** * Constructs a new analyzer component, with the index name and its settings and the analyzer name. * - * @param index The index name - * @param indexSettings The index settings + * @param indexSettings the settings and the name of the index * @param name The analyzer name */ - public AbstractIndexAnalyzerProvider(Index index, @IndexSettings Settings indexSettings, String name, Settings settings) { - super(index, indexSettings); + public AbstractIndexAnalyzerProvider(IndexSettings indexSettings, String name, Settings settings) { + super(indexSettings); this.name = name; - this.version = Analysis.parseAnalysisVersion(indexSettings, settings, logger); + this.version = Analysis.parseAnalysisVersion(this.indexSettings.getSettings(), settings, logger); } /** diff --git a/core/src/main/java/org/elasticsearch/index/analysis/AbstractTokenFilterFactory.java b/core/src/main/java/org/elasticsearch/index/analysis/AbstractTokenFilterFactory.java index f4efeda4d94..16096ca8f3f 100644 --- a/core/src/main/java/org/elasticsearch/index/analysis/AbstractTokenFilterFactory.java +++ b/core/src/main/java/org/elasticsearch/index/analysis/AbstractTokenFilterFactory.java @@ -22,8 +22,7 @@ package org.elasticsearch.index.analysis; import org.apache.lucene.util.Version; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.AbstractIndexComponent; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; /** * @@ -34,10 +33,10 @@ public abstract class AbstractTokenFilterFactory extends AbstractIndexComponent protected final Version version; - public AbstractTokenFilterFactory(Index index, @IndexSettings Settings indexSettings, String name, Settings settings) { - super(index, indexSettings); + public AbstractTokenFilterFactory(IndexSettings indexSettings, String name, Settings settings) { + super(indexSettings); this.name = name; - this.version = Analysis.parseAnalysisVersion(indexSettings, settings, logger); + this.version = Analysis.parseAnalysisVersion(this.indexSettings.getSettings(), settings, logger); } @Override diff --git a/core/src/main/java/org/elasticsearch/index/analysis/AbstractTokenizerFactory.java b/core/src/main/java/org/elasticsearch/index/analysis/AbstractTokenizerFactory.java index 94c80bdd763..dafc4b87730 100644 --- a/core/src/main/java/org/elasticsearch/index/analysis/AbstractTokenizerFactory.java +++ b/core/src/main/java/org/elasticsearch/index/analysis/AbstractTokenizerFactory.java @@ -22,8 +22,7 @@ package org.elasticsearch.index.analysis; import org.apache.lucene.util.Version; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.AbstractIndexComponent; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; /** * @@ -35,10 +34,10 @@ public abstract class AbstractTokenizerFactory extends AbstractIndexComponent im protected final Version version; - public AbstractTokenizerFactory(Index index, @IndexSettings Settings indexSettings, String name, Settings settings) { - super(index, indexSettings); + public AbstractTokenizerFactory(IndexSettings indexSettings, String name, Settings settings) { + super(indexSettings); this.name = name; - this.version = Analysis.parseAnalysisVersion(indexSettings, settings, logger); + this.version = Analysis.parseAnalysisVersion(this.indexSettings.getSettings(), settings, logger); } @Override diff --git a/core/src/main/java/org/elasticsearch/index/analysis/Analysis.java b/core/src/main/java/org/elasticsearch/index/analysis/Analysis.java index 827d337a745..27cd9fd8c4c 100644 --- a/core/src/main/java/org/elasticsearch/index/analysis/Analysis.java +++ b/core/src/main/java/org/elasticsearch/index/analysis/Analysis.java @@ -63,21 +63,13 @@ import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; -import org.elasticsearch.index.settings.IndexSettings; import java.io.BufferedReader; import java.io.IOException; import java.io.Reader; import java.nio.charset.StandardCharsets; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; +import java.util.*; import static java.util.Collections.unmodifiableMap; @@ -86,7 +78,7 @@ import static java.util.Collections.unmodifiableMap; */ public class Analysis { - public static Version parseAnalysisVersion(@IndexSettings Settings indexSettings, Settings settings, ESLogger logger) { + public static Version parseAnalysisVersion(Settings indexSettings, Settings settings, ESLogger logger) { // check for explicit version on the specific analyzer component String sVersion = settings.get("version"); if (sVersion != null) { diff --git a/core/src/main/java/org/elasticsearch/index/analysis/AnalysisService.java b/core/src/main/java/org/elasticsearch/index/analysis/AnalysisService.java index ba8b1e083af..25792bf70e7 100644 --- a/core/src/main/java/org/elasticsearch/index/analysis/AnalysisService.java +++ b/core/src/main/java/org/elasticsearch/index/analysis/AnalysisService.java @@ -27,9 +27,8 @@ import org.elasticsearch.common.Strings; 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.index.mapper.core.StringFieldMapper; -import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.indices.analysis.IndicesAnalysisService; import java.io.Closeable; @@ -53,21 +52,21 @@ public class AnalysisService extends AbstractIndexComponent implements Closeable private final NamedAnalyzer defaultSearchQuoteAnalyzer; - public AnalysisService(Index index, Settings indexSettings) { - this(index, indexSettings, null, null, null, null, null); + public AnalysisService(IndexSettings indexSettings) { + this(indexSettings, null, null, null, null, null); } @Inject - public AnalysisService(Index index, @IndexSettings Settings indexSettings, @Nullable IndicesAnalysisService indicesAnalysisService, + public AnalysisService(IndexSettings indexSettings, @Nullable IndicesAnalysisService indicesAnalysisService, @Nullable Map analyzerFactoryFactories, @Nullable Map tokenizerFactoryFactories, @Nullable Map charFilterFactoryFactories, @Nullable Map tokenFilterFactoryFactories) { - super(index, indexSettings); - Settings defaultSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.indexCreated(indexSettings)).build(); + super(indexSettings); + Settings defaultSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, indexSettings.getVersion()).build(); Map tokenizers = new HashMap<>(); if (tokenizerFactoryFactories != null) { - Map tokenizersSettings = indexSettings.getGroups("index.analysis.tokenizer"); + Map tokenizersSettings = this.indexSettings.getSettings().getGroups("index.analysis.tokenizer"); for (Map.Entry entry : tokenizerFactoryFactories.entrySet()) { String tokenizerName = entry.getKey(); TokenizerFactoryFactory tokenizerFactoryFactory = entry.getValue(); @@ -102,7 +101,7 @@ public class AnalysisService extends AbstractIndexComponent implements Closeable Map charFilters = new HashMap<>(); if (charFilterFactoryFactories != null) { - Map charFiltersSettings = indexSettings.getGroups("index.analysis.char_filter"); + Map charFiltersSettings = this.indexSettings.getSettings().getGroups("index.analysis.char_filter"); for (Map.Entry entry : charFilterFactoryFactories.entrySet()) { String charFilterName = entry.getKey(); CharFilterFactoryFactory charFilterFactoryFactory = entry.getValue(); @@ -137,7 +136,7 @@ public class AnalysisService extends AbstractIndexComponent implements Closeable Map tokenFilters = new HashMap<>(); if (tokenFilterFactoryFactories != null) { - Map tokenFiltersSettings = indexSettings.getGroups("index.analysis.filter"); + Map tokenFiltersSettings = this.indexSettings.getSettings().getGroups("index.analysis.filter"); for (Map.Entry entry : tokenFilterFactoryFactories.entrySet()) { String tokenFilterName = entry.getKey(); TokenFilterFactoryFactory tokenFilterFactoryFactory = entry.getValue(); @@ -172,7 +171,7 @@ public class AnalysisService extends AbstractIndexComponent implements Closeable Map analyzerProviders = new HashMap<>(); if (analyzerFactoryFactories != null) { - Map analyzersSettings = indexSettings.getGroups("index.analysis.analyzer"); + Map analyzersSettings = this.indexSettings.getSettings().getGroups("index.analysis.analyzer"); for (Map.Entry entry : analyzerFactoryFactories.entrySet()) { String analyzerName = entry.getKey(); AnalyzerProviderFactory analyzerFactoryFactory = entry.getValue(); @@ -189,7 +188,7 @@ public class AnalysisService extends AbstractIndexComponent implements Closeable if (indicesAnalysisService != null) { for (Map.Entry entry : indicesAnalysisService.analyzerProviderFactories().entrySet()) { String name = entry.getKey(); - Version indexVersion = Version.indexCreated(indexSettings); + Version indexVersion = Version.indexCreated(this.indexSettings.getSettings()); if (!analyzerProviders.containsKey(name)) { analyzerProviders.put(name, entry.getValue().create(name, Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, indexVersion).build())); } @@ -201,7 +200,7 @@ public class AnalysisService extends AbstractIndexComponent implements Closeable } if (!analyzerProviders.containsKey("default")) { - analyzerProviders.put("default", new StandardAnalyzerProvider(index, indexSettings, null, "default", Settings.Builder.EMPTY_SETTINGS)); + analyzerProviders.put("default", new StandardAnalyzerProvider(indexSettings, null, "default", Settings.Builder.EMPTY_SETTINGS)); } if (!analyzerProviders.containsKey("default_index")) { analyzerProviders.put("default_index", analyzerProviders.get("default")); @@ -221,7 +220,7 @@ public class AnalysisService extends AbstractIndexComponent implements Closeable * and 100 afterwards so we override the positionIncrementGap if it * doesn't match here. */ - int overridePositionIncrementGap = StringFieldMapper.Defaults.positionIncrementGap(Version.indexCreated(indexSettings)); + int overridePositionIncrementGap = StringFieldMapper.Defaults.positionIncrementGap(Version.indexCreated(this.indexSettings.getSettings())); if (analyzerFactory instanceof CustomAnalyzerProvider) { ((CustomAnalyzerProvider) analyzerFactory).build(this); /* @@ -250,13 +249,13 @@ public class AnalysisService extends AbstractIndexComponent implements Closeable } analyzers.put(analyzerFactory.name(), analyzer); analyzers.put(Strings.toCamelCase(analyzerFactory.name()), analyzer); - String strAliases = indexSettings.get("index.analysis.analyzer." + analyzerFactory.name() + ".alias"); + String strAliases = this.indexSettings.getSettings().get("index.analysis.analyzer." + analyzerFactory.name() + ".alias"); if (strAliases != null) { for (String alias : Strings.commaDelimitedListToStringArray(strAliases)) { analyzers.put(alias, analyzer); } } - String[] aliases = indexSettings.getAsArray("index.analysis.analyzer." + analyzerFactory.name() + ".alias"); + String[] aliases = this.indexSettings.getSettings().getAsArray("index.analysis.analyzer." + analyzerFactory.name() + ".alias"); for (String alias : aliases) { analyzers.put(alias, analyzer); } @@ -267,11 +266,11 @@ public class AnalysisService extends AbstractIndexComponent implements Closeable throw new IllegalArgumentException("no default analyzer configured"); } if (analyzers.containsKey("default_index")) { - final Version createdVersion = Version.indexCreated(indexSettings); + final Version createdVersion = indexSettings.getVersion(); if (createdVersion.onOrAfter(Version.V_3_0_0)) { - throw new IllegalArgumentException("setting [index.analysis.analyzer.default_index] is not supported anymore, use [index.analysis.analyzer.default] instead for index [" + index.getName() + "]"); + throw new IllegalArgumentException("setting [index.analysis.analyzer.default_index] is not supported anymore, use [index.analysis.analyzer.default] instead for index [" + index().getName() + "]"); } else { - deprecationLogger.deprecated("setting [index.analysis.analyzer.default_index] is deprecated, use [index.analysis.analyzer.default] instead for index [{}]", index.getName()); + deprecationLogger.deprecated("setting [index.analysis.analyzer.default_index] is deprecated, use [index.analysis.analyzer.default] instead for index [{}]", index().getName()); } } defaultIndexAnalyzer = analyzers.containsKey("default_index") ? analyzers.get("default_index") : defaultAnalyzer; diff --git a/core/src/main/java/org/elasticsearch/index/analysis/ApostropheFilterFactory.java b/core/src/main/java/org/elasticsearch/index/analysis/ApostropheFilterFactory.java index 614e860735a..9e907e40f0b 100644 --- a/core/src/main/java/org/elasticsearch/index/analysis/ApostropheFilterFactory.java +++ b/core/src/main/java/org/elasticsearch/index/analysis/ApostropheFilterFactory.java @@ -23,8 +23,7 @@ import org.apache.lucene.analysis.tr.ApostropheFilter; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; /** * Factory for {@link ApostropheFilter} @@ -32,8 +31,8 @@ import org.elasticsearch.index.settings.IndexSettings; public class ApostropheFilterFactory extends AbstractTokenFilterFactory { @Inject - public ApostropheFilterFactory(Index index, @IndexSettings Settings indexSettings, @Assisted String name, @Assisted Settings settings) { - super(index, indexSettings, name, settings); + public ApostropheFilterFactory(IndexSettings indexSettings, @Assisted String name, @Assisted Settings settings) { + super(indexSettings, name, settings); } @Override diff --git a/core/src/main/java/org/elasticsearch/index/analysis/ArabicAnalyzerProvider.java b/core/src/main/java/org/elasticsearch/index/analysis/ArabicAnalyzerProvider.java index c532204b164..7879967ae70 100644 --- a/core/src/main/java/org/elasticsearch/index/analysis/ArabicAnalyzerProvider.java +++ b/core/src/main/java/org/elasticsearch/index/analysis/ArabicAnalyzerProvider.java @@ -25,8 +25,7 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; /** * @@ -36,8 +35,8 @@ public class ArabicAnalyzerProvider extends AbstractIndexAnalyzerProvider scripts = new HashSet<>(Arrays.asList("han", "hiragana", "katakana", "hangul")); diff --git a/core/src/main/java/org/elasticsearch/index/analysis/CJKWidthFilterFactory.java b/core/src/main/java/org/elasticsearch/index/analysis/CJKWidthFilterFactory.java index d1aa0c25fa3..d7332096997 100644 --- a/core/src/main/java/org/elasticsearch/index/analysis/CJKWidthFilterFactory.java +++ b/core/src/main/java/org/elasticsearch/index/analysis/CJKWidthFilterFactory.java @@ -23,13 +23,13 @@ import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.cjk.CJKWidthFilter; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; public final class CJKWidthFilterFactory extends AbstractTokenFilterFactory { @Inject - public CJKWidthFilterFactory(Index index, Settings indexSettings, String name, Settings settings) { - super(index, indexSettings, name, settings); + public CJKWidthFilterFactory(IndexSettings indexSettings, String name, Settings settings) { + super(indexSettings, name, settings); } @Override diff --git a/core/src/main/java/org/elasticsearch/index/analysis/CatalanAnalyzerProvider.java b/core/src/main/java/org/elasticsearch/index/analysis/CatalanAnalyzerProvider.java index 4b354f09a42..61d756b9b7c 100644 --- a/core/src/main/java/org/elasticsearch/index/analysis/CatalanAnalyzerProvider.java +++ b/core/src/main/java/org/elasticsearch/index/analysis/CatalanAnalyzerProvider.java @@ -25,8 +25,7 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; /** * @@ -36,8 +35,8 @@ public class CatalanAnalyzerProvider extends AbstractIndexAnalyzerProvider escapedTags; @Inject - public HtmlStripCharFilterFactory(Index index, @IndexSettings Settings indexSettings, @Assisted String name, @Assisted Settings settings) { - super(index, indexSettings, name); + public HtmlStripCharFilterFactory(IndexSettings indexSettings, @Assisted String name, @Assisted Settings settings) { + super(indexSettings, name); String[] escapedTags = settings.getAsArray("escaped_tags"); if (escapedTags.length > 0) { this.escapedTags = unmodifiableSet(newHashSet(escapedTags)); diff --git a/core/src/main/java/org/elasticsearch/index/analysis/HungarianAnalyzerProvider.java b/core/src/main/java/org/elasticsearch/index/analysis/HungarianAnalyzerProvider.java index 8f6eef17b7f..462bde276e7 100644 --- a/core/src/main/java/org/elasticsearch/index/analysis/HungarianAnalyzerProvider.java +++ b/core/src/main/java/org/elasticsearch/index/analysis/HungarianAnalyzerProvider.java @@ -25,8 +25,7 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; /** * @@ -36,8 +35,8 @@ public class HungarianAnalyzerProvider extends AbstractIndexAnalyzerProvider rules = Analysis.getWordSet(env, settings, "keywords"); diff --git a/core/src/main/java/org/elasticsearch/index/analysis/KeywordTokenizerFactory.java b/core/src/main/java/org/elasticsearch/index/analysis/KeywordTokenizerFactory.java index 44ed001c2d4..14838676ba2 100644 --- a/core/src/main/java/org/elasticsearch/index/analysis/KeywordTokenizerFactory.java +++ b/core/src/main/java/org/elasticsearch/index/analysis/KeywordTokenizerFactory.java @@ -24,8 +24,7 @@ import org.apache.lucene.analysis.core.KeywordTokenizer; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; /** * @@ -35,8 +34,8 @@ public class KeywordTokenizerFactory extends AbstractTokenizerFactory { private final int bufferSize; @Inject - public KeywordTokenizerFactory(Index index, @IndexSettings Settings indexSettings, @Assisted String name, @Assisted Settings settings) { - super(index, indexSettings, name, settings); + public KeywordTokenizerFactory(IndexSettings indexSettings, @Assisted String name, @Assisted Settings settings) { + super(indexSettings, name, settings); bufferSize = settings.getAsInt("buffer_size", 256); } diff --git a/core/src/main/java/org/elasticsearch/index/analysis/LatvianAnalyzerProvider.java b/core/src/main/java/org/elasticsearch/index/analysis/LatvianAnalyzerProvider.java index 236676e4b5b..9f8cd799716 100644 --- a/core/src/main/java/org/elasticsearch/index/analysis/LatvianAnalyzerProvider.java +++ b/core/src/main/java/org/elasticsearch/index/analysis/LatvianAnalyzerProvider.java @@ -25,8 +25,7 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; /** * @@ -36,8 +35,8 @@ public class LatvianAnalyzerProvider extends AbstractIndexAnalyzerProvider rules = Analysis.getWordList(env, settings, "mappings"); if (rules == null) { diff --git a/core/src/main/java/org/elasticsearch/index/analysis/NGramTokenFilterFactory.java b/core/src/main/java/org/elasticsearch/index/analysis/NGramTokenFilterFactory.java index 226c41e67a5..9c879badd2d 100644 --- a/core/src/main/java/org/elasticsearch/index/analysis/NGramTokenFilterFactory.java +++ b/core/src/main/java/org/elasticsearch/index/analysis/NGramTokenFilterFactory.java @@ -20,14 +20,13 @@ package org.elasticsearch.index.analysis; import org.apache.lucene.analysis.TokenStream; -import org.apache.lucene.analysis.ngram.NGramTokenFilter; import org.apache.lucene.analysis.ngram.Lucene43NGramTokenFilter; +import org.apache.lucene.analysis.ngram.NGramTokenFilter; import org.apache.lucene.util.Version; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; /** @@ -41,8 +40,8 @@ public class NGramTokenFilterFactory extends AbstractTokenFilterFactory { @Inject - public NGramTokenFilterFactory(Index index, @IndexSettings Settings indexSettings, @Assisted String name, @Assisted Settings settings) { - super(index, indexSettings, name, settings); + public NGramTokenFilterFactory(IndexSettings indexSettings, @Assisted String name, @Assisted Settings settings) { + super(indexSettings, name, settings); this.minGram = settings.getAsInt("min_gram", NGramTokenFilter.DEFAULT_MIN_NGRAM_SIZE); this.maxGram = settings.getAsInt("max_gram", NGramTokenFilter.DEFAULT_MAX_NGRAM_SIZE); } diff --git a/core/src/main/java/org/elasticsearch/index/analysis/NGramTokenizerFactory.java b/core/src/main/java/org/elasticsearch/index/analysis/NGramTokenizerFactory.java index f1ad1d59a42..f21fbb19642 100644 --- a/core/src/main/java/org/elasticsearch/index/analysis/NGramTokenizerFactory.java +++ b/core/src/main/java/org/elasticsearch/index/analysis/NGramTokenizerFactory.java @@ -26,8 +26,7 @@ import org.apache.lucene.util.Version; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; import java.lang.reflect.Field; import java.lang.reflect.Modifier; @@ -90,12 +89,12 @@ public class NGramTokenizerFactory extends AbstractTokenizerFactory { } @Inject - public NGramTokenizerFactory(Index index, @IndexSettings Settings indexSettings, @Assisted String name, @Assisted Settings settings) { - super(index, indexSettings, name, settings); + public NGramTokenizerFactory(IndexSettings indexSettings, @Assisted String name, @Assisted Settings settings) { + super(indexSettings, name, settings); this.minGram = settings.getAsInt("min_gram", NGramTokenizer.DEFAULT_MIN_NGRAM_SIZE); this.maxGram = settings.getAsInt("max_gram", NGramTokenizer.DEFAULT_MAX_NGRAM_SIZE); this.matcher = parseTokenChars(settings.getAsArray("token_chars")); - this.esVersion = org.elasticsearch.Version.indexCreated(indexSettings); + this.esVersion = indexSettings.getVersion(); } @SuppressWarnings("deprecation") diff --git a/core/src/main/java/org/elasticsearch/index/analysis/NorwegianAnalyzerProvider.java b/core/src/main/java/org/elasticsearch/index/analysis/NorwegianAnalyzerProvider.java index 7e1b303e4c6..857abe946f5 100644 --- a/core/src/main/java/org/elasticsearch/index/analysis/NorwegianAnalyzerProvider.java +++ b/core/src/main/java/org/elasticsearch/index/analysis/NorwegianAnalyzerProvider.java @@ -25,8 +25,7 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; /** * @@ -36,8 +35,8 @@ public class NorwegianAnalyzerProvider extends AbstractIndexAnalyzerProvider rules = Analysis.getWordList(env, settings, "rules"); if (rules == null) { diff --git a/core/src/main/java/org/elasticsearch/index/analysis/StemmerTokenFilterFactory.java b/core/src/main/java/org/elasticsearch/index/analysis/StemmerTokenFilterFactory.java index 84ebe4087af..8f8e1a36f46 100644 --- a/core/src/main/java/org/elasticsearch/index/analysis/StemmerTokenFilterFactory.java +++ b/core/src/main/java/org/elasticsearch/index/analysis/StemmerTokenFilterFactory.java @@ -57,8 +57,7 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; import org.tartarus.snowball.ext.*; /** @@ -68,14 +67,14 @@ public class StemmerTokenFilterFactory extends AbstractTokenFilterFactory { private String language; @Inject - public StemmerTokenFilterFactory(Index index, @IndexSettings Settings indexSettings, @Assisted String name, @Assisted Settings settings) { - super(index, indexSettings, name, settings); + public StemmerTokenFilterFactory(IndexSettings indexSettings, @Assisted String name, @Assisted Settings settings) { + super(indexSettings, name, settings); this.language = Strings.capitalize(settings.get("language", settings.get("name", "porter"))); } @Override public TokenStream create(TokenStream tokenStream) { - final Version indexVersion = Version.indexCreated(indexSettings); + final Version indexVersion = indexSettings.getVersion(); if ("arabic".equalsIgnoreCase(language)) { return new ArabicStemFilter(tokenStream); diff --git a/core/src/main/java/org/elasticsearch/index/analysis/StopAnalyzerProvider.java b/core/src/main/java/org/elasticsearch/index/analysis/StopAnalyzerProvider.java index ed09590fa69..eca30d0c5d9 100644 --- a/core/src/main/java/org/elasticsearch/index/analysis/StopAnalyzerProvider.java +++ b/core/src/main/java/org/elasticsearch/index/analysis/StopAnalyzerProvider.java @@ -25,8 +25,7 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; /** * @@ -36,8 +35,8 @@ public class StopAnalyzerProvider extends AbstractIndexAnalyzerProvider tokenizerFactories, + public SynonymTokenFilterFactory(IndexSettings indexSettings, Environment env, IndicesAnalysisService indicesAnalysisService, Map tokenizerFactories, @Assisted String name, @Assisted Settings settings) { - super(index, indexSettings, name, settings); + super(indexSettings, name, settings); Reader rulesReader = null; if (settings.getAsArray("synonyms", null) != null) { @@ -79,7 +78,7 @@ public class SynonymTokenFilterFactory extends AbstractTokenFilterFactory { throw new IllegalArgumentException("failed to find tokenizer [" + tokenizerName + "] for synonym token filter"); } - final TokenizerFactory tokenizerFactory = tokenizerFactoryFactory.create(tokenizerName, Settings.builder().put(indexSettings).put(settings).build()); + final TokenizerFactory tokenizerFactory = tokenizerFactoryFactory.create(tokenizerName, Settings.builder().put(this.indexSettings.getSettings()).put(settings).build()); Analyzer analyzer = new Analyzer() { @Override diff --git a/core/src/main/java/org/elasticsearch/index/analysis/ThaiAnalyzerProvider.java b/core/src/main/java/org/elasticsearch/index/analysis/ThaiAnalyzerProvider.java index 2b75ae8591d..84eb8c5093b 100644 --- a/core/src/main/java/org/elasticsearch/index/analysis/ThaiAnalyzerProvider.java +++ b/core/src/main/java/org/elasticsearch/index/analysis/ThaiAnalyzerProvider.java @@ -24,8 +24,7 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; /** * @@ -35,8 +34,8 @@ public class ThaiAnalyzerProvider extends AbstractIndexAnalyzerProvider DIGIT diff --git a/core/src/main/java/org/elasticsearch/index/analysis/compound/AbstractCompoundWordTokenFilterFactory.java b/core/src/main/java/org/elasticsearch/index/analysis/compound/AbstractCompoundWordTokenFilterFactory.java index b9c296df22b..703f6a78148 100644 --- a/core/src/main/java/org/elasticsearch/index/analysis/compound/AbstractCompoundWordTokenFilterFactory.java +++ b/core/src/main/java/org/elasticsearch/index/analysis/compound/AbstractCompoundWordTokenFilterFactory.java @@ -25,10 +25,9 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; -import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.analysis.AbstractTokenFilterFactory; import org.elasticsearch.index.analysis.Analysis; -import org.elasticsearch.index.settings.IndexSettings; /** * Contains the common configuration settings between subclasses of this class. @@ -42,8 +41,8 @@ public abstract class AbstractCompoundWordTokenFilterFactory extends AbstractTok protected final CharArraySet wordList; @Inject - public AbstractCompoundWordTokenFilterFactory(Index index, @IndexSettings Settings indexSettings, Environment env, @Assisted String name, @Assisted Settings settings) { - super(index, indexSettings, name, settings); + public AbstractCompoundWordTokenFilterFactory(IndexSettings indexSettings, Environment env, @Assisted String name, @Assisted Settings settings) { + super(indexSettings, name, settings); minWordSize = settings.getAsInt("min_word_size", CompoundWordTokenFilterBase.DEFAULT_MIN_WORD_SIZE); minSubwordSize = settings.getAsInt("min_subword_size", CompoundWordTokenFilterBase.DEFAULT_MIN_SUBWORD_SIZE); diff --git a/core/src/main/java/org/elasticsearch/index/analysis/compound/DictionaryCompoundWordTokenFilterFactory.java b/core/src/main/java/org/elasticsearch/index/analysis/compound/DictionaryCompoundWordTokenFilterFactory.java index 55c1b4e3df1..e7d2fb7545f 100644 --- a/core/src/main/java/org/elasticsearch/index/analysis/compound/DictionaryCompoundWordTokenFilterFactory.java +++ b/core/src/main/java/org/elasticsearch/index/analysis/compound/DictionaryCompoundWordTokenFilterFactory.java @@ -23,14 +23,12 @@ import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.compound.DictionaryCompoundWordTokenFilter; import org.apache.lucene.analysis.compound.Lucene43DictionaryCompoundWordTokenFilter; import org.apache.lucene.util.Version; - import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; -import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.analysis.AnalysisSettingsRequired; -import org.elasticsearch.index.settings.IndexSettings; /** @@ -42,8 +40,8 @@ import org.elasticsearch.index.settings.IndexSettings; public class DictionaryCompoundWordTokenFilterFactory extends AbstractCompoundWordTokenFilterFactory { @Inject - public DictionaryCompoundWordTokenFilterFactory(Index index, @IndexSettings Settings indexSettings, Environment env, @Assisted String name, @Assisted Settings settings) { - super(index, indexSettings, env, name, settings); + public DictionaryCompoundWordTokenFilterFactory(IndexSettings indexSettings, Environment env, @Assisted String name, @Assisted Settings settings) { + super(indexSettings, env, name, settings); } @Override diff --git a/core/src/main/java/org/elasticsearch/index/analysis/compound/HyphenationCompoundWordTokenFilterFactory.java b/core/src/main/java/org/elasticsearch/index/analysis/compound/HyphenationCompoundWordTokenFilterFactory.java index 72d7bdc5871..9dbee39063b 100644 --- a/core/src/main/java/org/elasticsearch/index/analysis/compound/HyphenationCompoundWordTokenFilterFactory.java +++ b/core/src/main/java/org/elasticsearch/index/analysis/compound/HyphenationCompoundWordTokenFilterFactory.java @@ -24,17 +24,14 @@ import org.apache.lucene.analysis.compound.HyphenationCompoundWordTokenFilter; import org.apache.lucene.analysis.compound.Lucene43HyphenationCompoundWordTokenFilter; import org.apache.lucene.analysis.compound.hyphenation.HyphenationTree; import org.apache.lucene.util.Version; - import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; -import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.analysis.AnalysisSettingsRequired; -import org.elasticsearch.index.settings.IndexSettings; import org.xml.sax.InputSource; -import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; @@ -49,8 +46,8 @@ public class HyphenationCompoundWordTokenFilterFactory extends AbstractCompoundW private final HyphenationTree hyphenationTree; @Inject - public HyphenationCompoundWordTokenFilterFactory(Index index, @IndexSettings Settings indexSettings, Environment env, @Assisted String name, @Assisted Settings settings) { - super(index, indexSettings, env, name, settings); + public HyphenationCompoundWordTokenFilterFactory(IndexSettings indexSettings, Environment env, @Assisted String name, @Assisted Settings settings) { + super(indexSettings, env, name, settings); String hyphenationPatternsPath = settings.get("hyphenation_patterns_path", null); if (hyphenationPatternsPath == null) { diff --git a/core/src/main/java/org/elasticsearch/index/cache/IndexCache.java b/core/src/main/java/org/elasticsearch/index/cache/IndexCache.java index 0f2ace8c28b..67a7e717021 100644 --- a/core/src/main/java/org/elasticsearch/index/cache/IndexCache.java +++ b/core/src/main/java/org/elasticsearch/index/cache/IndexCache.java @@ -21,12 +21,10 @@ package org.elasticsearch.index.cache; import org.apache.lucene.util.IOUtils; 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.index.cache.bitset.BitsetFilterCache; import org.elasticsearch.index.cache.query.QueryCache; -import org.elasticsearch.index.settings.IndexSettings; import java.io.Closeable; import java.io.IOException; @@ -40,8 +38,8 @@ public class IndexCache extends AbstractIndexComponent implements Closeable { private final BitsetFilterCache bitsetFilterCache; @Inject - public IndexCache(Index index, @IndexSettings Settings indexSettings, QueryCache queryCache, BitsetFilterCache bitsetFilterCache) { - super(index, indexSettings); + public IndexCache(IndexSettings indexSettings, QueryCache queryCache, BitsetFilterCache bitsetFilterCache) { + super(indexSettings); this.queryCache = queryCache; this.bitsetFilterCache = bitsetFilterCache; } diff --git a/core/src/main/java/org/elasticsearch/index/cache/bitset/BitsetFilterCache.java b/core/src/main/java/org/elasticsearch/index/cache/bitset/BitsetFilterCache.java index f2b7ba8e131..994033273a3 100644 --- a/core/src/main/java/org/elasticsearch/index/cache/bitset/BitsetFilterCache.java +++ b/core/src/main/java/org/elasticsearch/index/cache/bitset/BitsetFilterCache.java @@ -39,14 +39,12 @@ import org.elasticsearch.common.cache.RemovalListener; import org.elasticsearch.common.cache.RemovalNotification; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.lucene.search.Queries; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.index.AbstractIndexComponent; -import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.mapper.DocumentMapper; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.object.ObjectMapper; -import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.shard.IndexShard; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardUtils; @@ -91,9 +89,9 @@ public class BitsetFilterCache extends AbstractIndexComponent implements LeafRea private IndicesWarmer indicesWarmer; @Inject - public BitsetFilterCache(Index index, @IndexSettings Settings indexSettings) { - super(index, indexSettings); - this.loadRandomAccessFiltersEagerly = indexSettings.getAsBoolean(LOAD_RANDOM_ACCESS_FILTERS_EAGERLY, true); + public BitsetFilterCache(IndexSettings indexSettings) { + super(indexSettings); + this.loadRandomAccessFiltersEagerly = this.indexSettings.getSettings().getAsBoolean(LOAD_RANDOM_ACCESS_FILTERS_EAGERLY, true); this.loadedFilters = CacheBuilder.>builder().removalListener(this).build(); this.warmer = new BitSetProducerWarmer(); } diff --git a/core/src/main/java/org/elasticsearch/index/cache/bitset/ShardBitsetFilterCache.java b/core/src/main/java/org/elasticsearch/index/cache/bitset/ShardBitsetFilterCache.java index 6e0551a8905..86a00fdbcf7 100644 --- a/core/src/main/java/org/elasticsearch/index/cache/bitset/ShardBitsetFilterCache.java +++ b/core/src/main/java/org/elasticsearch/index/cache/bitset/ShardBitsetFilterCache.java @@ -20,8 +20,7 @@ package org.elasticsearch.index.cache.bitset; import org.elasticsearch.common.metrics.CounterMetric; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.shard.AbstractIndexShardComponent; import org.elasticsearch.index.shard.ShardId; @@ -31,7 +30,7 @@ public class ShardBitsetFilterCache extends AbstractIndexShardComponent { private final CounterMetric totalMetric = new CounterMetric(); - public ShardBitsetFilterCache(ShardId shardId, @IndexSettings Settings indexSettings) { + public ShardBitsetFilterCache(ShardId shardId, IndexSettings indexSettings) { super(shardId, indexSettings); } diff --git a/core/src/main/java/org/elasticsearch/index/cache/query/index/IndexQueryCache.java b/core/src/main/java/org/elasticsearch/index/cache/query/index/IndexQueryCache.java index af3d2ea5cb9..04f66290a5e 100644 --- a/core/src/main/java/org/elasticsearch/index/cache/query/index/IndexQueryCache.java +++ b/core/src/main/java/org/elasticsearch/index/cache/query/index/IndexQueryCache.java @@ -23,11 +23,9 @@ import org.apache.lucene.search.QueryCachingPolicy; import org.apache.lucene.search.Weight; import org.elasticsearch.ElasticsearchException; 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.index.cache.query.QueryCache; -import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.indices.cache.query.IndicesQueryCache; /** @@ -39,8 +37,8 @@ public class IndexQueryCache extends AbstractIndexComponent implements QueryCach final IndicesQueryCache indicesQueryCache; @Inject - public IndexQueryCache(Index index, @IndexSettings Settings indexSettings, IndicesQueryCache indicesQueryCache) { - super(index, indexSettings); + public IndexQueryCache(IndexSettings indexSettings, IndicesQueryCache indicesQueryCache) { + super(indexSettings); this.indicesQueryCache = indicesQueryCache; } @@ -52,7 +50,7 @@ public class IndexQueryCache extends AbstractIndexComponent implements QueryCach @Override public void clear(String reason) { logger.debug("full cache clear, reason [{}]", reason); - indicesQueryCache.clearIndex(index.getName()); + indicesQueryCache.clearIndex(index().getName()); } @Override diff --git a/core/src/main/java/org/elasticsearch/index/cache/query/none/NoneQueryCache.java b/core/src/main/java/org/elasticsearch/index/cache/query/none/NoneQueryCache.java index 9d88940ff89..67408655726 100644 --- a/core/src/main/java/org/elasticsearch/index/cache/query/none/NoneQueryCache.java +++ b/core/src/main/java/org/elasticsearch/index/cache/query/none/NoneQueryCache.java @@ -22,11 +22,9 @@ package org.elasticsearch.index.cache.query.none; import org.apache.lucene.search.QueryCachingPolicy; import org.apache.lucene.search.Weight; 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.index.cache.query.QueryCache; -import org.elasticsearch.index.settings.IndexSettings; /** * @@ -34,8 +32,8 @@ import org.elasticsearch.index.settings.IndexSettings; public class NoneQueryCache extends AbstractIndexComponent implements QueryCache { @Inject - public NoneQueryCache(Index index, @IndexSettings Settings indexSettings) { - super(index, indexSettings); + public NoneQueryCache(IndexSettings indexSettings) { + super(indexSettings); logger.debug("Using no query cache"); } diff --git a/core/src/main/java/org/elasticsearch/index/cache/request/ShardRequestCache.java b/core/src/main/java/org/elasticsearch/index/cache/request/ShardRequestCache.java index 0f594d2faca..5e9c8156046 100644 --- a/core/src/main/java/org/elasticsearch/index/cache/request/ShardRequestCache.java +++ b/core/src/main/java/org/elasticsearch/index/cache/request/ShardRequestCache.java @@ -22,8 +22,7 @@ package org.elasticsearch.index.cache.request; import org.elasticsearch.common.cache.RemovalListener; import org.elasticsearch.common.cache.RemovalNotification; import org.elasticsearch.common.metrics.CounterMetric; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.shard.AbstractIndexShardComponent; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.indices.cache.request.IndicesRequestCache; @@ -37,7 +36,7 @@ public class ShardRequestCache extends AbstractIndexShardComponent implements Re final CounterMetric hitCount = new CounterMetric(); final CounterMetric missCount = new CounterMetric(); - public ShardRequestCache(ShardId shardId, @IndexSettings Settings indexSettings) { + public ShardRequestCache(ShardId shardId, IndexSettings indexSettings) { super(shardId, indexSettings); } 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 62ff583220c..9a15d853eda 100644 --- a/core/src/main/java/org/elasticsearch/index/codec/CodecService.java +++ b/core/src/main/java/org/elasticsearch/index/codec/CodecService.java @@ -27,9 +27,10 @@ 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.index.mapper.MapperService; -import org.elasticsearch.index.settings.IndexSettings; +import java.util.Collections; import java.util.Map; /** @@ -49,17 +50,9 @@ public class CodecService extends AbstractIndexComponent { /** the raw unfiltered lucene default. useful for testing */ public final static String LUCENE_DEFAULT_CODEC = "lucene_default"; - public CodecService(Index index) { - this(index, Settings.Builder.EMPTY_SETTINGS); - } - - public CodecService(Index index, @IndexSettings Settings indexSettings) { - this(index, indexSettings, null); - } - @Inject - public CodecService(Index index, @IndexSettings Settings indexSettings, MapperService mapperService) { - super(index, indexSettings); + public CodecService(IndexSettings indexSettings, MapperService mapperService) { + super(indexSettings); this.mapperService = mapperService; MapBuilder codecs = MapBuilder.newMapBuilder(); if (mapperService == null) { diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/IndexFieldData.java b/core/src/main/java/org/elasticsearch/index/fielddata/IndexFieldData.java index ba03efb8d87..7d2689dc157 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/IndexFieldData.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/IndexFieldData.java @@ -31,13 +31,11 @@ import org.apache.lucene.util.BitDocIdSet; import org.apache.lucene.util.BitSet; import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexComponent; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.MapperService; -import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.indices.breaker.CircuitBreakerService; import org.elasticsearch.search.MultiValueMode; @@ -232,7 +230,7 @@ public interface IndexFieldData extends IndexCompone interface Builder { - IndexFieldData build(Index index, @IndexSettings Settings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache, + IndexFieldData build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache, CircuitBreakerService breakerService, MapperService mapperService); } diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/IndexFieldDataService.java b/core/src/main/java/org/elasticsearch/index/fielddata/IndexFieldDataService.java index 6ee6e9b1110..903eba213f7 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/IndexFieldDataService.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/IndexFieldDataService.java @@ -24,9 +24,8 @@ import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.collect.Tuple; 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.index.fielddata.plain.BytesBinaryDVIndexFieldData; import org.elasticsearch.index.fielddata.plain.DisabledIndexFieldData; import org.elasticsearch.index.fielddata.plain.DocValuesIndexFieldData; @@ -41,7 +40,6 @@ import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.core.BooleanFieldMapper; import org.elasticsearch.index.mapper.internal.IndexFieldMapper; import org.elasticsearch.index.mapper.internal.ParentFieldMapper; -import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.indices.breaker.CircuitBreakerService; import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache; @@ -61,13 +59,10 @@ public class IndexFieldDataService extends AbstractIndexComponent { public static final String FIELDDATA_CACHE_KEY = "index.fielddata.cache"; public static final String FIELDDATA_CACHE_VALUE_NODE = "node"; - private static final IndexFieldData.Builder MISSING_DOC_VALUES_BUILDER = new IndexFieldData.Builder() { - @Override - public IndexFieldData build(Index index, Settings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache, CircuitBreakerService breakerService, MapperService mapperService) { - throw new IllegalStateException("Can't load fielddata on [" + fieldType.names().fullName() - + "] of index [" + index.getName() + "] because fielddata is unsupported on fields of type [" - + fieldType.fieldDataType().getType() + "]. Use doc values instead."); - } + private static final IndexFieldData.Builder MISSING_DOC_VALUES_BUILDER = (indexProperties, fieldType, cache, breakerService, mapperService1) -> { + throw new IllegalStateException("Can't load fielddata on [" + fieldType.names().fullName() + + "] of index [" + indexProperties.getIndex().getName() + "] because fielddata is unsupported on fields of type [" + + fieldType.fieldDataType().getType() + "]. Use doc values instead."); }; private static final String ARRAY_FORMAT = "array"; @@ -161,10 +156,11 @@ public class IndexFieldDataService extends AbstractIndexComponent { }; private volatile IndexFieldDataCache.Listener listener = DEFAULT_NOOP_LISTENER; + @Inject - public IndexFieldDataService(Index index, @IndexSettings Settings indexSettings, IndicesFieldDataCache indicesFieldDataCache, + public IndexFieldDataService(IndexSettings indexSettings, IndicesFieldDataCache indicesFieldDataCache, CircuitBreakerService circuitBreakerService, MapperService mapperService) { - super(index, indexSettings); + super(indexSettings); this.indicesFieldDataCache = indicesFieldDataCache; this.circuitBreakerService = circuitBreakerService; this.mapperService = mapperService; @@ -206,7 +202,7 @@ public class IndexFieldDataService extends AbstractIndexComponent { } final boolean docValues = fieldType.hasDocValues(); IndexFieldData.Builder builder = null; - String format = type.getFormat(indexSettings); + String format = type.getFormat(indexSettings.getSettings()); if (format != null && FieldDataType.DOC_VALUES_FORMAT_VALUE.equals(format) && !docValues) { logger.warn("field [" + fieldNames.fullName() + "] has no doc values, will use default field data format"); format = null; @@ -233,9 +229,9 @@ public class IndexFieldDataService extends AbstractIndexComponent { if (cache == null) { // we default to node level cache, which in turn defaults to be unbounded // this means changing the node level settings is simple, just set the bounds there - String cacheType = type.getSettings().get("cache", indexSettings.get(FIELDDATA_CACHE_KEY, FIELDDATA_CACHE_VALUE_NODE)); + String cacheType = type.getSettings().get("cache", indexSettings.getSettings().get(FIELDDATA_CACHE_KEY, FIELDDATA_CACHE_VALUE_NODE)); if (FIELDDATA_CACHE_VALUE_NODE.equals(cacheType)) { - cache = indicesFieldDataCache.buildIndexFieldDataCache(listener, index, fieldNames, type); + cache = indicesFieldDataCache.buildIndexFieldDataCache(listener, index(), fieldNames, type); } else if ("none".equals(cacheType)){ cache = new IndexFieldDataCache.None(); } else { @@ -245,7 +241,7 @@ public class IndexFieldDataService extends AbstractIndexComponent { } } - return (IFD) builder.build(index, indexSettings, fieldType, cache, circuitBreakerService, mapperService); + return (IFD) builder.build(indexSettings, fieldType, cache, circuitBreakerService, mapperService); } /** diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/ShardFieldData.java b/core/src/main/java/org/elasticsearch/index/fielddata/ShardFieldData.java index 8fccda94d80..e646364ef13 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/ShardFieldData.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/ShardFieldData.java @@ -21,14 +21,10 @@ package org.elasticsearch.index.fielddata; import com.carrotsearch.hppc.ObjectLongHashMap; import org.apache.lucene.util.Accountable; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.metrics.CounterMetric; import org.elasticsearch.common.regex.Regex; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ConcurrentCollections; import org.elasticsearch.index.mapper.MappedFieldType; -import org.elasticsearch.index.settings.IndexSettings; -import org.elasticsearch.index.shard.AbstractIndexShardComponent; import org.elasticsearch.index.shard.ShardId; import java.util.Map; diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/ordinals/GlobalOrdinalsBuilder.java b/core/src/main/java/org/elasticsearch/index/fielddata/ordinals/GlobalOrdinalsBuilder.java index a7f25d4f8f5..31014a5a1a9 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/ordinals/GlobalOrdinalsBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/ordinals/GlobalOrdinalsBuilder.java @@ -25,8 +25,8 @@ import org.apache.lucene.index.RandomAccessOrds; import org.apache.lucene.util.packed.PackedInts; import org.elasticsearch.common.breaker.CircuitBreaker; import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.fielddata.AtomicOrdinalsFieldData; import org.elasticsearch.index.fielddata.IndexOrdinalsFieldData; import org.elasticsearch.indices.breaker.CircuitBreakerService; @@ -42,7 +42,7 @@ public enum GlobalOrdinalsBuilder { /** * Build global ordinals for the provided {@link IndexReader}. */ - public static IndexOrdinalsFieldData build(final IndexReader indexReader, IndexOrdinalsFieldData indexFieldData, Settings settings, CircuitBreakerService breakerService, ESLogger logger) throws IOException { + public static IndexOrdinalsFieldData build(final IndexReader indexReader, IndexOrdinalsFieldData indexFieldData, IndexSettings indexSettings, CircuitBreakerService breakerService, ESLogger logger) throws IOException { assert indexReader.leaves().size() > 1; long startTimeNS = System.nanoTime(); @@ -64,7 +64,7 @@ public enum GlobalOrdinalsBuilder { TimeValue.nsecToMSec(System.nanoTime() - startTimeNS) ); } - return new InternalGlobalOrdinalsIndexFieldData(indexFieldData.index(), settings, indexFieldData.getFieldNames(), + return new InternalGlobalOrdinalsIndexFieldData(indexSettings, indexFieldData.getFieldNames(), indexFieldData.getFieldDataType(), atomicFD, ordinalMap, memorySizeInBytes ); } diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/ordinals/GlobalOrdinalsIndexFieldData.java b/core/src/main/java/org/elasticsearch/index/fielddata/ordinals/GlobalOrdinalsIndexFieldData.java index 0d6c129d73c..4a8bd78bb4e 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/ordinals/GlobalOrdinalsIndexFieldData.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/ordinals/GlobalOrdinalsIndexFieldData.java @@ -19,19 +19,16 @@ package org.elasticsearch.index.fielddata.ordinals; import org.apache.lucene.index.DirectoryReader; -import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.util.Accountable; import org.elasticsearch.common.Nullable; -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.fielddata.AtomicOrdinalsFieldData; import org.elasticsearch.index.fielddata.FieldDataType; import org.elasticsearch.index.fielddata.IndexFieldData; import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested; import org.elasticsearch.index.fielddata.IndexOrdinalsFieldData; -import org.elasticsearch.index.mapper.FieldMapper; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.search.MultiValueMode; @@ -47,8 +44,8 @@ public abstract class GlobalOrdinalsIndexFieldData extends AbstractIndexComponen private final FieldDataType fieldDataType; private final long memorySizeInBytes; - protected GlobalOrdinalsIndexFieldData(Index index, Settings settings, MappedFieldType.Names fieldNames, FieldDataType fieldDataType, long memorySizeInBytes) { - super(index, settings); + protected GlobalOrdinalsIndexFieldData(IndexSettings indexSettings, MappedFieldType.Names fieldNames, FieldDataType fieldDataType, long memorySizeInBytes) { + super(indexSettings); this.fieldNames = fieldNames; this.fieldDataType = fieldDataType; this.memorySizeInBytes = memorySizeInBytes; diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/ordinals/InternalGlobalOrdinalsIndexFieldData.java b/core/src/main/java/org/elasticsearch/index/fielddata/ordinals/InternalGlobalOrdinalsIndexFieldData.java index b91d98f4a62..fc1b6db9758 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/ordinals/InternalGlobalOrdinalsIndexFieldData.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/ordinals/InternalGlobalOrdinalsIndexFieldData.java @@ -22,12 +22,10 @@ import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.MultiDocValues.OrdinalMap; import org.apache.lucene.index.RandomAccessOrds; import org.apache.lucene.util.Accountable; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.fielddata.AtomicOrdinalsFieldData; import org.elasticsearch.index.fielddata.FieldDataType; import org.elasticsearch.index.fielddata.plain.AbstractAtomicOrdinalsFieldData; -import org.elasticsearch.index.mapper.FieldMapper; import org.elasticsearch.index.mapper.MappedFieldType; import java.util.Collection; @@ -39,8 +37,8 @@ final class InternalGlobalOrdinalsIndexFieldData extends GlobalOrdinalsIndexFiel private final Atomic[] atomicReaders; - InternalGlobalOrdinalsIndexFieldData(Index index, Settings settings, MappedFieldType.Names fieldNames, FieldDataType fieldDataType, AtomicOrdinalsFieldData[] segmentAfd, OrdinalMap ordinalMap, long memorySizeInBytes) { - super(index, settings, fieldNames, fieldDataType, memorySizeInBytes); + InternalGlobalOrdinalsIndexFieldData(IndexSettings indexSettings, MappedFieldType.Names fieldNames, FieldDataType fieldDataType, AtomicOrdinalsFieldData[] segmentAfd, OrdinalMap ordinalMap, long memorySizeInBytes) { + super(indexSettings, fieldNames, fieldDataType, memorySizeInBytes); this.atomicReaders = new Atomic[segmentAfd.length]; for (int i = 0; i < segmentAfd.length; i++) { atomicReaders[i] = new Atomic(segmentAfd[i], ordinalMap, i); diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractIndexFieldData.java b/core/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractIndexFieldData.java index c0b8f7a7b74..95dd417fdf5 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractIndexFieldData.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractIndexFieldData.java @@ -19,18 +19,15 @@ package org.elasticsearch.index.fielddata.plain; -import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.Terms; import org.apache.lucene.index.TermsEnum; import org.apache.lucene.util.BytesRef; import org.elasticsearch.ElasticsearchException; -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.fielddata.*; import org.elasticsearch.index.mapper.MappedFieldType; -import org.elasticsearch.index.settings.IndexSettings; import java.io.IOException; @@ -42,8 +39,8 @@ public abstract class AbstractIndexFieldData extends protected final FieldDataType fieldDataType; protected final IndexFieldDataCache cache; - public AbstractIndexFieldData(Index index, @IndexSettings Settings indexSettings, MappedFieldType.Names fieldNames, FieldDataType fieldDataType, IndexFieldDataCache cache) { - super(index, indexSettings); + public AbstractIndexFieldData(IndexSettings indexSettings, MappedFieldType.Names fieldNames, FieldDataType fieldDataType, IndexFieldDataCache cache) { + super(indexSettings); this.fieldNames = fieldNames; this.fieldDataType = fieldDataType; this.cache = cache; diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractIndexGeoPointFieldData.java b/core/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractIndexGeoPointFieldData.java index 480cbfa2baf..8e9fbf1a8f7 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractIndexGeoPointFieldData.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractIndexGeoPointFieldData.java @@ -24,8 +24,7 @@ import org.apache.lucene.util.BytesRefIterator; import org.apache.lucene.util.CharsRefBuilder; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.geo.GeoPoint; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.fielddata.*; import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested; import org.elasticsearch.index.mapper.MappedFieldType.Names; @@ -71,8 +70,8 @@ abstract class AbstractIndexGeoPointFieldData extends AbstractIndexFieldData groups = fieldDataType.getSettings().getGroups("filter"); frequency = groups.get("frequency"); regex = groups.get("regex"); diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/plain/BytesBinaryDVIndexFieldData.java b/core/src/main/java/org/elasticsearch/index/fielddata/plain/BytesBinaryDVIndexFieldData.java index b80aad90fb1..efe8bc97a30 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/plain/BytesBinaryDVIndexFieldData.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/plain/BytesBinaryDVIndexFieldData.java @@ -22,13 +22,12 @@ package org.elasticsearch.index.fielddata.plain; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.DocValues; import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.fielddata.FieldDataType; import org.elasticsearch.index.fielddata.IndexFieldData; import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested; import org.elasticsearch.index.fielddata.IndexFieldDataCache; -import org.elasticsearch.index.mapper.FieldMapper; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.MappedFieldType.Names; import org.elasticsearch.index.mapper.MapperService; @@ -65,11 +64,11 @@ public class BytesBinaryDVIndexFieldData extends DocValuesIndexFieldData impleme public static class Builder implements IndexFieldData.Builder { @Override - public IndexFieldData build(Index index, Settings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache, + public IndexFieldData build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache, CircuitBreakerService breakerService, MapperService mapperService) { // Ignore breaker final Names fieldNames = fieldType.names(); - return new BytesBinaryDVIndexFieldData(index, fieldNames, fieldType.fieldDataType()); + return new BytesBinaryDVIndexFieldData(indexSettings.getIndex(), fieldNames, fieldType.fieldDataType()); } } diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/plain/DisabledIndexFieldData.java b/core/src/main/java/org/elasticsearch/index/fielddata/plain/DisabledIndexFieldData.java index 03ac099489e..58a195057bb 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/plain/DisabledIndexFieldData.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/plain/DisabledIndexFieldData.java @@ -20,14 +20,12 @@ package org.elasticsearch.index.fielddata.plain; import org.apache.lucene.index.LeafReaderContext; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.fielddata.*; import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.MappedFieldType.Names; import org.elasticsearch.index.mapper.MapperService; -import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.search.MultiValueMode; import org.elasticsearch.indices.breaker.CircuitBreakerService; @@ -39,15 +37,15 @@ public final class DisabledIndexFieldData extends AbstractIndexFieldData build(Index index, @IndexSettings Settings indexSettings, MappedFieldType fieldType, + public IndexFieldData build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache, CircuitBreakerService breakerService, MapperService mapperService) { // Ignore Circuit Breaker - return new DisabledIndexFieldData(index, indexSettings, fieldType.names(), fieldType.fieldDataType(), cache); + return new DisabledIndexFieldData(indexSettings, fieldType.names(), fieldType.fieldDataType(), cache); } } - public DisabledIndexFieldData(Index index, Settings indexSettings, Names fieldNames, FieldDataType fieldDataType, IndexFieldDataCache cache) { - super(index, indexSettings, fieldNames, fieldDataType, cache); + public DisabledIndexFieldData(IndexSettings indexSettings, Names fieldNames, FieldDataType fieldDataType, IndexFieldDataCache cache) { + super(indexSettings, fieldNames, fieldDataType, cache); } @Override diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/plain/DocValuesIndexFieldData.java b/core/src/main/java/org/elasticsearch/index/fielddata/plain/DocValuesIndexFieldData.java index a8427dcd180..9cea1b00a94 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/plain/DocValuesIndexFieldData.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/plain/DocValuesIndexFieldData.java @@ -24,6 +24,7 @@ import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.fielddata.FieldDataType; import org.elasticsearch.index.fielddata.IndexFieldData; import org.elasticsearch.index.fielddata.IndexFieldDataCache; @@ -88,7 +89,7 @@ public abstract class DocValuesIndexFieldData { } @Override - public IndexFieldData build(Index index, Settings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache, + public IndexFieldData build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache, CircuitBreakerService breakerService, MapperService mapperService) { // Ignore Circuit Breaker final Names fieldNames = fieldType.names(); @@ -100,11 +101,11 @@ public abstract class DocValuesIndexFieldData { if (BINARY_INDEX_FIELD_NAMES.contains(fieldNames.indexName())) { assert numericType == null; - return new BinaryDVIndexFieldData(index, fieldNames, fieldType.fieldDataType()); + return new BinaryDVIndexFieldData(indexSettings.getIndex(), fieldNames, fieldType.fieldDataType()); } else if (numericType != null) { - return new SortedNumericDVIndexFieldData(index, fieldNames, numericType, fieldType.fieldDataType()); + return new SortedNumericDVIndexFieldData(indexSettings.getIndex(), fieldNames, numericType, fieldType.fieldDataType()); } else { - return new SortedSetDVOrdinalsIndexFieldData(index, cache, indexSettings, fieldNames, breakerService, fieldType.fieldDataType()); + return new SortedSetDVOrdinalsIndexFieldData(indexSettings, cache, fieldNames, breakerService, fieldType.fieldDataType()); } } diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/plain/GeoPointBinaryDVIndexFieldData.java b/core/src/main/java/org/elasticsearch/index/fielddata/plain/GeoPointBinaryDVIndexFieldData.java index 466ae0fcb65..552aa5642ef 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/plain/GeoPointBinaryDVIndexFieldData.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/plain/GeoPointBinaryDVIndexFieldData.java @@ -22,11 +22,10 @@ package org.elasticsearch.index.fielddata.plain; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.DocValues; import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.fielddata.*; import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested; -import org.elasticsearch.index.mapper.FieldMapper; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.MappedFieldType.Names; import org.elasticsearch.index.mapper.MapperService; @@ -63,11 +62,11 @@ public class GeoPointBinaryDVIndexFieldData extends DocValuesIndexFieldData impl public static class Builder implements IndexFieldData.Builder { @Override - public IndexFieldData build(Index index, Settings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache, + public IndexFieldData build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache, CircuitBreakerService breakerService, MapperService mapperService) { // Ignore breaker final Names fieldNames = fieldType.names(); - return new GeoPointBinaryDVIndexFieldData(index, fieldNames, fieldType.fieldDataType()); + return new GeoPointBinaryDVIndexFieldData(indexSettings.getIndex(), fieldNames, fieldType.fieldDataType()); } } diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/plain/GeoPointDoubleArrayIndexFieldData.java b/core/src/main/java/org/elasticsearch/index/fielddata/plain/GeoPointDoubleArrayIndexFieldData.java index ddc6c3fd821..8d1bf71332a 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/plain/GeoPointDoubleArrayIndexFieldData.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/plain/GeoPointDoubleArrayIndexFieldData.java @@ -25,17 +25,14 @@ import org.apache.lucene.index.Terms; import org.apache.lucene.util.BitSet; import org.elasticsearch.common.breaker.CircuitBreaker; import org.elasticsearch.common.geo.GeoPoint; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.DoubleArray; -import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.fielddata.*; import org.elasticsearch.index.fielddata.ordinals.Ordinals; import org.elasticsearch.index.fielddata.ordinals.OrdinalsBuilder; -import org.elasticsearch.index.mapper.FieldMapper; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.MapperService; -import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.indices.breaker.CircuitBreakerService; /** @@ -47,15 +44,15 @@ public class GeoPointDoubleArrayIndexFieldData extends AbstractIndexGeoPointFiel public static class Builder implements IndexFieldData.Builder { @Override - public IndexFieldData build(Index index, @IndexSettings Settings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache, + public IndexFieldData build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache, CircuitBreakerService breakerService, MapperService mapperService) { - return new GeoPointDoubleArrayIndexFieldData(index, indexSettings, fieldType.names(), fieldType.fieldDataType(), cache, breakerService); + return new GeoPointDoubleArrayIndexFieldData(indexSettings, fieldType.names(), fieldType.fieldDataType(), cache, breakerService); } } - public GeoPointDoubleArrayIndexFieldData(Index index, @IndexSettings Settings indexSettings, MappedFieldType.Names fieldNames, + public GeoPointDoubleArrayIndexFieldData(IndexSettings indexSettings, MappedFieldType.Names fieldNames, FieldDataType fieldDataType, IndexFieldDataCache cache, CircuitBreakerService breakerService) { - super(index, indexSettings, fieldNames, fieldDataType, cache); + super(indexSettings, fieldNames, fieldDataType, cache); this.breakerService = breakerService; } diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/plain/IndexIndexFieldData.java b/core/src/main/java/org/elasticsearch/index/fielddata/plain/IndexIndexFieldData.java index 36bc96d5f6d..e836f13609b 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/plain/IndexIndexFieldData.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/plain/IndexIndexFieldData.java @@ -22,14 +22,12 @@ package org.elasticsearch.index.fielddata.plain; import org.apache.lucene.index.*; import org.apache.lucene.util.Accountable; import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.fielddata.AtomicOrdinalsFieldData; import org.elasticsearch.index.fielddata.FieldDataType; import org.elasticsearch.index.fielddata.IndexFieldData; import org.elasticsearch.index.fielddata.IndexFieldDataCache; import org.elasticsearch.index.fielddata.IndexOrdinalsFieldData; -import org.elasticsearch.index.mapper.FieldMapper; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.indices.breaker.CircuitBreakerService; @@ -42,9 +40,9 @@ public class IndexIndexFieldData extends AbstractIndexOrdinalsFieldData { public static class Builder implements IndexFieldData.Builder { @Override - public IndexFieldData build(Index index, Settings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache, + public IndexFieldData build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache, CircuitBreakerService breakerService, MapperService mapperService) { - return new IndexIndexFieldData(index, fieldType.names()); + return new IndexIndexFieldData(indexSettings, fieldType.names()); } } @@ -98,8 +96,8 @@ public class IndexIndexFieldData extends AbstractIndexOrdinalsFieldData { private final AtomicOrdinalsFieldData atomicFieldData; - private IndexIndexFieldData(Index index, MappedFieldType.Names names) { - super(index, Settings.EMPTY, names, new FieldDataType("string"), null, null); + private IndexIndexFieldData(IndexSettings indexSettings, MappedFieldType.Names names) { + super(indexSettings, names, new FieldDataType("string"), null, null); atomicFieldData = new IndexAtomicFieldData(index().name()); } diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/plain/PagedBytesIndexFieldData.java b/core/src/main/java/org/elasticsearch/index/fielddata/plain/PagedBytesIndexFieldData.java index 48c954394e5..2dcffbe12cc 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/plain/PagedBytesIndexFieldData.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/plain/PagedBytesIndexFieldData.java @@ -27,15 +27,12 @@ import org.apache.lucene.util.PagedBytes; import org.apache.lucene.util.packed.PackedInts; import org.apache.lucene.util.packed.PackedLongValues; import org.elasticsearch.common.breaker.CircuitBreaker; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.fielddata.*; import org.elasticsearch.index.fielddata.ordinals.Ordinals; import org.elasticsearch.index.fielddata.ordinals.OrdinalsBuilder; -import org.elasticsearch.index.mapper.FieldMapper; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.MapperService; -import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.indices.breaker.CircuitBreakerService; import java.io.IOException; @@ -48,15 +45,15 @@ public class PagedBytesIndexFieldData extends AbstractIndexOrdinalsFieldData { public static class Builder implements IndexFieldData.Builder { @Override - public IndexOrdinalsFieldData build(Index index, @IndexSettings Settings indexSettings, MappedFieldType fieldType, + public IndexOrdinalsFieldData build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache, CircuitBreakerService breakerService, MapperService mapperService) { - return new PagedBytesIndexFieldData(index, indexSettings, fieldType.names(), fieldType.fieldDataType(), cache, breakerService); + return new PagedBytesIndexFieldData(indexSettings, fieldType.names(), fieldType.fieldDataType(), cache, breakerService); } } - public PagedBytesIndexFieldData(Index index, @IndexSettings Settings indexSettings, MappedFieldType.Names fieldNames, + public PagedBytesIndexFieldData(IndexSettings indexSettings, MappedFieldType.Names fieldNames, FieldDataType fieldDataType, IndexFieldDataCache cache, CircuitBreakerService breakerService) { - super(index, indexSettings, fieldNames, fieldDataType, cache, breakerService); + super(indexSettings, fieldNames, fieldDataType, cache, breakerService); } @Override diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/plain/ParentChildIndexFieldData.java b/core/src/main/java/org/elasticsearch/index/fielddata/plain/ParentChildIndexFieldData.java index facdc091e69..b1393542098 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/plain/ParentChildIndexFieldData.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/plain/ParentChildIndexFieldData.java @@ -30,9 +30,9 @@ import org.elasticsearch.common.Nullable; import org.elasticsearch.common.breaker.CircuitBreaker; import org.elasticsearch.common.lease.Releasable; import org.elasticsearch.common.lease.Releasables; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.fielddata.*; import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested; import org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource; @@ -41,7 +41,6 @@ import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.MappedFieldType.Names; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.internal.ParentFieldMapper; -import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.indices.breaker.CircuitBreakerService; import org.elasticsearch.search.MultiValueMode; @@ -58,10 +57,10 @@ public class ParentChildIndexFieldData extends AbstractIndexFieldData parentTypes; private final CircuitBreakerService breakerService; - public ParentChildIndexFieldData(Index index, @IndexSettings Settings indexSettings, MappedFieldType.Names fieldNames, + public ParentChildIndexFieldData(IndexSettings indexSettings, MappedFieldType.Names fieldNames, FieldDataType fieldDataType, IndexFieldDataCache cache, MapperService mapperService, CircuitBreakerService breakerService) { - super(index, indexSettings, fieldNames, fieldDataType, cache); + super(indexSettings, fieldNames, fieldDataType, cache); this.breakerService = breakerService; Set parentTypes = new HashSet<>(); for (DocumentMapper mapper : mapperService.docMappers(false)) { @@ -126,10 +125,11 @@ public class ParentChildIndexFieldData extends AbstractIndexFieldData build(Index index, @IndexSettings Settings indexSettings, MappedFieldType fieldType, + public IndexFieldData build(IndexSettings indexSettings, + MappedFieldType fieldType, IndexFieldDataCache cache, CircuitBreakerService breakerService, MapperService mapperService) { - return new ParentChildIndexFieldData(index, indexSettings, fieldType.names(), fieldType.fieldDataType(), cache, + return new ParentChildIndexFieldData(indexSettings, fieldType.names(), fieldType.fieldDataType(), cache, mapperService, breakerService); } } diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/plain/SortedSetDVOrdinalsIndexFieldData.java b/core/src/main/java/org/elasticsearch/index/fielddata/plain/SortedSetDVOrdinalsIndexFieldData.java index 470423a6599..10b18e3cb83 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/plain/SortedSetDVOrdinalsIndexFieldData.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/plain/SortedSetDVOrdinalsIndexFieldData.java @@ -21,10 +21,8 @@ package org.elasticsearch.index.fielddata.plain; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.IndexReader; import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.fielddata.*; import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested; import org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource; @@ -35,12 +33,12 @@ import org.elasticsearch.indices.breaker.CircuitBreakerService; public class SortedSetDVOrdinalsIndexFieldData extends DocValuesIndexFieldData implements IndexOrdinalsFieldData { - private final Settings indexSettings; + private final IndexSettings indexSettings; private final IndexFieldDataCache cache; private final CircuitBreakerService breakerService; - public SortedSetDVOrdinalsIndexFieldData(Index index, IndexFieldDataCache cache, Settings indexSettings, Names fieldNames, CircuitBreakerService breakerService, FieldDataType fieldDataType) { - super(index, fieldNames, fieldDataType); + public SortedSetDVOrdinalsIndexFieldData(IndexSettings indexSettings, IndexFieldDataCache cache, Names fieldNames, CircuitBreakerService breakerService, FieldDataType fieldDataType) { + super(indexSettings.getIndex(), fieldNames, fieldDataType); this.indexSettings = indexSettings; this.cache = cache; this.breakerService = breakerService; diff --git a/core/src/main/java/org/elasticsearch/index/get/ShardGetService.java b/core/src/main/java/org/elasticsearch/index/get/ShardGetService.java index 1cf68ad383e..1a4938ed532 100644 --- a/core/src/main/java/org/elasticsearch/index/get/ShardGetService.java +++ b/core/src/main/java/org/elasticsearch/index/get/ShardGetService.java @@ -32,6 +32,7 @@ import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.support.XContentMapValues; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.VersionType; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.fieldvisitor.CustomFieldsVisitor; @@ -72,9 +73,9 @@ public final class ShardGetService extends AbstractIndexShardComponent { private final CounterMetric currentMetric = new CounterMetric(); private final IndexShard indexShard; - public ShardGetService(IndexShard indexShard, + public ShardGetService(IndexSettings indexSettings, IndexShard indexShard, MapperService mapperService) { - super(indexShard.shardId(), indexShard.indexSettings()); + super(indexShard.shardId(), indexSettings); this.mapperService = mapperService; this.indexShard = indexShard; } diff --git a/core/src/main/java/org/elasticsearch/index/indexing/ShardIndexingService.java b/core/src/main/java/org/elasticsearch/index/indexing/ShardIndexingService.java index a3a1fa5b4a7..601b94bbcb7 100644 --- a/core/src/main/java/org/elasticsearch/index/indexing/ShardIndexingService.java +++ b/core/src/main/java/org/elasticsearch/index/indexing/ShardIndexingService.java @@ -25,6 +25,7 @@ import org.elasticsearch.common.metrics.MeanMetric; import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.shard.AbstractIndexShardComponent; import org.elasticsearch.index.shard.ShardId; @@ -48,9 +49,9 @@ public class ShardIndexingService extends AbstractIndexShardComponent { private volatile Map typesStats = emptyMap(); - public ShardIndexingService(ShardId shardId, Settings indexSettings) { + public ShardIndexingService(ShardId shardId, IndexSettings indexSettings) { super(shardId, indexSettings); - this.slowLog = new IndexingSlowLog(indexSettings); + this.slowLog = new IndexingSlowLog(this.indexSettings); } /** diff --git a/core/src/main/java/org/elasticsearch/index/mapper/DocumentMapperParser.java b/core/src/main/java/org/elasticsearch/index/mapper/DocumentMapperParser.java index 91371a2663a..8b13b5eba19 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/DocumentMapperParser.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/DocumentMapperParser.java @@ -32,49 +32,20 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.analysis.AnalysisService; -import org.elasticsearch.index.mapper.core.BinaryFieldMapper; -import org.elasticsearch.index.mapper.core.BooleanFieldMapper; -import org.elasticsearch.index.mapper.core.ByteFieldMapper; -import org.elasticsearch.index.mapper.core.CompletionFieldMapper; -import org.elasticsearch.index.mapper.core.DateFieldMapper; -import org.elasticsearch.index.mapper.core.DoubleFieldMapper; -import org.elasticsearch.index.mapper.core.FloatFieldMapper; -import org.elasticsearch.index.mapper.core.IntegerFieldMapper; -import org.elasticsearch.index.mapper.core.LongFieldMapper; -import org.elasticsearch.index.mapper.core.ShortFieldMapper; -import org.elasticsearch.index.mapper.core.StringFieldMapper; -import org.elasticsearch.index.mapper.core.TokenCountFieldMapper; -import org.elasticsearch.index.mapper.core.TypeParsers; +import org.elasticsearch.index.mapper.core.*; import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper; import org.elasticsearch.index.mapper.geo.GeoShapeFieldMapper; -import org.elasticsearch.index.mapper.internal.AllFieldMapper; -import org.elasticsearch.index.mapper.internal.FieldNamesFieldMapper; -import org.elasticsearch.index.mapper.internal.IdFieldMapper; -import org.elasticsearch.index.mapper.internal.IndexFieldMapper; -import org.elasticsearch.index.mapper.internal.ParentFieldMapper; -import org.elasticsearch.index.mapper.internal.RoutingFieldMapper; -import org.elasticsearch.index.mapper.internal.SourceFieldMapper; -import org.elasticsearch.index.mapper.internal.TTLFieldMapper; -import org.elasticsearch.index.mapper.internal.TimestampFieldMapper; -import org.elasticsearch.index.mapper.internal.TypeFieldMapper; -import org.elasticsearch.index.mapper.internal.UidFieldMapper; -import org.elasticsearch.index.mapper.internal.VersionFieldMapper; +import org.elasticsearch.index.mapper.internal.*; import org.elasticsearch.index.mapper.ip.IpFieldMapper; import org.elasticsearch.index.mapper.object.ObjectMapper; import org.elasticsearch.index.mapper.object.RootObjectMapper; -import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.similarity.SimilarityService; import org.elasticsearch.script.Script; import org.elasticsearch.script.ScriptService; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.SortedMap; -import java.util.TreeMap; +import java.util.*; import static java.util.Collections.unmodifiableMap; import static java.util.Collections.unmodifiableSortedMap; @@ -99,10 +70,10 @@ public class DocumentMapperParser { private volatile Map rootTypeParsers; private volatile SortedMap additionalRootMappers; - public DocumentMapperParser(@IndexSettings Settings indexSettings, MapperService mapperService, AnalysisService analysisService, + public DocumentMapperParser(IndexSettings indexSettings, MapperService mapperService, AnalysisService analysisService, SimilarityService similarityService, ScriptService scriptService) { - this.indexSettings = indexSettings; - this.parseFieldMatcher = new ParseFieldMatcher(indexSettings); + this.indexSettings = indexSettings.getSettings(); + this.parseFieldMatcher = new ParseFieldMatcher(this.indexSettings); this.mapperService = mapperService; this.analysisService = analysisService; this.similarityService = similarityService; @@ -147,7 +118,7 @@ public class DocumentMapperParser { rootTypeParsers.put(FieldNamesFieldMapper.NAME, new FieldNamesFieldMapper.TypeParser()); this.rootTypeParsers = unmodifiableMap(rootTypeParsers); additionalRootMappers = Collections.emptySortedMap(); - indexVersionCreated = Version.indexCreated(indexSettings); + indexVersionCreated = Version.indexCreated(this.indexSettings); } public void putTypeParser(String type, Mapper.TypeParser typeParser) { diff --git a/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java b/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java index bbd96f7d930..37590f7e3ad 100755 --- a/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java @@ -20,18 +20,13 @@ package org.elasticsearch.index.mapper; import com.carrotsearch.hppc.ObjectHashSet; - import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.DelegatingAnalyzerWrapper; import org.apache.lucene.index.IndexOptions; import org.apache.lucene.index.Term; import org.apache.lucene.queries.TermsQuery; -import org.apache.lucene.search.BooleanClause; +import org.apache.lucene.search.*; import org.apache.lucene.search.BooleanClause.Occur; -import org.apache.lucene.search.BooleanQuery; -import org.apache.lucene.search.ConstantScoreQuery; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.TermQuery; import org.apache.lucene.util.BytesRef; import org.elasticsearch.ElasticsearchGenerationException; import org.elasticsearch.Version; @@ -41,15 +36,13 @@ import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.lucene.search.Queries; import org.elasticsearch.common.regex.Regex; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ReleasableLock; import org.elasticsearch.index.AbstractIndexComponent; -import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.analysis.AnalysisService; import org.elasticsearch.index.mapper.Mapper.BuilderContext; import org.elasticsearch.index.mapper.internal.TypeFieldMapper; import org.elasticsearch.index.mapper.object.ObjectMapper; -import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.similarity.SimilarityService; import org.elasticsearch.indices.InvalidTypeNameException; import org.elasticsearch.indices.TypeMissingException; @@ -58,24 +51,13 @@ import org.elasticsearch.script.ScriptService; import java.io.Closeable; import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.function.Function; import java.util.stream.Collectors; -import static java.util.Collections.emptyMap; -import static java.util.Collections.emptySet; -import static java.util.Collections.unmodifiableMap; -import static java.util.Collections.unmodifiableSet; +import static java.util.Collections.*; import static org.elasticsearch.common.collect.MapBuilder.newMapBuilder; /** @@ -124,18 +106,18 @@ public class MapperService extends AbstractIndexComponent implements Closeable { private volatile Set parentTypes = emptySet(); @Inject - public MapperService(Index index, @IndexSettings Settings indexSettings, AnalysisService analysisService, + public MapperService(IndexSettings indexSettings, AnalysisService analysisService, SimilarityService similarityService, ScriptService scriptService) { - super(index, indexSettings); + super(indexSettings); this.analysisService = analysisService; this.fieldTypes = new FieldTypeLookup(); this.documentParser = new DocumentMapperParser(indexSettings, this, analysisService, similarityService, scriptService); this.indexAnalyzer = new MapperAnalyzerWrapper(analysisService.defaultIndexAnalyzer(), p -> p.indexAnalyzer()); this.searchAnalyzer = new MapperAnalyzerWrapper(analysisService.defaultSearchAnalyzer(), p -> p.searchAnalyzer()); this.searchQuoteAnalyzer = new MapperAnalyzerWrapper(analysisService.defaultSearchQuoteAnalyzer(), p -> p.searchQuoteAnalyzer()); - - this.dynamic = indexSettings.getAsBoolean("index.mapper.dynamic", true); + + this.dynamic = this.indexSettings.getSettings().getAsBoolean("index.mapper.dynamic", true); defaultPercolatorMappingSource = "{\n" + "\"_default_\":{\n" + "\"properties\" : {\n" + @@ -146,7 +128,7 @@ public class MapperService extends AbstractIndexComponent implements Closeable { "}\n" + "}\n" + "}"; - if (index.getName().equals(ScriptService.SCRIPT_INDEX)){ + if (index().getName().equals(ScriptService.SCRIPT_INDEX)){ defaultMappingSource = "{" + "\"_default_\": {" + "\"properties\": {" + @@ -238,7 +220,7 @@ public class MapperService extends AbstractIndexComponent implements Closeable { if (mapper.type().length() == 0) { throw new InvalidTypeNameException("mapping type name is empty"); } - if (Version.indexCreated(indexSettings).onOrAfter(Version.V_2_0_0_beta1) && mapper.type().length() > 255) { + if (indexSettings.getVersion().onOrAfter(Version.V_2_0_0_beta1) && mapper.type().length() > 255) { throw new InvalidTypeNameException("mapping type name [" + mapper.type() + "] is too long; limit is length 255 but was [" + mapper.type().length() + "]"); } if (mapper.type().charAt(0) == '_') { @@ -254,7 +236,7 @@ public class MapperService extends AbstractIndexComponent implements Closeable { throw new IllegalArgumentException("The [_parent.type] option can't point to the same type"); } if (typeNameStartsWithIllegalDot(mapper)) { - if (Version.indexCreated(indexSettings).onOrAfter(Version.V_2_0_0_beta1)) { + if (indexSettings.getVersion().onOrAfter(Version.V_2_0_0_beta1)) { throw new IllegalArgumentException("mapping type name [" + mapper.type() + "] must not start with a '.'"); } else { logger.warn("Type [{}] starts with a '.', it is recommended not to start a type name with a '.'", mapper.type()); @@ -378,7 +360,7 @@ public class MapperService extends AbstractIndexComponent implements Closeable { return new DocumentMapperForType(mapper, null); } if (!dynamic) { - throw new TypeMissingException(index, type, "trying to auto create mapping, but dynamic mapping is disabled"); + throw new TypeMissingException(index(), type, "trying to auto create mapping, but dynamic mapping is disabled"); } mapper = parse(type, null, true); return new DocumentMapperForType(mapper, mapper.mapping()); @@ -547,7 +529,7 @@ public class MapperService extends AbstractIndexComponent implements Closeable { throw new IllegalArgumentException("No mapper found for type [" + type + "]"); } final Mapper.Builder builder = typeParser.parse("__anonymous_" + type, emptyMap(), parserContext); - final BuilderContext builderContext = new BuilderContext(indexSettings, new ContentPath(1)); + final BuilderContext builderContext = new BuilderContext(indexSettings.getSettings(), new ContentPath(1)); fieldType = ((FieldMapper)builder.build(builderContext)).fieldType(); // There is no need to synchronize writes here. In the case of concurrent access, we could just diff --git a/core/src/main/java/org/elasticsearch/index/mapper/object/ObjectMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/object/ObjectMapper.java index 9d9d0df59bd..fc47fc561cb 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/object/ObjectMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/object/ObjectMapper.java @@ -34,7 +34,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.mapper.*; import org.elasticsearch.index.mapper.internal.AllFieldMapper; import org.elasticsearch.index.mapper.internal.TypeFieldMapper; -import org.elasticsearch.index.settings.IndexSettings; import java.io.IOException; import java.util.*; @@ -166,7 +165,7 @@ public class ObjectMapper extends Mapper implements AllFieldMapper.IncludeInAll, return (Y) objectMapper; } - protected ObjectMapper createMapper(String name, String fullPath, boolean enabled, Nested nested, Dynamic dynamic, ContentPath.Type pathType, Map mappers, @Nullable @IndexSettings Settings settings) { + protected ObjectMapper createMapper(String name, String fullPath, boolean enabled, Nested nested, Dynamic dynamic, ContentPath.Type pathType, Map mappers, @Nullable Settings settings) { return new ObjectMapper(name, fullPath, enabled, nested, dynamic, pathType, mappers); } } diff --git a/core/src/main/java/org/elasticsearch/index/mapper/object/RootObjectMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/object/RootObjectMapper.java index b2e572f5291..a0c989abd7d 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/object/RootObjectMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/object/RootObjectMapper.java @@ -26,22 +26,11 @@ import org.elasticsearch.common.joda.Joda; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.index.mapper.ContentPath; -import org.elasticsearch.index.mapper.Mapper; -import org.elasticsearch.index.mapper.MapperParsingException; -import org.elasticsearch.index.mapper.MergeResult; -import org.elasticsearch.index.mapper.ParseContext; +import org.elasticsearch.index.mapper.*; import org.elasticsearch.index.mapper.core.DateFieldMapper; -import org.elasticsearch.index.settings.IndexSettings; import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeBooleanValue; import static org.elasticsearch.index.mapper.core.TypeParsers.parseDateTimeFormatter; @@ -106,7 +95,7 @@ public class RootObjectMapper extends ObjectMapper { @Override - protected ObjectMapper createMapper(String name, String fullPath, boolean enabled, Nested nested, Dynamic dynamic, ContentPath.Type pathType, Map mappers, @Nullable @IndexSettings Settings settings) { + protected ObjectMapper createMapper(String name, String fullPath, boolean enabled, Nested nested, Dynamic dynamic, ContentPath.Type pathType, Map mappers, @Nullable Settings settings) { assert !nested.isNested(); FormatDateTimeFormatter[] dates = null; if (dynamicDateTimeFormatters == null) { diff --git a/core/src/main/java/org/elasticsearch/index/percolator/PercolatorQueriesRegistry.java b/core/src/main/java/org/elasticsearch/index/percolator/PercolatorQueriesRegistry.java index 1f8a4c61f9a..83fa95195fa 100644 --- a/core/src/main/java/org/elasticsearch/index/percolator/PercolatorQueriesRegistry.java +++ b/core/src/main/java/org/elasticsearch/index/percolator/PercolatorQueriesRegistry.java @@ -30,12 +30,12 @@ import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.metrics.CounterMetric; import org.elasticsearch.common.metrics.MeanMetric; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ConcurrentCollections; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.fielddata.IndexFieldDataService; import org.elasticsearch.index.indexing.IndexingOperationListener; @@ -46,7 +46,6 @@ import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.internal.TypeFieldMapper; import org.elasticsearch.index.query.IndexQueryParserService; import org.elasticsearch.index.query.QueryShardContext; -import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.shard.AbstractIndexShardComponent; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.percolator.PercolatorService; @@ -85,7 +84,7 @@ public final class PercolatorQueriesRegistry extends AbstractIndexShardComponent private final CounterMetric currentMetric = new CounterMetric(); private final CounterMetric numberOfQueries = new CounterMetric(); - public PercolatorQueriesRegistry(ShardId shardId, @IndexSettings Settings indexSettings, IndexQueryParserService queryParserService, + public PercolatorQueriesRegistry(ShardId shardId, IndexSettings indexSettings, IndexQueryParserService queryParserService, ShardIndexingService indexingService, MapperService mapperService, IndexFieldDataService indexFieldDataService) { super(shardId, indexSettings); @@ -93,7 +92,7 @@ public final class PercolatorQueriesRegistry extends AbstractIndexShardComponent this.mapperService = mapperService; this.indexingService = indexingService; this.indexFieldDataService = indexFieldDataService; - this.mapUnmappedFieldsAsString = indexSettings.getAsBoolean(MAP_UNMAPPED_FIELDS_AS_STRING, false); + this.mapUnmappedFieldsAsString = this.indexSettings.getAsBoolean(MAP_UNMAPPED_FIELDS_AS_STRING, false); mapperService.addTypeListener(percolateTypeListener); } diff --git a/core/src/main/java/org/elasticsearch/index/query/IndexQueryParserService.java b/core/src/main/java/org/elasticsearch/index/query/IndexQueryParserService.java index 76a1577b2a4..df8be3f2219 100644 --- a/core/src/main/java/org/elasticsearch/index/query/IndexQueryParserService.java +++ b/core/src/main/java/org/elasticsearch/index/query/IndexQueryParserService.java @@ -33,12 +33,11 @@ import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.lucene.search.Queries; import org.elasticsearch.common.regex.Regex; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.AbstractIndexComponent; -import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.analysis.AnalysisService; import org.elasticsearch.index.cache.IndexCache; import org.elasticsearch.index.cache.bitset.BitsetFilterCache; @@ -46,7 +45,6 @@ import org.elasticsearch.index.fielddata.IndexFieldDataService; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.internal.AllFieldMapper; import org.elasticsearch.index.query.support.InnerHitsQueryParserHelper; -import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.similarity.SimilarityService; import org.elasticsearch.indices.query.IndicesQueriesRegistry; import org.elasticsearch.script.ScriptService; @@ -66,7 +64,7 @@ public class IndexQueryParserService extends AbstractIndexComponent { private CloseableThreadLocal cache = new CloseableThreadLocal() { @Override protected QueryShardContext initialValue() { - return new QueryShardContext(index, IndexQueryParserService.this); + return new QueryShardContext(IndexQueryParserService.this); } }; @@ -99,7 +97,7 @@ public class IndexQueryParserService extends AbstractIndexComponent { private final Client client; @Inject - public IndexQueryParserService(Index index, @IndexSettings Settings indexSettings, Settings settings, + public IndexQueryParserService(IndexSettings indexSettings, IndicesQueriesRegistry indicesQueriesRegistry, ScriptService scriptService, AnalysisService analysisService, MapperService mapperService, IndexCache indexCache, IndexFieldDataService fieldDataService, @@ -107,7 +105,7 @@ public class IndexQueryParserService extends AbstractIndexComponent { @Nullable SimilarityService similarityService, ClusterService clusterService, IndexNameExpressionResolver indexNameExpressionResolver, InnerHitsQueryParserHelper innerHitsQueryParserHelper, Client client) { - super(index, indexSettings); + super(indexSettings); this.scriptService = scriptService; this.analysisService = analysisService; this.mapperService = mapperService; @@ -118,12 +116,12 @@ public class IndexQueryParserService extends AbstractIndexComponent { this.clusterService = clusterService; this.indexNameExpressionResolver = indexNameExpressionResolver; - this.defaultField = indexSettings.get(DEFAULT_FIELD, AllFieldMapper.NAME); - this.queryStringLenient = indexSettings.getAsBoolean(QUERY_STRING_LENIENT, false); - this.queryStringAnalyzeWildcard = settings.getAsBoolean(QUERY_STRING_ANALYZE_WILDCARD, false); - this.queryStringAllowLeadingWildcard = settings.getAsBoolean(QUERY_STRING_ALLOW_LEADING_WILDCARD, true); - this.parseFieldMatcher = new ParseFieldMatcher(indexSettings); - this.defaultAllowUnmappedFields = indexSettings.getAsBoolean(ALLOW_UNMAPPED, true); + this.defaultField = this.indexSettings.getSettings().get(DEFAULT_FIELD, AllFieldMapper.NAME); + this.queryStringLenient = this.indexSettings.getSettings().getAsBoolean(QUERY_STRING_LENIENT, false); + this.queryStringAnalyzeWildcard = indexSettings.getSettings().getAsBoolean(QUERY_STRING_ANALYZE_WILDCARD, false); + this.queryStringAllowLeadingWildcard = indexSettings.getSettings().getAsBoolean(QUERY_STRING_ALLOW_LEADING_WILDCARD, true); + this.parseFieldMatcher = new ParseFieldMatcher(this.indexSettings.getSettings()); + this.defaultAllowUnmappedFields = this.indexSettings.getSettings().getAsBoolean(ALLOW_UNMAPPED, true); this.indicesQueriesRegistry = indicesQueriesRegistry; this.innerHitsQueryParserHelper = innerHitsQueryParserHelper; this.client = client; @@ -209,7 +207,7 @@ public class IndexQueryParserService extends AbstractIndexComponent { * @return The lowest node version in the cluster when the index was created or null if that was unknown */ public Version getIndexCreatedVersion() { - return Version.indexCreated(indexSettings); + return indexSettings.getVersion(); } /** @@ -291,7 +289,7 @@ public class IndexQueryParserService extends AbstractIndexComponent { public boolean matchesIndices(String... indices) { final String[] concreteIndices = indexNameExpressionResolver.concreteIndices(clusterService.state(), IndicesOptions.lenientExpandOpen(), indices); for (String index : concreteIndices) { - if (Regex.simpleMatch(index, this.index.name())) { + if (Regex.simpleMatch(index, index().name())) { return true; } } diff --git a/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java b/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java index 82098988a31..087c32946ec 100644 --- a/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java +++ b/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java @@ -83,8 +83,6 @@ public class QueryShardContext { typesContext.remove(); } - private final Index index; - private final Version indexVersionCreated; private final IndexQueryParserService indexQueryParser; @@ -103,9 +101,8 @@ public class QueryShardContext { boolean isFilter; - public QueryShardContext(Index index, IndexQueryParserService indexQueryParser) { - this.index = index; - this.indexVersionCreated = Version.indexCreated(indexQueryParser.indexSettings()); + public QueryShardContext(IndexQueryParserService indexQueryParser) { + this.indexVersionCreated = indexQueryParser.getIndexCreatedVersion(); this.indexQueryParser = indexQueryParser; this.parseContext = new QueryParseContext(indexQueryParser.indicesQueriesRegistry()); } @@ -132,7 +129,7 @@ public class QueryShardContext { } public Index index() { - return this.index; + return this.indexQueryParser.index(); } public IndexQueryParserService indexQueryParserService() { diff --git a/core/src/main/java/org/elasticsearch/index/query/TemplateQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/TemplateQueryBuilder.java index d63f160542e..1cdca373587 100644 --- a/core/src/main/java/org/elasticsearch/index/query/TemplateQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/TemplateQueryBuilder.java @@ -102,7 +102,7 @@ public class TemplateQueryBuilder extends AbstractQueryBuilder { - - private final IndexSettingsService indexSettingsService; - - @Inject - public IndexSettingsProvider(IndexSettingsService indexSettingsService) { - this.indexSettingsService = indexSettingsService; - } - - @Override - public Settings get() { - return indexSettingsService.getSettings(); - } -} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/index/settings/IndexSettingsService.java b/core/src/main/java/org/elasticsearch/index/settings/IndexSettingsService.java deleted file mode 100644 index d76540e1e85..00000000000 --- a/core/src/main/java/org/elasticsearch/index/settings/IndexSettingsService.java +++ /dev/null @@ -1,85 +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.settings; - -import org.elasticsearch.cluster.metadata.IndexMetaData; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.AbstractIndexComponent; -import org.elasticsearch.index.Index; - -import java.util.concurrent.CopyOnWriteArrayList; - -/** - * A holds to the latest, updated settings for an index. - */ -public class IndexSettingsService extends AbstractIndexComponent { - - private volatile Settings settings; - - private final CopyOnWriteArrayList listeners = new CopyOnWriteArrayList<>(); - - @Inject - public IndexSettingsService(Index index, Settings settings) { - super(index, settings); - this.settings = settings; - } - - public synchronized void refreshSettings(Settings settings) { - // this.settings include also the node settings - if (this.settings.getByPrefix(IndexMetaData.INDEX_SETTING_PREFIX).getAsMap().equals(settings.getByPrefix(IndexMetaData.INDEX_SETTING_PREFIX).getAsMap())) { - // nothing to update, same settings - return; - } - this.settings = Settings.settingsBuilder().put(this.settings).put(settings).build(); - for (Listener listener : listeners) { - try { - listener.onRefreshSettings(settings); - } catch (Exception e) { - logger.warn("failed to refresh settings for [{}]", e, listener); - } - } - } - - public Settings getSettings() { - return this.settings; - } - - /** - * Only settings registered in {@link org.elasticsearch.cluster.ClusterModule} can be changed dynamically. - */ - public void addListener(Listener listener) { - this.listeners.add(listener); - } - - public void removeListener(Listener listener) { - this.listeners.remove(listener); - } - - /** - * Returns true iff the given listener is already registered otherwise false - */ - public boolean isRegistered(Listener listener) { - return listeners.contains(listener); - } - public interface Listener { - void onRefreshSettings(Settings settings); - } -} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/index/shard/AbstractIndexShardComponent.java b/core/src/main/java/org/elasticsearch/index/shard/AbstractIndexShardComponent.java index 76ae65522c4..d39f4d19e50 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/AbstractIndexShardComponent.java +++ b/core/src/main/java/org/elasticsearch/index/shard/AbstractIndexShardComponent.java @@ -23,7 +23,7 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; /** * @@ -35,10 +35,10 @@ public abstract class AbstractIndexShardComponent implements IndexShardComponent protected final ShardId shardId; protected final Settings indexSettings; - protected AbstractIndexShardComponent(ShardId shardId, @IndexSettings Settings indexSettings) { + protected AbstractIndexShardComponent(ShardId shardId, IndexSettings indexSettings) { this.shardId = shardId; - this.indexSettings = indexSettings; - this.logger = Loggers.getLogger(getClass(), indexSettings, shardId); + this.indexSettings = indexSettings.getSettings(); + this.logger = Loggers.getLogger(getClass(), this.indexSettings, shardId); this.deprecationLogger = new DeprecationLogger(logger); } 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 28e78f4e48b..f9ed256c613 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java +++ b/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java @@ -55,6 +55,7 @@ import org.elasticsearch.common.util.concurrent.AbstractRefCounted; import org.elasticsearch.common.util.concurrent.AbstractRunnable; import org.elasticsearch.common.util.concurrent.FutureUtils; import org.elasticsearch.gateway.MetaDataStateFormat; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.IndexServicesProvider; import org.elasticsearch.index.VersionType; import org.elasticsearch.index.cache.IndexCache; @@ -80,8 +81,6 @@ import org.elasticsearch.index.recovery.RecoveryStats; import org.elasticsearch.index.refresh.RefreshStats; import org.elasticsearch.index.search.stats.SearchStats; import org.elasticsearch.index.search.stats.ShardSearchStats; -import org.elasticsearch.index.settings.IndexSettings; -import org.elasticsearch.index.settings.IndexSettingsService; import org.elasticsearch.index.similarity.SimilarityService; import org.elasticsearch.index.snapshots.IndexShardRepository; import org.elasticsearch.index.store.Store.MetadataSnapshot; @@ -119,7 +118,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; -public class IndexShard extends AbstractIndexShardComponent implements IndexSettingsService.Listener { +public class IndexShard extends AbstractIndexShardComponent { private final ThreadPool threadPool; private final MapperService mapperService; @@ -197,7 +196,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett private final IndexingMemoryController indexingMemoryController; @Inject - public IndexShard(ShardId shardId, @IndexSettings Settings indexSettings, ShardPath path, Store store, IndexServicesProvider provider) { + public IndexShard(ShardId shardId, IndexSettings indexSettings, ShardPath path, Store store, IndexServicesProvider provider) { super(shardId, indexSettings); this.codecService = provider.getCodecService(); this.warmer = provider.getWarmer(); @@ -207,14 +206,14 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett this.engineFactory = provider.getFactory(); this.store = store; this.indexEventListener = provider.getIndexEventListener(); - this.mergeSchedulerConfig = new MergeSchedulerConfig(indexSettings); + this.mergeSchedulerConfig = new MergeSchedulerConfig(this.indexSettings); this.threadPool = provider.getThreadPool(); this.mapperService = provider.getMapperService(); this.indexCache = provider.getIndexCache(); this.indexingService = new ShardIndexingService(shardId, indexSettings); - this.getService = new ShardGetService(this, mapperService); + this.getService = new ShardGetService(indexSettings, this, mapperService); this.termVectorsService = provider.getTermVectorsService(); - this.searchService = new ShardSearchStats(indexSettings); + this.searchService = new ShardSearchStats(this.indexSettings); this.shardWarmerService = new ShardIndexWarmerService(shardId, indexSettings); this.indicesQueryCache = provider.getIndicesQueryCache(); this.shardQueryCache = new ShardRequestCache(shardId, indexSettings); @@ -222,29 +221,29 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett this.indexFieldDataService = provider.getIndexFieldDataService(); this.shardBitsetFilterCache = new ShardBitsetFilterCache(shardId, indexSettings); state = IndexShardState.CREATED; - this.refreshInterval = indexSettings.getAsTime(INDEX_REFRESH_INTERVAL, EngineConfig.DEFAULT_REFRESH_INTERVAL); - this.flushOnClose = indexSettings.getAsBoolean(INDEX_FLUSH_ON_CLOSE, true); + this.refreshInterval = this.indexSettings.getAsTime(INDEX_REFRESH_INTERVAL, EngineConfig.DEFAULT_REFRESH_INTERVAL); + this.flushOnClose = this.indexSettings.getAsBoolean(INDEX_FLUSH_ON_CLOSE, true); this.path = path; - this.mergePolicyConfig = new MergePolicyConfig(logger, indexSettings); + this.mergePolicyConfig = new MergePolicyConfig(logger, this.indexSettings); /* create engine config */ logger.debug("state: [CREATED]"); - this.checkIndexOnStartup = indexSettings.get("index.shard.check_on_startup", "false"); - this.translogConfig = new TranslogConfig(shardId, shardPath().resolveTranslog(), indexSettings, getFromSettings(logger, indexSettings, Translog.Durabilty.REQUEST), + this.checkIndexOnStartup = this.indexSettings.get("index.shard.check_on_startup", "false"); + this.translogConfig = new TranslogConfig(shardId, shardPath().resolveTranslog(), indexSettings, getFromSettings(logger, this.indexSettings, Translog.Durabilty.REQUEST), provider.getBigArrays(), threadPool); final QueryCachingPolicy cachingPolicy; // the query cache is a node-level thing, however we want the most popular filters // to be computed on a per-shard basis - if (indexSettings.getAsBoolean(IndexCacheModule.QUERY_CACHE_EVERYTHING, false)) { + if (this.indexSettings.getAsBoolean(IndexCacheModule.QUERY_CACHE_EVERYTHING, false)) { cachingPolicy = QueryCachingPolicy.ALWAYS_CACHE; } else { cachingPolicy = new UsageTrackingQueryCachingPolicy(); } this.engineConfig = newEngineConfig(translogConfig, cachingPolicy); - this.flushThresholdOperations = indexSettings.getAsInt(INDEX_TRANSLOG_FLUSH_THRESHOLD_OPS, indexSettings.getAsInt("index.translog.flush_threshold", Integer.MAX_VALUE)); - this.flushThresholdSize = indexSettings.getAsBytesSize(INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE, new ByteSizeValue(512, ByteSizeUnit.MB)); - this.disableFlush = indexSettings.getAsBoolean(INDEX_TRANSLOG_DISABLE_FLUSH, false); + this.flushThresholdOperations = this.indexSettings.getAsInt(INDEX_TRANSLOG_FLUSH_THRESHOLD_OPS, this.indexSettings.getAsInt("index.translog.flush_threshold", Integer.MAX_VALUE)); + this.flushThresholdSize = this.indexSettings.getAsBytesSize(INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE, new ByteSizeValue(512, ByteSizeUnit.MB)); + this.disableFlush = this.indexSettings.getAsBoolean(INDEX_TRANSLOG_DISABLE_FLUSH, false); this.indexShardOperationCounter = new IndexShardOperationCounter(logger, shardId); this.indexingMemoryController = provider.getIndexingMemoryController(); @@ -1005,7 +1004,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett long iwBytesUsed = engine.indexWriterRAMBytesUsed(); String message = LoggerMessageFormat.format("updating index_buffer_size from [{}] to [{}]; IndexWriter now using [{}] bytes", - preValue, shardIndexingBufferSize, iwBytesUsed); + preValue, shardIndexingBufferSize, iwBytesUsed); if (iwBytesUsed > shardIndexingBufferSize.bytes()) { // our allowed buffer was changed to less than we are currently using; we ask IW to refresh @@ -1102,7 +1101,6 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett return false; } - @Override public void onRefreshSettings(Settings settings) { boolean change = false; synchronized (mutex) { diff --git a/core/src/main/java/org/elasticsearch/index/shard/MergePolicyConfig.java b/core/src/main/java/org/elasticsearch/index/shard/MergePolicyConfig.java index c664d3a3794..0e1ecc1d208 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/MergePolicyConfig.java +++ b/core/src/main/java/org/elasticsearch/index/shard/MergePolicyConfig.java @@ -26,7 +26,6 @@ import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.unit.ByteSizeValue; -import org.elasticsearch.index.settings.IndexSettingsService; /** * A shard in elasticsearch is a Lucene index, and a Lucene index is broken @@ -114,7 +113,7 @@ import org.elasticsearch.index.settings.IndexSettingsService; * call for the index (try and aim to issue it on a low traffic time). */ -public final class MergePolicyConfig implements IndexSettingsService.Listener{ +public final class MergePolicyConfig { private final TieredMergePolicy mergePolicy = new TieredMergePolicy(); private final ESLogger logger; private final boolean mergesEnabled; @@ -185,7 +184,6 @@ public final class MergePolicyConfig implements IndexSettingsService.Listener{ return mergesEnabled ? mergePolicy : NoMergePolicy.INSTANCE; } - @Override public void onRefreshSettings(Settings settings) { final double oldExpungeDeletesPctAllowed = mergePolicy.getForceMergeDeletesPctAllowed(); final double expungeDeletesPctAllowed = settings.getAsDouble(INDEX_MERGE_POLICY_EXPUNGE_DELETES_ALLOWED, oldExpungeDeletesPctAllowed); diff --git a/core/src/main/java/org/elasticsearch/index/shard/ShadowIndexShard.java b/core/src/main/java/org/elasticsearch/index/shard/ShadowIndexShard.java index 8bdf1fb5382..26e8e55b64f 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/ShadowIndexShard.java +++ b/core/src/main/java/org/elasticsearch/index/shard/ShadowIndexShard.java @@ -21,12 +21,11 @@ package org.elasticsearch.index.shard; import java.io.IOException; import org.elasticsearch.cluster.routing.ShardRouting; -import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.IndexServicesProvider; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.engine.EngineConfig; import org.elasticsearch.index.merge.MergeStats; -import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.store.Store; import org.elasticsearch.index.translog.TranslogStats; @@ -38,7 +37,7 @@ import org.elasticsearch.index.translog.TranslogStats; */ public final class ShadowIndexShard extends IndexShard { - public ShadowIndexShard(ShardId shardId, @IndexSettings Settings indexSettings, ShardPath path, Store store, IndexServicesProvider provider) throws IOException { + public ShadowIndexShard(ShardId shardId, IndexSettings indexSettings, ShardPath path, Store store, IndexServicesProvider provider) throws IOException { super(shardId, indexSettings, path, store, provider); } diff --git a/core/src/main/java/org/elasticsearch/index/shard/ShardPath.java b/core/src/main/java/org/elasticsearch/index/shard/ShardPath.java index b2b26c12d19..327a080cd6a 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/ShardPath.java +++ b/core/src/main/java/org/elasticsearch/index/shard/ShardPath.java @@ -20,12 +20,10 @@ package org.elasticsearch.index.shard; import org.apache.lucene.util.IOUtils; import org.elasticsearch.cluster.metadata.IndexMetaData; -import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.env.ShardLock; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; import java.io.IOException; import java.nio.file.FileStore; @@ -116,8 +114,8 @@ public final class ShardPath { * directories with a valid shard state exist the one with the highest version will be used. * Note: this method resolves custom data locations for the shard. */ - public static ShardPath loadShardPath(ESLogger logger, NodeEnvironment env, ShardId shardId, @IndexSettings Settings indexSettings) throws IOException { - final String indexUUID = indexSettings.get(IndexMetaData.SETTING_INDEX_UUID, IndexMetaData.INDEX_UUID_NA_VALUE); + public static ShardPath loadShardPath(ESLogger logger, NodeEnvironment env, ShardId shardId, IndexSettings indexSettings) throws IOException { + final String indexUUID = indexSettings.getUUID(); final Path[] paths = env.availableShardPaths(shardId); Path loadedPath = null; for (Path path : paths) { @@ -140,13 +138,13 @@ public final class ShardPath { } else { final Path dataPath; final Path statePath = loadedPath; - if (NodeEnvironment.hasCustomDataPath(indexSettings)) { - dataPath = env.resolveCustomLocation(indexSettings, shardId); + if (indexSettings.hasCustomDataPath()) { + dataPath = env.resolveCustomLocation(indexSettings.getSettings(), shardId); } else { dataPath = statePath; } logger.debug("{} loaded data path [{}], state path [{}]", shardId, dataPath, statePath); - return new ShardPath(NodeEnvironment.hasCustomDataPath(indexSettings), dataPath, statePath, indexUUID, shardId); + return new ShardPath(indexSettings.hasCustomDataPath(), dataPath, statePath, indexUUID, shardId); } } @@ -154,8 +152,8 @@ public final class ShardPath { * This method tries to delete left-over shards where the index name has been reused but the UUID is different * to allow the new shard to be allocated. */ - public static void deleteLeftoverShardDirectory(ESLogger logger, NodeEnvironment env, ShardLock lock, @IndexSettings Settings indexSettings) throws IOException { - final String indexUUID = indexSettings.get(IndexMetaData.SETTING_INDEX_UUID, IndexMetaData.INDEX_UUID_NA_VALUE); + public static void deleteLeftoverShardDirectory(ESLogger logger, NodeEnvironment env, ShardLock lock, IndexSettings indexSettings) throws IOException { + final String indexUUID = indexSettings.getUUID(); final Path[] paths = env.availableShardPaths(lock.getShardId()); for (Path path : paths) { ShardStateMetaData load = ShardStateMetaData.FORMAT.loadLatestState(logger, path); @@ -163,7 +161,7 @@ public final class ShardPath { if (load.indexUUID.equals(indexUUID) == false && IndexMetaData.INDEX_UUID_NA_VALUE.equals(load.indexUUID) == false) { logger.warn("{} deleting leftover shard on path: [{}] with a different index UUID", lock.getShardId(), path); assert Files.isDirectory(path) : path + " is not a directory"; - NodeEnvironment.acquireFSLockForPaths(indexSettings, paths); + NodeEnvironment.acquireFSLockForPaths(indexSettings.getSettings(), paths); IOUtils.rm(path); } } @@ -198,14 +196,14 @@ public final class ShardPath { return reservedBytes; } - public static ShardPath selectNewPathForShard(NodeEnvironment env, ShardId shardId, @IndexSettings Settings indexSettings, + public static ShardPath selectNewPathForShard(NodeEnvironment env, ShardId shardId, IndexSettings indexSettings, long avgShardSizeInBytes, Map dataPathToShardCount) throws IOException { final Path dataPath; final Path statePath; - if (NodeEnvironment.hasCustomDataPath(indexSettings)) { - dataPath = env.resolveCustomLocation(indexSettings, shardId); + if (indexSettings.hasCustomDataPath()) { + dataPath = env.resolveCustomLocation(indexSettings.getSettings(), shardId); statePath = env.nodePaths()[0].resolve(shardId); } else { @@ -244,9 +242,8 @@ public final class ShardPath { dataPath = statePath; } - final String indexUUID = indexSettings.get(IndexMetaData.SETTING_INDEX_UUID, IndexMetaData.INDEX_UUID_NA_VALUE); - - return new ShardPath(NodeEnvironment.hasCustomDataPath(indexSettings), dataPath, statePath, indexUUID, shardId); + final String indexUUID = indexSettings.getUUID(); + return new ShardPath(indexSettings.hasCustomDataPath(), dataPath, statePath, indexUUID, shardId); } @Override diff --git a/core/src/main/java/org/elasticsearch/index/similarity/SimilarityModule.java b/core/src/main/java/org/elasticsearch/index/similarity/SimilarityModule.java index 29312f2557b..5d1b9d9a761 100644 --- a/core/src/main/java/org/elasticsearch/index/similarity/SimilarityModule.java +++ b/core/src/main/java/org/elasticsearch/index/similarity/SimilarityModule.java @@ -21,7 +21,7 @@ package org.elasticsearch.index.similarity; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import java.util.HashMap; import java.util.Map; @@ -40,13 +40,10 @@ public class SimilarityModule extends AbstractModule { public static final String SIMILARITY_SETTINGS_PREFIX = "index.similarity"; - private final Settings settings; private final Map> similarities = new HashMap<>(); - private final Index index; - - public SimilarityModule(Index index, Settings settings) { - this.settings = settings; - this.index = index; + private final IndexSettings indexSettings; + public SimilarityModule(IndexSettings indexSettings) { + this.indexSettings = indexSettings; } /** @@ -64,7 +61,7 @@ public class SimilarityModule extends AbstractModule { @Override protected void configure() { - SimilarityService service = new SimilarityService(index, settings, new HashMap<>(similarities)); + SimilarityService service = new SimilarityService(indexSettings, new HashMap<>(similarities)); bind(SimilarityService.class).toInstance(service); } } diff --git a/core/src/main/java/org/elasticsearch/index/similarity/SimilarityService.java b/core/src/main/java/org/elasticsearch/index/similarity/SimilarityService.java index a77a2de4dff..63e42719e1b 100644 --- a/core/src/main/java/org/elasticsearch/index/similarity/SimilarityService.java +++ b/core/src/main/java/org/elasticsearch/index/similarity/SimilarityService.java @@ -24,10 +24,9 @@ import org.apache.lucene.search.similarities.Similarity; 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.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.MapperService; -import org.elasticsearch.index.settings.IndexSettings; import java.util.Collections; import java.util.HashMap; @@ -59,19 +58,12 @@ public class SimilarityService extends AbstractIndexComponent { DEFAULTS = Collections.unmodifiableMap(defaults); BUILT_IN = Collections.unmodifiableMap(buildIn); } - public SimilarityService(Index index) { - this(index, Settings.Builder.EMPTY_SETTINGS); - } - - public SimilarityService(Index index, Settings settings) { - this(index, settings, Collections.EMPTY_MAP); - } @Inject - public SimilarityService(Index index, @IndexSettings Settings indexSettings, Map> similarities) { - super(index, indexSettings); + public SimilarityService(IndexSettings indexSettings, Map> similarities) { + super(indexSettings); Map providers = new HashMap<>(similarities.size()); - Map similaritySettings = indexSettings.getGroups(SimilarityModule.SIMILARITY_SETTINGS_PREFIX); + Map similaritySettings = this.indexSettings.getSettings().getGroups(SimilarityModule.SIMILARITY_SETTINGS_PREFIX); for (Map.Entry entry : similaritySettings.entrySet()) { String name = entry.getKey(); Settings settings = entry.getValue(); diff --git a/core/src/main/java/org/elasticsearch/index/store/DirectoryService.java b/core/src/main/java/org/elasticsearch/index/store/DirectoryService.java index fbf25649b74..90f9ed92712 100644 --- a/core/src/main/java/org/elasticsearch/index/store/DirectoryService.java +++ b/core/src/main/java/org/elasticsearch/index/store/DirectoryService.java @@ -20,8 +20,7 @@ package org.elasticsearch.index.store; import org.apache.lucene.store.Directory; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.shard.AbstractIndexShardComponent; import org.elasticsearch.index.shard.ShardId; @@ -31,7 +30,7 @@ import java.io.IOException; */ public abstract class DirectoryService extends AbstractIndexShardComponent { - protected DirectoryService(ShardId shardId, @IndexSettings Settings indexSettings) { + protected DirectoryService(ShardId shardId, IndexSettings indexSettings) { super(shardId, indexSettings); } diff --git a/core/src/main/java/org/elasticsearch/index/store/FsDirectoryService.java b/core/src/main/java/org/elasticsearch/index/store/FsDirectoryService.java index 2d12fab1637..837b113d1c5 100644 --- a/core/src/main/java/org/elasticsearch/index/store/FsDirectoryService.java +++ b/core/src/main/java/org/elasticsearch/index/store/FsDirectoryService.java @@ -19,23 +19,13 @@ package org.elasticsearch.index.store; -import org.apache.lucene.store.Directory; -import org.apache.lucene.store.FSDirectory; -import org.apache.lucene.store.FileSwitchDirectory; -import org.apache.lucene.store.LockFactory; -import org.apache.lucene.store.MMapDirectory; -import org.apache.lucene.store.NIOFSDirectory; -import org.apache.lucene.store.NativeFSLockFactory; -import org.apache.lucene.store.RateLimitedFSDirectory; -import org.apache.lucene.store.SimpleFSDirectory; -import org.apache.lucene.store.SimpleFSLockFactory; -import org.apache.lucene.store.StoreRateLimiting; +import org.apache.lucene.store.*; import org.apache.lucene.util.Constants; 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.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.shard.ShardPath; import java.io.IOException; @@ -54,7 +44,7 @@ public class FsDirectoryService extends DirectoryService implements StoreRateLim private final ShardPath path; @Inject - public FsDirectoryService(@IndexSettings Settings indexSettings, IndexStore indexStore, ShardPath path) { + public FsDirectoryService(IndexSettings indexSettings, IndexStore indexStore, ShardPath path) { super(path.getShardId(), indexSettings); this.path = path; this.indexStore = indexStore; @@ -70,7 +60,7 @@ public class FsDirectoryService extends DirectoryService implements StoreRateLim return indexStore.rateLimiting(); } - public static LockFactory buildLockFactory(@IndexSettings Settings indexSettings) { + public static LockFactory buildLockFactory(Settings indexSettings) { String fsLock = indexSettings.get("index.store.fs.lock", indexSettings.get("index.store.fs.fs_lock", "native")); LockFactory lockFactory; if (fsLock.equals("native")) { 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 3a23a09a652..07ae843421a 100644 --- a/core/src/main/java/org/elasticsearch/index/store/IndexStore.java +++ b/core/src/main/java/org/elasticsearch/index/store/IndexStore.java @@ -24,82 +24,41 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.index.AbstractIndexComponent; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; -import org.elasticsearch.index.settings.IndexSettingsService; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.shard.ShardPath; import org.elasticsearch.indices.store.IndicesStore; -import java.io.Closeable; - /** * */ -public class IndexStore extends AbstractIndexComponent implements Closeable { +public class IndexStore extends AbstractIndexComponent { public static final String INDEX_STORE_THROTTLE_TYPE = "index.store.throttle.type"; public static final String INDEX_STORE_THROTTLE_MAX_BYTES_PER_SEC = "index.store.throttle.max_bytes_per_sec"; - private final IndexSettingsService settingsService; - - class ApplySettings implements IndexSettingsService.Listener { - @Override - public void onRefreshSettings(Settings settings) { - String rateLimitingType = settings.get(INDEX_STORE_THROTTLE_TYPE, IndexStore.this.rateLimitingType); - if (!rateLimitingType.equals(IndexStore.this.rateLimitingType)) { - logger.info("updating index.store.throttle.type from [{}] to [{}]", IndexStore.this.rateLimitingType, rateLimitingType); - if (rateLimitingType.equalsIgnoreCase("node")) { - IndexStore.this.rateLimitingType = rateLimitingType; - IndexStore.this.nodeRateLimiting = true; - } else { - StoreRateLimiting.Type.fromString(rateLimitingType); - IndexStore.this.rateLimitingType = rateLimitingType; - IndexStore.this.nodeRateLimiting = false; - IndexStore.this.rateLimiting.setType(rateLimitingType); - } - } - - ByteSizeValue rateLimitingThrottle = settings.getAsBytesSize(INDEX_STORE_THROTTLE_MAX_BYTES_PER_SEC, IndexStore.this.rateLimitingThrottle); - if (!rateLimitingThrottle.equals(IndexStore.this.rateLimitingThrottle)) { - logger.info("updating index.store.throttle.max_bytes_per_sec from [{}] to [{}], note, type is [{}]", IndexStore.this.rateLimitingThrottle, rateLimitingThrottle, IndexStore.this.rateLimitingType); - IndexStore.this.rateLimitingThrottle = rateLimitingThrottle; - IndexStore.this.rateLimiting.setMaxRate(rateLimitingThrottle); - } - } - } protected final IndicesStore indicesStore; - private volatile String rateLimitingType; private volatile ByteSizeValue rateLimitingThrottle; private volatile boolean nodeRateLimiting; private final StoreRateLimiting rateLimiting = new StoreRateLimiting(); - private final ApplySettings applySettings = new ApplySettings(); - @Inject - public IndexStore(Index index, @IndexSettings Settings indexSettings, IndexSettingsService settingsService, IndicesStore indicesStore) { - super(index, indexSettings); - this.indicesStore = indicesStore; + public IndexStore(IndexSettings indexSettings, IndicesStore indicesStore) { + super(indexSettings); + this.indicesStore = indicesStore; - this.rateLimitingType = indexSettings.get(INDEX_STORE_THROTTLE_TYPE, "none"); + this.rateLimitingType = indexSettings.getSettings().get(INDEX_STORE_THROTTLE_TYPE, "none"); if (rateLimitingType.equalsIgnoreCase("node")) { nodeRateLimiting = true; } else { nodeRateLimiting = false; rateLimiting.setType(rateLimitingType); } - this.rateLimitingThrottle = indexSettings.getAsBytesSize(INDEX_STORE_THROTTLE_MAX_BYTES_PER_SEC, new ByteSizeValue(0)); + this.rateLimitingThrottle = indexSettings.getSettings().getAsBytesSize(INDEX_STORE_THROTTLE_MAX_BYTES_PER_SEC, new ByteSizeValue(0)); rateLimiting.setMaxRate(rateLimitingThrottle); logger.debug("using index.store.throttle.type [{}], with index.store.throttle.max_bytes_per_sec [{}]", rateLimitingType, rateLimitingThrottle); - this.settingsService = settingsService; - this.settingsService.addListener(applySettings); - } - - @Override - public void close() { - settingsService.removeListener(applySettings); } /** @@ -116,4 +75,27 @@ public class IndexStore extends AbstractIndexComponent implements Closeable { public DirectoryService newDirectoryService(ShardPath path) { return new FsDirectoryService(indexSettings, this, path); } + + public void onRefreshSettings(Settings settings) { + String rateLimitingType = settings.get(INDEX_STORE_THROTTLE_TYPE, IndexStore.this.rateLimitingType); + if (!rateLimitingType.equals(IndexStore.this.rateLimitingType)) { + logger.info("updating index.store.throttle.type from [{}] to [{}]", IndexStore.this.rateLimitingType, rateLimitingType); + if (rateLimitingType.equalsIgnoreCase("node")) { + IndexStore.this.rateLimitingType = rateLimitingType; + IndexStore.this.nodeRateLimiting = true; + } else { + StoreRateLimiting.Type.fromString(rateLimitingType); + IndexStore.this.rateLimitingType = rateLimitingType; + IndexStore.this.nodeRateLimiting = false; + IndexStore.this.rateLimiting.setType(rateLimitingType); + } + } + + ByteSizeValue rateLimitingThrottle = settings.getAsBytesSize(INDEX_STORE_THROTTLE_MAX_BYTES_PER_SEC, IndexStore.this.rateLimitingThrottle); + if (!rateLimitingThrottle.equals(IndexStore.this.rateLimitingThrottle)) { + logger.info("updating index.store.throttle.max_bytes_per_sec from [{}] to [{}], note, type is [{}]", IndexStore.this.rateLimitingThrottle, rateLimitingThrottle, IndexStore.this.rateLimitingType); + IndexStore.this.rateLimitingThrottle = rateLimitingThrottle; + IndexStore.this.rateLimiting.setMaxRate(rateLimitingThrottle); + } + } } diff --git a/core/src/main/java/org/elasticsearch/index/store/Store.java b/core/src/main/java/org/elasticsearch/index/store/Store.java index c2b55ac0032..033fb6d18b1 100644 --- a/core/src/main/java/org/elasticsearch/index/store/Store.java +++ b/core/src/main/java/org/elasticsearch/index/store/Store.java @@ -20,31 +20,9 @@ package org.elasticsearch.index.store; import org.apache.lucene.codecs.CodecUtil; -import org.apache.lucene.index.CorruptIndexException; -import org.apache.lucene.index.IndexCommit; -import org.apache.lucene.index.IndexFileNames; -import org.apache.lucene.index.IndexFormatTooNewException; -import org.apache.lucene.index.IndexFormatTooOldException; -import org.apache.lucene.index.IndexNotFoundException; -import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.SegmentCommitInfo; -import org.apache.lucene.index.SegmentInfos; -import org.apache.lucene.store.AlreadyClosedException; -import org.apache.lucene.store.BufferedChecksum; -import org.apache.lucene.store.ByteArrayDataInput; -import org.apache.lucene.store.ChecksumIndexInput; -import org.apache.lucene.store.Directory; -import org.apache.lucene.store.FilterDirectory; -import org.apache.lucene.store.IOContext; -import org.apache.lucene.store.IndexInput; -import org.apache.lucene.store.IndexOutput; -import org.apache.lucene.store.Lock; -import org.apache.lucene.store.SimpleFSDirectory; -import org.apache.lucene.util.ArrayUtil; -import org.apache.lucene.util.BytesRef; -import org.apache.lucene.util.BytesRefBuilder; -import org.apache.lucene.util.IOUtils; -import org.apache.lucene.util.Version; +import org.apache.lucene.index.*; +import org.apache.lucene.store.*; +import org.apache.lucene.util.*; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.common.Strings; @@ -61,7 +39,6 @@ import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.lucene.store.ByteArrayIndexInput; import org.elasticsearch.common.lucene.store.InputStreamIndexInput; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.Callback; import org.elasticsearch.common.util.SingleObjectCache; @@ -69,25 +46,15 @@ import org.elasticsearch.common.util.concurrent.AbstractRefCounted; import org.elasticsearch.common.util.concurrent.RefCounted; import org.elasticsearch.common.util.iterable.Iterables; import org.elasticsearch.env.ShardLock; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.engine.Engine; -import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.shard.AbstractIndexShardComponent; import org.elasticsearch.index.shard.ShardId; -import java.io.Closeable; -import java.io.EOFException; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; import java.nio.file.NoSuchFileException; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.zip.Adler32; @@ -142,17 +109,17 @@ public class Store extends AbstractIndexShardComponent implements Closeable, Ref } }; - public Store(ShardId shardId, @IndexSettings Settings indexSettings, DirectoryService directoryService, ShardLock shardLock) throws IOException { + public Store(ShardId shardId, IndexSettings indexSettings, DirectoryService directoryService, ShardLock shardLock) throws IOException { this(shardId, indexSettings, directoryService, shardLock, OnClose.EMPTY); } @Inject - public Store(ShardId shardId, @IndexSettings Settings indexSettings, DirectoryService directoryService, ShardLock shardLock, OnClose onClose) throws IOException { + public Store(ShardId shardId, IndexSettings indexSettings, DirectoryService directoryService, ShardLock shardLock, OnClose onClose) throws IOException { super(shardId, indexSettings); - this.directory = new StoreDirectory(directoryService.newDirectory(), Loggers.getLogger("index.store.deletes", indexSettings, shardId)); + this.directory = new StoreDirectory(directoryService.newDirectory(), Loggers.getLogger("index.store.deletes", this.indexSettings, shardId)); this.shardLock = shardLock; this.onClose = onClose; - final TimeValue refreshInterval = indexSettings.getAsTime(INDEX_STORE_STATS_REFRESH_INTERVAL, TimeValue.timeValueSeconds(10)); + final TimeValue refreshInterval = this.indexSettings.getAsTime(INDEX_STORE_STATS_REFRESH_INTERVAL, TimeValue.timeValueSeconds(10)); this.statsCache = new StoreStatsCache(refreshInterval, directory, directoryService); logger.debug("store stats are refreshed with refresh_interval [{}]", refreshInterval); diff --git a/core/src/main/java/org/elasticsearch/index/suggest/stats/ShardSuggestMetric.java b/core/src/main/java/org/elasticsearch/index/suggest/stats/ShardSuggestMetric.java index 2ced4a8a058..750d7de7b22 100644 --- a/core/src/main/java/org/elasticsearch/index/suggest/stats/ShardSuggestMetric.java +++ b/core/src/main/java/org/elasticsearch/index/suggest/stats/ShardSuggestMetric.java @@ -19,13 +19,8 @@ package org.elasticsearch.index.suggest.stats; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.metrics.CounterMetric; import org.elasticsearch.common.metrics.MeanMetric; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.settings.IndexSettings; -import org.elasticsearch.index.shard.AbstractIndexShardComponent; -import org.elasticsearch.index.shard.ShardId; import java.util.concurrent.TimeUnit; diff --git a/core/src/main/java/org/elasticsearch/index/translog/TranslogConfig.java b/core/src/main/java/org/elasticsearch/index/translog/TranslogConfig.java index 30ab8144e1e..ca479bec080 100644 --- a/core/src/main/java/org/elasticsearch/index/translog/TranslogConfig.java +++ b/core/src/main/java/org/elasticsearch/index/translog/TranslogConfig.java @@ -20,11 +20,10 @@ package org.elasticsearch.index.translog; import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.BigArrays; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.translog.Translog.TranslogGeneration; import org.elasticsearch.indices.memory.IndexingMemoryController; @@ -52,7 +51,7 @@ public final class TranslogConfig { private volatile TranslogGeneration translogGeneration; private volatile Translog.Durabilty durabilty = Translog.Durabilty.REQUEST; private volatile TranslogWriter.Type type; - private final Settings indexSettings; + private final IndexSettings indexSettings; private final ShardId shardId; private final Path translogPath; @@ -65,17 +64,17 @@ public final class TranslogConfig { * @param bigArrays a bigArrays instance used for temporarily allocating write operations * @param threadPool a {@link ThreadPool} to schedule async sync durability */ - public TranslogConfig(ShardId shardId, Path translogPath, @IndexSettings Settings indexSettings, Translog.Durabilty durabilty, BigArrays bigArrays, @Nullable ThreadPool threadPool) { + public TranslogConfig(ShardId shardId, Path translogPath, IndexSettings indexSettings, Translog.Durabilty durabilty, BigArrays bigArrays, @Nullable ThreadPool threadPool) { this.indexSettings = indexSettings; this.shardId = shardId; this.translogPath = translogPath; this.durabilty = durabilty; this.threadPool = threadPool; this.bigArrays = bigArrays; - this.type = TranslogWriter.Type.fromString(indexSettings.get(INDEX_TRANSLOG_FS_TYPE, TranslogWriter.Type.BUFFERED.name())); - this.bufferSize = (int) indexSettings.getAsBytesSize(INDEX_TRANSLOG_BUFFER_SIZE, IndexingMemoryController.INACTIVE_SHARD_TRANSLOG_BUFFER).bytes(); // Not really interesting, updated by IndexingMemoryController... + this.type = TranslogWriter.Type.fromString(indexSettings.getSettings().get(INDEX_TRANSLOG_FS_TYPE, TranslogWriter.Type.BUFFERED.name())); + this.bufferSize = (int) indexSettings.getSettings().getAsBytesSize(INDEX_TRANSLOG_BUFFER_SIZE, IndexingMemoryController.INACTIVE_SHARD_TRANSLOG_BUFFER).bytes(); // Not really interesting, updated by IndexingMemoryController... - syncInterval = indexSettings.getAsTime(INDEX_TRANSLOG_SYNC_INTERVAL, TimeValue.timeValueSeconds(5)); + syncInterval = indexSettings.getSettings().getAsTime(INDEX_TRANSLOG_SYNC_INTERVAL, TimeValue.timeValueSeconds(5)); if (syncInterval.millis() > 0 && threadPool != null) { syncOnEachOperation = false; } else if (syncInterval.millis() == 0) { @@ -149,9 +148,9 @@ public final class TranslogConfig { } /** - * Returns the current index settings + * Returns the index indexSettings */ - public Settings getIndexSettings() { + public IndexSettings getIndexSettings() { return indexSettings; } diff --git a/core/src/main/java/org/elasticsearch/index/warmer/ShardIndexWarmerService.java b/core/src/main/java/org/elasticsearch/index/warmer/ShardIndexWarmerService.java index f9b33769f81..57decb25f56 100644 --- a/core/src/main/java/org/elasticsearch/index/warmer/ShardIndexWarmerService.java +++ b/core/src/main/java/org/elasticsearch/index/warmer/ShardIndexWarmerService.java @@ -19,12 +19,10 @@ package org.elasticsearch.index.warmer; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.metrics.CounterMetric; import org.elasticsearch.common.metrics.MeanMetric; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.shard.AbstractIndexShardComponent; import org.elasticsearch.index.shard.ShardId; @@ -37,7 +35,7 @@ public class ShardIndexWarmerService extends AbstractIndexShardComponent { private final CounterMetric current = new CounterMetric(); private final MeanMetric warmerMetric = new MeanMetric(); - public ShardIndexWarmerService(ShardId shardId, @IndexSettings Settings indexSettings) { + public ShardIndexWarmerService(ShardId shardId, IndexSettings indexSettings) { super(shardId, indexSettings); } diff --git a/core/src/main/java/org/elasticsearch/indices/IndicesService.java b/core/src/main/java/org/elasticsearch/indices/IndicesService.java index 818cb69352b..a9000ca1576 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndicesService.java +++ b/core/src/main/java/org/elasticsearch/indices/IndicesService.java @@ -32,12 +32,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.component.AbstractLifecycleComponent; -import org.elasticsearch.common.inject.CreationException; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.inject.Injector; -import org.elasticsearch.common.inject.Injectors; -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.common.inject.ModulesBuilder; +import org.elasticsearch.common.inject.*; import org.elasticsearch.common.io.FileSystemUtils; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; @@ -45,11 +40,7 @@ import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.env.ShardLock; import org.elasticsearch.gateway.MetaDataStateFormat; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexModule; -import org.elasticsearch.index.IndexNameModule; -import org.elasticsearch.index.IndexNotFoundException; -import org.elasticsearch.index.IndexService; +import org.elasticsearch.index.*; import org.elasticsearch.index.analysis.AnalysisModule; import org.elasticsearch.index.analysis.AnalysisService; import org.elasticsearch.index.cache.IndexCache; @@ -64,14 +55,11 @@ import org.elasticsearch.index.query.IndexQueryParserService; import org.elasticsearch.index.recovery.RecoveryStats; import org.elasticsearch.index.refresh.RefreshStats; import org.elasticsearch.index.search.stats.SearchStats; -import org.elasticsearch.index.settings.IndexSettings; -import org.elasticsearch.index.settings.IndexSettingsModule; import org.elasticsearch.index.shard.IllegalIndexShardStateException; 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.IndexStore; import org.elasticsearch.index.store.IndexStoreModule; import org.elasticsearch.indices.analysis.IndicesAnalysisService; import org.elasticsearch.indices.recovery.RecoverySettings; @@ -80,14 +68,11 @@ import org.elasticsearch.plugins.PluginsService; import java.io.Closeable; import java.io.IOException; import java.nio.file.Files; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.*; +import java.util.*; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; import java.util.stream.Stream; import static java.util.Collections.emptyMap; @@ -322,20 +307,19 @@ public class IndicesService extends AbstractLifecycleComponent i .build(); ModulesBuilder modules = new ModulesBuilder(); - modules.add(new IndexNameModule(index)); - modules.add(new IndexSettingsModule(index, indexSettings)); // plugin modules must be added here, before others or we can get crazy injection errors... for (Module pluginModule : pluginsService.indexModules(indexSettings)) { modules.add(pluginModule); } - final IndexModule indexModule = new IndexModule(settings, indexMetaData); + final IndexSettings idxSettings = new IndexSettings(index, indexSettings, Collections.EMPTY_LIST); + final IndexModule indexModule = new IndexModule(idxSettings, indexMetaData); for (IndexEventListener listener : builtInListeners) { indexModule.addIndexEventListener(listener); } indexModule.addIndexEventListener(oldShardsStats); modules.add(new IndexStoreModule(indexSettings)); modules.add(new AnalysisModule(indexSettings, indicesAnalysisService)); - modules.add(new SimilarityModule(index, indexSettings)); + modules.add(new SimilarityModule(idxSettings)); modules.add(new IndexCacheModule(indexSettings)); modules.add(indexModule); pluginsService.processModules(modules); @@ -409,13 +393,10 @@ public class IndicesService extends AbstractLifecycleComponent i logger.debug("[{}] closing index query parser service (reason [{}])", index, reason); indexInjector.getInstance(IndexQueryParserService.class).close(); - logger.debug("[{}] closing index service (reason [{}])", index, reason); - indexInjector.getInstance(IndexStore.class).close(); - logger.debug("[{}] closed... (reason [{}])", index, reason); - listener.afterIndexClosed(indexService.index(), indexService.settingsService().getSettings()); + listener.afterIndexClosed(indexService.index(), indexService.getIndexSettings().getSettings()); if (delete) { - final Settings indexSettings = indexService.getIndexSettings(); + final Settings indexSettings = indexService.getIndexSettings().getSettings(); listener.afterIndexDeleted(indexService.index(), indexSettings); // now we are done - try to wipe data on disk if possible deleteIndexStore(reason, indexService.index(), indexSettings, false); @@ -436,8 +417,7 @@ public class IndicesService extends AbstractLifecycleComponent i final RecoveryStats recoveryStats = new RecoveryStats(); @Override - public synchronized void beforeIndexShardClosed(ShardId shardId, @Nullable IndexShard indexShard, - @IndexSettings Settings indexSettings) { + public synchronized void beforeIndexShardClosed(ShardId shardId, @Nullable IndexShard indexShard, Settings indexSettings) { if (indexShard != null) { getStats.addTotals(indexShard.getStats()); indexingStats.addTotals(indexShard.indexingStats()); @@ -622,7 +602,7 @@ public class IndicesService extends AbstractLifecycleComponent i return canDeleteShardContent(shardId, indexSettings); } - private boolean canDeleteShardContent(ShardId shardId, @IndexSettings Settings indexSettings) { + private boolean canDeleteShardContent(ShardId shardId, Settings indexSettings) { final IndexServiceInjectorPair indexServiceInjectorPair = this.indices.get(shardId.getIndex()); if (IndexMetaData.isOnSharedFilesystem(indexSettings) == false) { if (indexServiceInjectorPair != null && nodeEnv.hasNodeFile()) { @@ -654,7 +634,7 @@ public class IndicesService extends AbstractLifecycleComponent i /** * Adds a pending delete for the given index shard. */ - public void addPendingDelete(ShardId shardId, @IndexSettings Settings settings) { + public void addPendingDelete(ShardId shardId, Settings settings) { if (shardId == null) { throw new IllegalArgumentException("shardId must not be null"); } @@ -668,7 +648,7 @@ public class IndicesService extends AbstractLifecycleComponent i /** * Adds a pending delete for the given index. */ - public void addPendingDelete(Index index, @IndexSettings Settings settings) { + public void addPendingDelete(Index index, Settings settings) { PendingDelete pendingDelete = new PendingDelete(index, settings); addPendingDelete(index, pendingDelete); } @@ -735,7 +715,7 @@ public class IndicesService extends AbstractLifecycleComponent i * @param index the index to process the pending deletes for * @param timeout the timeout used for processing pending deletes */ - public void processPendingDeletes(Index index, @IndexSettings Settings indexSettings, TimeValue timeout) throws IOException { + public void processPendingDeletes(Index index, Settings indexSettings, TimeValue timeout) throws IOException { logger.debug("{} processing pending deletes", index); final long startTimeNS = System.nanoTime(); final List shardLocks = nodeEnv.lockAllForIndex(index, indexSettings, timeout.millis()); 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 c0f821fbca0..42004c91dc1 100644 --- a/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java +++ b/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java @@ -47,7 +47,6 @@ import org.elasticsearch.index.IndexService; import org.elasticsearch.index.IndexShardAlreadyExistsException; import org.elasticsearch.index.mapper.DocumentMapper; import org.elasticsearch.index.mapper.MapperService; -import org.elasticsearch.index.settings.IndexSettingsService; import org.elasticsearch.index.shard.*; import org.elasticsearch.index.snapshots.IndexShardRepository; import org.elasticsearch.indices.IndicesService; @@ -172,7 +171,6 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent imp } @Override - public void afterIndexClosed(Index index, @IndexSettings Settings indexSettings) { + public void afterIndexClosed(Index index, Settings indexSettings) { // once an index is closed we can just clean up all the pending search context information // to release memory and let references to the filesystem go etc. IndexMetaData idxMeta = SearchService.this.clusterService.state().metaData().index(index.getName()); @@ -230,7 +215,7 @@ public class SearchService extends AbstractLifecycleComponent imp } @Override - public void afterIndexDeleted(Index index, @IndexSettings Settings indexSettings) { + public void afterIndexDeleted(Index index, Settings indexSettings) { freeAllContextForIndex(index); } diff --git a/core/src/main/java/org/elasticsearch/search/internal/DefaultSearchContext.java b/core/src/main/java/org/elasticsearch/search/internal/DefaultSearchContext.java index 64d765985cb..1f6f05fea5e 100644 --- a/core/src/main/java/org/elasticsearch/search/internal/DefaultSearchContext.java +++ b/core/src/main/java/org/elasticsearch/search/internal/DefaultSearchContext.java @@ -181,7 +181,7 @@ public class DefaultSearchContext extends SearchContext { long resultWindow = from + size; // We need settingsService's view of the settings because its dynamic. // indexService's isn't. - int maxResultWindow = indexService.settingsService().getSettings().getAsInt(MAX_RESULT_WINDOW, Defaults.MAX_RESULT_WINDOW); + int maxResultWindow = indexService.getIndexSettings().getSettings().getAsInt(MAX_RESULT_WINDOW, Defaults.MAX_RESULT_WINDOW); if (resultWindow > maxResultWindow) { throw new QueryPhaseExecutionException(this, diff --git a/core/src/test/java/org/elasticsearch/index/IndexModuleTests.java b/core/src/test/java/org/elasticsearch/index/IndexModuleTests.java index 2c3e2105478..4166e80eb0e 100644 --- a/core/src/test/java/org/elasticsearch/index/IndexModuleTests.java +++ b/core/src/test/java/org/elasticsearch/index/IndexModuleTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.index; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.search.IndexSearcher; +import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.inject.ModuleTestCase; import org.elasticsearch.common.settings.Settings; @@ -31,22 +32,27 @@ import org.elasticsearch.index.shard.IndexEventListener; import org.elasticsearch.index.shard.IndexSearcherWrapper; import org.elasticsearch.test.engine.MockEngineFactory; -import java.util.Arrays; import java.util.Collections; -import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Consumer; public class IndexModuleTests extends ModuleTestCase { public void testWrapperIsBound() { - IndexModule module = new IndexModule(Settings.EMPTY, IndexMetaData.PROTO); + final Index index = new Index("foo"); + final Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); + IndexSettings indexSettings = new IndexSettings(index, settings, Collections.EMPTY_LIST); + IndexModule module = new IndexModule(indexSettings, IndexMetaData.PROTO); assertInstanceBinding(module, IndexSearcherWrapper.class,(x) -> x == null); module.indexSearcherWrapper = Wrapper.class; assertBinding(module, IndexSearcherWrapper.class, Wrapper.class); } public void testEngineFactoryBound() { - IndexModule module = new IndexModule(Settings.EMPTY,IndexMetaData.PROTO); + final Index index = new Index("foo"); + final Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); + IndexSettings indexSettings = new IndexSettings(index, settings, Collections.EMPTY_LIST); + IndexModule module = new IndexModule(indexSettings, IndexMetaData.PROTO); assertBinding(module, EngineFactory.class, InternalEngineFactory.class); module.engineFactoryImpl = MockEngineFactory.class; assertBinding(module, EngineFactory.class, MockEngineFactory.class); @@ -54,19 +60,57 @@ public class IndexModuleTests extends ModuleTestCase { public void testOtherServiceBound() { final AtomicBoolean atomicBoolean = new AtomicBoolean(false); - final IndexEventListener listener = new IndexEventListener() { + final IndexEventListener eventListener = new IndexEventListener() { @Override public void beforeIndexDeleted(IndexService indexService) { atomicBoolean.set(true); } }; final IndexMetaData meta = IndexMetaData.builder(IndexMetaData.PROTO).index("foo").build(); - IndexModule module = new IndexModule(Settings.EMPTY,meta); - module.addIndexEventListener(listener); + final Index index = new Index("foo"); + final Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); + IndexSettings indexSettings = new IndexSettings(index, settings, Collections.EMPTY_LIST); + IndexModule module = new IndexModule(indexSettings, meta); + Consumer listener = (s) -> {}; + module.addIndexSettingsListener(listener); + module.addIndexEventListener(eventListener); assertBinding(module, IndexService.class, IndexService.class); assertBinding(module, IndexServicesProvider.class, IndexServicesProvider.class); assertInstanceBinding(module, IndexMetaData.class, (x) -> x == meta); assertInstanceBinding(module, IndexEventListener.class, (x) -> {x.beforeIndexDeleted(null); return atomicBoolean.get();}); + assertInstanceBinding(module, IndexSettings.class, (x) -> x.getSettings() == indexSettings.getSettings()); + assertInstanceBinding(module, IndexSettings.class, (x) -> x.getIndex() == indexSettings.getIndex()); + assertInstanceBinding(module, IndexSettings.class, (x) -> x.getUpdateListeners().get(0) == listener); + } + + + public void testListener() { + final IndexMetaData meta = IndexMetaData.builder(IndexMetaData.PROTO).index("foo").build(); + final Index index = new Index("foo"); + final Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); + IndexSettings indexSettings = new IndexSettings(index, settings, Collections.EMPTY_LIST); + IndexModule module = new IndexModule(indexSettings, meta); + Consumer listener = (s) -> { + }; + module.addIndexSettingsListener(listener); + + try { + module.addIndexSettingsListener(listener); + fail("already added"); + } catch (IllegalStateException ex) { + + } + + try { + module.addIndexSettingsListener(null); + fail("must not be null"); + } catch (IllegalArgumentException ex) { + + } + assertInstanceBinding(module, IndexSettings.class, (x) -> x.getUpdateListeners().size() == 1); + assertInstanceBinding(module, IndexSettings.class, (x) -> x.getUpdateListeners().get(0) == listener); + + } public static final class Wrapper extends IndexSearcherWrapper { diff --git a/core/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java b/core/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java index 03986188c6c..9e5f847fa1e 100644 --- a/core/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java +++ b/core/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java @@ -37,11 +37,10 @@ import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.env.Environment; import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexNameModule; import org.elasticsearch.index.analysis.filter1.MyFilterTokenFilterFactory; -import org.elasticsearch.index.settings.IndexSettingsModule; import org.elasticsearch.indices.analysis.IndicesAnalysisService; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.IndexNameAndSettingsModule; import org.elasticsearch.test.VersionUtils; import org.hamcrest.MatcherAssert; @@ -69,8 +68,7 @@ public class AnalysisModuleTests extends ESTestCase { AnalysisModule analysisModule = new AnalysisModule(settings, parentInjector.getInstance(IndicesAnalysisService.class)); analysisModule.addTokenFilter("myfilter", MyFilterTokenFilterFactory.class); injector = new ModulesBuilder().add( - new IndexSettingsModule(index, settings), - new IndexNameModule(index), + new IndexNameAndSettingsModule(index, settings), analysisModule) .createChildInjector(parentInjector); diff --git a/core/src/test/java/org/elasticsearch/index/analysis/AnalysisServiceTests.java b/core/src/test/java/org/elasticsearch/index/analysis/AnalysisServiceTests.java index cd3a8c643ca..20f4733faa3 100644 --- a/core/src/test/java/org/elasticsearch/index/analysis/AnalysisServiceTests.java +++ b/core/src/test/java/org/elasticsearch/index/analysis/AnalysisServiceTests.java @@ -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.IndexSettings; import org.elasticsearch.indices.analysis.IndicesAnalysisService; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.VersionUtils; @@ -50,7 +51,7 @@ public class AnalysisServiceTests extends ESTestCase { Version version = VersionUtils.randomVersion(getRandom()); Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); IndicesAnalysisService indicesAnalysisService = new IndicesAnalysisService(settings); - AnalysisService analysisService = new AnalysisService(new Index("index"), settings, indicesAnalysisService, + AnalysisService analysisService = new AnalysisService(new IndexSettings(new Index("index"), settings, Collections.EMPTY_LIST), indicesAnalysisService, Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap()); assertThat(analysisService.defaultIndexAnalyzer().analyzer(), instanceOf(StandardAnalyzer.class)); assertThat(analysisService.defaultSearchAnalyzer().analyzer(), instanceOf(StandardAnalyzer.class)); @@ -61,7 +62,7 @@ public class AnalysisServiceTests extends ESTestCase { Version version = VersionUtils.randomVersion(getRandom()); Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); IndicesAnalysisService indicesAnalysisService = new IndicesAnalysisService(settings); - AnalysisService analysisService = new AnalysisService(new Index("index"), settings, indicesAnalysisService, + AnalysisService analysisService = new AnalysisService(new IndexSettings(new Index("index"), settings, Collections.EMPTY_LIST), indicesAnalysisService, Collections.singletonMap("default", analyzerProvider("default")), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap()); assertThat(analysisService.defaultIndexAnalyzer().analyzer(), instanceOf(EnglishAnalyzer.class)); @@ -74,7 +75,7 @@ public class AnalysisServiceTests extends ESTestCase { Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); IndicesAnalysisService indicesAnalysisService = new IndicesAnalysisService(settings); try { - AnalysisService analysisService = new AnalysisService(new Index("index"), settings, indicesAnalysisService, + AnalysisService analysisService = new AnalysisService(new IndexSettings(new Index("index"), settings, Collections.EMPTY_LIST), indicesAnalysisService, Collections.singletonMap("default_index", new PreBuiltAnalyzerProviderFactory("default_index", AnalyzerScope.INDEX, new EnglishAnalyzer())), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap()); fail("Expected ISE"); @@ -88,7 +89,7 @@ public class AnalysisServiceTests extends ESTestCase { Version version = VersionUtils.randomVersionBetween(getRandom(), VersionUtils.getFirstVersion(), VersionUtils.getPreviousVersion(Version.V_3_0_0)); Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); IndicesAnalysisService indicesAnalysisService = new IndicesAnalysisService(settings); - AnalysisService analysisService = new AnalysisService(new Index("index"), settings, indicesAnalysisService, + AnalysisService analysisService = new AnalysisService(new IndexSettings(new Index("index"), settings, Collections.EMPTY_LIST), indicesAnalysisService, Collections.singletonMap("default_index", analyzerProvider("default_index")), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap()); assertThat(analysisService.defaultIndexAnalyzer().analyzer(), instanceOf(EnglishAnalyzer.class)); @@ -100,7 +101,7 @@ public class AnalysisServiceTests extends ESTestCase { Version version = VersionUtils.randomVersion(getRandom()); Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); IndicesAnalysisService indicesAnalysisService = new IndicesAnalysisService(settings); - AnalysisService analysisService = new AnalysisService(new Index("index"), settings, indicesAnalysisService, + AnalysisService analysisService = new AnalysisService(new IndexSettings(new Index("index"), settings, Collections.EMPTY_LIST), indicesAnalysisService, Collections.singletonMap("default_search", analyzerProvider("default_search")), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap()); assertThat(analysisService.defaultIndexAnalyzer().analyzer(), instanceOf(StandardAnalyzer.class)); @@ -115,7 +116,7 @@ public class AnalysisServiceTests extends ESTestCase { Map analyzers = new HashMap<>(); analyzers.put("default_index", analyzerProvider("default_index")); analyzers.put("default_search", analyzerProvider("default_search")); - AnalysisService analysisService = new AnalysisService(new Index("index"), settings, indicesAnalysisService, + AnalysisService analysisService = new AnalysisService(new IndexSettings(new Index("index"), settings, Collections.EMPTY_LIST), indicesAnalysisService, analyzers, Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap()); assertThat(analysisService.defaultIndexAnalyzer().analyzer(), instanceOf(EnglishAnalyzer.class)); assertThat(analysisService.defaultSearchAnalyzer().analyzer(), instanceOf(EnglishAnalyzer.class)); diff --git a/core/src/test/java/org/elasticsearch/index/analysis/AnalysisTestsHelper.java b/core/src/test/java/org/elasticsearch/index/analysis/AnalysisTestsHelper.java index 74102fc014d..67367ac11aa 100644 --- a/core/src/test/java/org/elasticsearch/index/analysis/AnalysisTestsHelper.java +++ b/core/src/test/java/org/elasticsearch/index/analysis/AnalysisTestsHelper.java @@ -28,10 +28,9 @@ import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.env.Environment; import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexNameModule; -import org.elasticsearch.index.settings.IndexSettingsModule; import org.elasticsearch.indices.IndicesModule; import org.elasticsearch.indices.analysis.IndicesAnalysisService; +import org.elasticsearch.test.IndexNameAndSettingsModule; import java.nio.file.Path; @@ -65,8 +64,8 @@ public class AnalysisTestsHelper { AnalysisModule analysisModule = new AnalysisModule(settings, parentInjector.getInstance(IndicesAnalysisService.class)); - Injector injector = new ModulesBuilder().add(new IndexSettingsModule(index, settings), - new IndexNameModule(index), analysisModule).createChildInjector(parentInjector); + Injector injector = new ModulesBuilder().add(new IndexNameAndSettingsModule(index, settings), + analysisModule).createChildInjector(parentInjector); return injector.getInstance(AnalysisService.class); } diff --git a/core/src/test/java/org/elasticsearch/index/analysis/CharFilterTests.java b/core/src/test/java/org/elasticsearch/index/analysis/CharFilterTests.java index 9f3544e6846..f15d2fe4683 100644 --- a/core/src/test/java/org/elasticsearch/index/analysis/CharFilterTests.java +++ b/core/src/test/java/org/elasticsearch/index/analysis/CharFilterTests.java @@ -27,10 +27,9 @@ import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.env.Environment; import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexNameModule; -import org.elasticsearch.index.settings.IndexSettingsModule; import org.elasticsearch.indices.analysis.IndicesAnalysisService; import org.elasticsearch.test.ESTokenStreamTestCase; +import org.elasticsearch.test.IndexNameAndSettingsModule; import static org.elasticsearch.common.settings.Settings.settingsBuilder; @@ -49,8 +48,7 @@ public class CharFilterTests extends ESTokenStreamTestCase { .build(); Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings))).createInjector(); Injector injector = new ModulesBuilder().add( - new IndexSettingsModule(index, settings), - new IndexNameModule(index), + new IndexNameAndSettingsModule(index, settings), new AnalysisModule(settings, parentInjector.getInstance(IndicesAnalysisService.class))) .createChildInjector(parentInjector); @@ -74,8 +72,7 @@ public class CharFilterTests extends ESTokenStreamTestCase { .build(); Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings))).createInjector(); Injector injector = new ModulesBuilder().add( - new IndexSettingsModule(index, settings), - new IndexNameModule(index), + new IndexNameAndSettingsModule(index, settings), new AnalysisModule(settings, parentInjector.getInstance(IndicesAnalysisService.class))) .createChildInjector(parentInjector); diff --git a/core/src/test/java/org/elasticsearch/index/analysis/CompoundAnalysisTests.java b/core/src/test/java/org/elasticsearch/index/analysis/CompoundAnalysisTests.java index 523760c797b..0a968a12410 100644 --- a/core/src/test/java/org/elasticsearch/index/analysis/CompoundAnalysisTests.java +++ b/core/src/test/java/org/elasticsearch/index/analysis/CompoundAnalysisTests.java @@ -33,12 +33,11 @@ import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.env.Environment; import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexNameModule; import org.elasticsearch.index.analysis.compound.DictionaryCompoundWordTokenFilterFactory; import org.elasticsearch.index.analysis.filter1.MyFilterTokenFilterFactory; -import org.elasticsearch.index.settings.IndexSettingsModule; import org.elasticsearch.indices.analysis.IndicesAnalysisService; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.IndexNameAndSettingsModule; import org.hamcrest.MatcherAssert; import java.io.IOException; @@ -60,8 +59,7 @@ public class CompoundAnalysisTests extends ESTestCase { AnalysisModule analysisModule = new AnalysisModule(settings, parentInjector.getInstance(IndicesAnalysisService.class)); analysisModule.addTokenFilter("myfilter", MyFilterTokenFilterFactory.class); Injector injector = new ModulesBuilder().add( - new IndexSettingsModule(index, settings), - new IndexNameModule(index), + new IndexNameAndSettingsModule(index, settings), analysisModule) .createChildInjector(parentInjector); @@ -86,8 +84,7 @@ public class CompoundAnalysisTests extends ESTestCase { AnalysisModule analysisModule = new AnalysisModule(settings, parentInjector.getInstance(IndicesAnalysisService.class)); analysisModule.addTokenFilter("myfilter", MyFilterTokenFilterFactory.class); Injector injector = new ModulesBuilder().add( - new IndexSettingsModule(index, settings), - new IndexNameModule(index), + new IndexNameAndSettingsModule(index, settings), analysisModule) .createChildInjector(parentInjector); diff --git a/core/src/test/java/org/elasticsearch/index/analysis/NGramTokenizerFactoryTests.java b/core/src/test/java/org/elasticsearch/index/analysis/NGramTokenizerFactoryTests.java index 1fddd12b238..dd588f1fae9 100644 --- a/core/src/test/java/org/elasticsearch/index/analysis/NGramTokenizerFactoryTests.java +++ b/core/src/test/java/org/elasticsearch/index/analysis/NGramTokenizerFactoryTests.java @@ -34,16 +34,14 @@ import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings.Builder; import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.test.ESTokenStreamTestCase; import java.io.IOException; import java.io.StringReader; import java.lang.reflect.Field; import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Random; +import java.util.*; import static com.carrotsearch.randomizedtesting.RandomizedTest.scaledRandomIntBetween; import static org.hamcrest.Matchers.instanceOf; @@ -53,10 +51,11 @@ public class NGramTokenizerFactoryTests extends ESTokenStreamTestCase { final Index index = new Index("test"); final String name = "ngr"; final Settings indexSettings = newAnalysisSettingsBuilder().build(); + IndexSettings indexProperties = new IndexSettings(index, indexSettings, Collections.EMPTY_LIST); for (String tokenChars : Arrays.asList("letters", "number", "DIRECTIONALITY_UNDEFINED")) { final Settings settings = newAnalysisSettingsBuilder().put("min_gram", 2).put("max_gram", 3).put("token_chars", tokenChars).build(); try { - new NGramTokenizerFactory(index, indexSettings, name, settings).create(); + new NGramTokenizerFactory(indexProperties, name, settings).create(); fail(); } catch (IllegalArgumentException expected) { // OK @@ -64,7 +63,9 @@ public class NGramTokenizerFactoryTests extends ESTokenStreamTestCase { } for (String tokenChars : Arrays.asList("letter", " digit ", "punctuation", "DIGIT", "CoNtRoL", "dash_punctuation")) { final Settings settings = newAnalysisSettingsBuilder().put("min_gram", 2).put("max_gram", 3).put("token_chars", tokenChars).build(); - new NGramTokenizerFactory(index, indexSettings, name, settings).create(); + indexProperties = new IndexSettings(index, indexSettings, Collections.EMPTY_LIST); + + new NGramTokenizerFactory(indexProperties, name, settings).create(); // no exception } } @@ -74,7 +75,7 @@ public class NGramTokenizerFactoryTests extends ESTokenStreamTestCase { final String name = "ngr"; final Settings indexSettings = newAnalysisSettingsBuilder().build(); final Settings settings = newAnalysisSettingsBuilder().put("min_gram", 2).put("max_gram", 4).putArray("token_chars", new String[0]).build(); - Tokenizer tokenizer = new NGramTokenizerFactory(index, indexSettings, name, settings).create(); + Tokenizer tokenizer = new NGramTokenizerFactory(new IndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(); tokenizer.setReader(new StringReader("1.34")); assertTokenStreamContents(tokenizer, new String[] {"1.", "1.3", "1.34", ".3", ".34", "34"}); } @@ -85,12 +86,12 @@ public class NGramTokenizerFactoryTests extends ESTokenStreamTestCase { final String name = "ngr"; final Settings indexSettings = newAnalysisSettingsBuilder().build(); Settings settings = newAnalysisSettingsBuilder().put("min_gram", 2).put("max_gram", 3).put("token_chars", "letter,digit").build(); - Tokenizer tokenizer = new NGramTokenizerFactory(index, indexSettings, name, settings).create(); + Tokenizer tokenizer = new NGramTokenizerFactory(new IndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(); tokenizer.setReader(new StringReader("Åbc déf g\uD801\uDC00f ")); assertTokenStreamContents(tokenizer, new String[] {"Åb", "Åbc", "bc", "dé", "déf", "éf", "g\uD801\uDC00", "g\uD801\uDC00f", "\uD801\uDC00f"}); settings = newAnalysisSettingsBuilder().put("min_gram", 2).put("max_gram", 3).put("token_chars", "letter,digit,punctuation,whitespace,symbol").build(); - tokenizer = new NGramTokenizerFactory(index, indexSettings, name, settings).create(); + tokenizer = new NGramTokenizerFactory(new IndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(); tokenizer.setReader(new StringReader(" a!$ 9")); assertTokenStreamContents(tokenizer, new String[] {" a", " a!", "a!", "a!$", "!$", "!$ ", "$ ", "$ 9", " 9"}); @@ -102,12 +103,12 @@ public class NGramTokenizerFactoryTests extends ESTokenStreamTestCase { final String name = "ngr"; final Settings indexSettings = newAnalysisSettingsBuilder().build(); Settings settings = newAnalysisSettingsBuilder().put("min_gram", 2).put("max_gram", 3).put("token_chars", "letter,digit").build(); - Tokenizer tokenizer = new EdgeNGramTokenizerFactory(index, indexSettings, name, settings).create(); + Tokenizer tokenizer = new EdgeNGramTokenizerFactory(new IndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(); tokenizer.setReader(new StringReader("Åbc déf g\uD801\uDC00f ")); assertTokenStreamContents(tokenizer, new String[] {"Åb", "Åbc", "dé", "déf", "g\uD801\uDC00", "g\uD801\uDC00f"}); settings = newAnalysisSettingsBuilder().put("min_gram", 2).put("max_gram", 3).put("token_chars", "letter,digit,punctuation,whitespace,symbol").build(); - tokenizer = new EdgeNGramTokenizerFactory(index, indexSettings, name, settings).create(); + tokenizer = new EdgeNGramTokenizerFactory(new IndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(); tokenizer.setReader(new StringReader(" a!$ 9")); assertTokenStreamContents(tokenizer, new String[] {" a", " a!"}); @@ -128,7 +129,7 @@ public class NGramTokenizerFactoryTests extends ESTokenStreamTestCase { } Settings settings = builder.build(); Settings indexSettings = newAnalysisSettingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, v.id).build(); - Tokenizer edgeNGramTokenizer = new EdgeNGramTokenizerFactory(index, indexSettings, name, settings).create(); + Tokenizer edgeNGramTokenizer = new EdgeNGramTokenizerFactory(new IndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(); edgeNGramTokenizer.setReader(new StringReader("foo bar")); if (compatVersion) { assertThat(edgeNGramTokenizer, instanceOf(Lucene43EdgeNGramTokenizer.class)); @@ -139,7 +140,7 @@ public class NGramTokenizerFactoryTests extends ESTokenStreamTestCase { } else { Settings settings = newAnalysisSettingsBuilder().put("min_gram", 2).put("max_gram", 3).put("side", "back").build(); Settings indexSettings = newAnalysisSettingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, v.id).build(); - Tokenizer edgeNGramTokenizer = new EdgeNGramTokenizerFactory(index, indexSettings, name, settings).create(); + Tokenizer edgeNGramTokenizer = new EdgeNGramTokenizerFactory(new IndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(); edgeNGramTokenizer.setReader(new StringReader("foo bar")); assertThat(edgeNGramTokenizer, instanceOf(Lucene43EdgeNGramTokenizer.class)); } @@ -147,7 +148,7 @@ public class NGramTokenizerFactoryTests extends ESTokenStreamTestCase { Settings settings = newAnalysisSettingsBuilder().put("min_gram", 2).put("max_gram", 3).put("side", "back").build(); Settings indexSettings = newAnalysisSettingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); try { - new EdgeNGramTokenizerFactory(index, indexSettings, name, settings).create(); + new EdgeNGramTokenizerFactory(new IndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(); fail("should fail side:back is not supported anymore"); } catch (IllegalArgumentException ex) { } @@ -168,7 +169,7 @@ public class NGramTokenizerFactoryTests extends ESTokenStreamTestCase { } Settings settings = builder.build(); Settings indexSettings = newAnalysisSettingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, v.id).build(); - Tokenizer nGramTokenizer = new NGramTokenizerFactory(index, indexSettings, name, settings).create(); + Tokenizer nGramTokenizer = new NGramTokenizerFactory(new IndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(); nGramTokenizer.setReader(new StringReader("foo bar")); if (compatVersion) { assertThat(nGramTokenizer, instanceOf(Lucene43NGramTokenizer.class)); @@ -179,7 +180,7 @@ public class NGramTokenizerFactoryTests extends ESTokenStreamTestCase { } else { Settings settings = newAnalysisSettingsBuilder().put("min_gram", 2).put("max_gram", 3).build(); Settings indexSettings = newAnalysisSettingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, v.id).build(); - Tokenizer nGramTokenizer = new NGramTokenizerFactory(index, indexSettings, name, settings).create(); + Tokenizer nGramTokenizer = new NGramTokenizerFactory(new IndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(); nGramTokenizer.setReader(new StringReader("foo bar")); assertThat(nGramTokenizer, instanceOf(Lucene43NGramTokenizer.class)); } @@ -206,7 +207,7 @@ public class NGramTokenizerFactoryTests extends ESTokenStreamTestCase { Settings indexSettings = newAnalysisSettingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, v.id).build(); Tokenizer tokenizer = new MockTokenizer(); tokenizer.setReader(new StringReader("foo bar")); - TokenStream edgeNGramTokenFilter = new EdgeNGramTokenFilterFactory(index, indexSettings, name, settings).create(tokenizer); + TokenStream edgeNGramTokenFilter = new EdgeNGramTokenFilterFactory(new IndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(tokenizer); if (reverse) { assertThat(edgeNGramTokenFilter, instanceOf(ReverseStringFilter.class)); } else if (compatVersion) { @@ -225,7 +226,7 @@ public class NGramTokenizerFactoryTests extends ESTokenStreamTestCase { Settings indexSettings = newAnalysisSettingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, v.id).build(); Tokenizer tokenizer = new MockTokenizer(); tokenizer.setReader(new StringReader("foo bar")); - TokenStream edgeNGramTokenFilter = new EdgeNGramTokenFilterFactory(index, indexSettings, name, settings).create(tokenizer); + TokenStream edgeNGramTokenFilter = new EdgeNGramTokenFilterFactory(new IndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(tokenizer); if (reverse) { assertThat(edgeNGramTokenFilter, instanceOf(ReverseStringFilter.class)); } else { diff --git a/core/src/test/java/org/elasticsearch/index/analysis/PatternCaptureTokenFilterTests.java b/core/src/test/java/org/elasticsearch/index/analysis/PatternCaptureTokenFilterTests.java index 880d2229000..12984741c6b 100644 --- a/core/src/test/java/org/elasticsearch/index/analysis/PatternCaptureTokenFilterTests.java +++ b/core/src/test/java/org/elasticsearch/index/analysis/PatternCaptureTokenFilterTests.java @@ -28,10 +28,12 @@ import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.env.Environment; import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexNameModule; -import org.elasticsearch.index.settings.IndexSettingsModule; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.indices.analysis.IndicesAnalysisService; import org.elasticsearch.test.ESTokenStreamTestCase; +import org.elasticsearch.test.IndexNameAndSettingsModule; + +import java.util.Collections; import static org.elasticsearch.common.settings.Settings.settingsBuilder; import static org.hamcrest.Matchers.containsString; @@ -47,8 +49,7 @@ public class PatternCaptureTokenFilterTests extends ESTokenStreamTestCase { .build(); Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings))).createInjector(); Injector injector = new ModulesBuilder().add( - new IndexSettingsModule(index, settings), - new IndexNameModule(index), + new IndexNameAndSettingsModule(index, settings), new AnalysisModule(settings, parentInjector.getInstance(IndicesAnalysisService.class))) .createChildInjector(parentInjector); @@ -69,7 +70,7 @@ public class PatternCaptureTokenFilterTests extends ESTokenStreamTestCase { public void testNoPatterns() { try { - new PatternCaptureGroupTokenFilterFactory(new Index("test"), settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(), "pattern_capture", settingsBuilder().put("pattern", "foobar").build()); + new PatternCaptureGroupTokenFilterFactory(new IndexSettings(new Index("test"), settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(), Collections.EMPTY_LIST), "pattern_capture", settingsBuilder().put("pattern", "foobar").build()); fail ("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), containsString("required setting 'patterns' is missing")); diff --git a/core/src/test/java/org/elasticsearch/index/analysis/StopAnalyzerTests.java b/core/src/test/java/org/elasticsearch/index/analysis/StopAnalyzerTests.java index c48d723260d..1e48756d179 100644 --- a/core/src/test/java/org/elasticsearch/index/analysis/StopAnalyzerTests.java +++ b/core/src/test/java/org/elasticsearch/index/analysis/StopAnalyzerTests.java @@ -28,10 +28,9 @@ import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.env.Environment; import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexNameModule; -import org.elasticsearch.index.settings.IndexSettingsModule; import org.elasticsearch.indices.analysis.IndicesAnalysisService; import org.elasticsearch.test.ESTokenStreamTestCase; +import org.elasticsearch.test.IndexNameAndSettingsModule; import static org.elasticsearch.common.settings.Settings.settingsBuilder; @@ -46,8 +45,7 @@ public class StopAnalyzerTests extends ESTokenStreamTestCase { .build(); Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings))).createInjector(); Injector injector = new ModulesBuilder().add( - new IndexSettingsModule(index, settings), - new IndexNameModule(index), + new IndexNameAndSettingsModule(index, settings), new AnalysisModule(settings, parentInjector.getInstance(IndicesAnalysisService.class))) .createChildInjector(parentInjector); diff --git a/core/src/test/java/org/elasticsearch/index/analysis/filter1/MyFilterTokenFilterFactory.java b/core/src/test/java/org/elasticsearch/index/analysis/filter1/MyFilterTokenFilterFactory.java index 47bf1bb8101..60256a5a955 100644 --- a/core/src/test/java/org/elasticsearch/index/analysis/filter1/MyFilterTokenFilterFactory.java +++ b/core/src/test/java/org/elasticsearch/index/analysis/filter1/MyFilterTokenFilterFactory.java @@ -23,15 +23,14 @@ import org.apache.lucene.analysis.core.StopAnalyzer; import org.apache.lucene.analysis.core.StopFilter; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.analysis.AbstractTokenFilterFactory; -import org.elasticsearch.index.settings.IndexSettings; public class MyFilterTokenFilterFactory extends AbstractTokenFilterFactory { @Inject - public MyFilterTokenFilterFactory(Index index, @IndexSettings Settings indexSettings, String name) { - super(index, indexSettings, name, Settings.Builder.EMPTY_SETTINGS); + public MyFilterTokenFilterFactory(IndexSettings indexSettings, String name) { + super(indexSettings, name, Settings.Builder.EMPTY_SETTINGS); } @Override diff --git a/core/src/test/java/org/elasticsearch/index/analysis/synonyms/SynonymsAnalysisTests.java b/core/src/test/java/org/elasticsearch/index/analysis/synonyms/SynonymsAnalysisTests.java index 65c2fa21648..23c77390f30 100644 --- a/core/src/test/java/org/elasticsearch/index/analysis/synonyms/SynonymsAnalysisTests.java +++ b/core/src/test/java/org/elasticsearch/index/analysis/synonyms/SynonymsAnalysisTests.java @@ -35,12 +35,11 @@ import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.env.Environment; import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexNameModule; import org.elasticsearch.index.analysis.AnalysisModule; import org.elasticsearch.index.analysis.AnalysisService; -import org.elasticsearch.index.settings.IndexSettingsModule; import org.elasticsearch.indices.analysis.IndicesAnalysisService; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.IndexNameAndSettingsModule; import org.hamcrest.MatcherAssert; import java.io.IOException; @@ -79,8 +78,7 @@ public class SynonymsAnalysisTests extends ESTestCase { new EnvironmentModule(new Environment(settings))) .createInjector(); Injector injector = new ModulesBuilder().add( - new IndexSettingsModule(index, settings), - new IndexNameModule(index), + new IndexNameAndSettingsModule(index, settings), new AnalysisModule(settings, parentInjector.getInstance(IndicesAnalysisService.class))) .createChildInjector(parentInjector); diff --git a/core/src/test/java/org/elasticsearch/index/cache/bitset/BitSetFilterCacheTests.java b/core/src/test/java/org/elasticsearch/index/cache/bitset/BitSetFilterCacheTests.java index 4c93ecada03..f658bbe6a14 100644 --- a/core/src/test/java/org/elasticsearch/index/cache/bitset/BitSetFilterCacheTests.java +++ b/core/src/test/java/org/elasticsearch/index/cache/bitset/BitSetFilterCacheTests.java @@ -37,19 +37,25 @@ import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.util.Accountable; import org.apache.lucene.util.BitSet; import org.apache.lucene.util.IOUtils; +import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.lucene.index.ElasticsearchDirectoryReader; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.test.ESTestCase; import java.io.IOException; +import java.util.Collections; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; import static org.hamcrest.Matchers.equalTo; public class BitSetFilterCacheTests extends ESTestCase { + + private static final IndexSettings INDEX_SETTINGS = new IndexSettings(new Index("test"), Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, org.elasticsearch.Version.CURRENT).build(), Collections.emptyList()); + private static int matchCount(BitSetProducer producer, IndexReader reader) throws IOException { int count = 0; for (LeafReaderContext ctx : reader.leaves()) { @@ -84,7 +90,7 @@ public class BitSetFilterCacheTests extends ESTestCase { IndexReader reader = DirectoryReader.open(writer, false); IndexSearcher searcher = new IndexSearcher(reader); - BitsetFilterCache cache = new BitsetFilterCache(new Index("test"), Settings.EMPTY); + BitsetFilterCache cache = new BitsetFilterCache(INDEX_SETTINGS); BitSetProducer filter = cache.getBitSetProducer(new TermQuery(new Term("field", "value"))); assertThat(matchCount(filter, reader), equalTo(3)); @@ -127,7 +133,7 @@ public class BitSetFilterCacheTests extends ESTestCase { final AtomicInteger onCacheCalls = new AtomicInteger(); final AtomicInteger onRemoveCalls = new AtomicInteger(); - final BitsetFilterCache cache = new BitsetFilterCache(new Index("test"), Settings.EMPTY); + final BitsetFilterCache cache = new BitsetFilterCache(INDEX_SETTINGS); cache.setListener(new BitsetFilterCache.Listener() { @Override public void onCache(ShardId shardId, Accountable accountable) { @@ -166,7 +172,7 @@ public class BitSetFilterCacheTests extends ESTestCase { } public void testSetListenerTwice() { - final BitsetFilterCache cache = new BitsetFilterCache(new Index("test"), Settings.EMPTY); + final BitsetFilterCache cache = new BitsetFilterCache(INDEX_SETTINGS); cache.setListener(new BitsetFilterCache.Listener() { @Override 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 68c18ace1d5..dbb54e9c26b 100644 --- a/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java +++ b/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java @@ -64,6 +64,7 @@ import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.VersionType; import org.elasticsearch.index.analysis.AnalysisService; import org.elasticsearch.index.codec.CodecService; @@ -121,7 +122,6 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import static java.util.Collections.emptyMap; -import static org.elasticsearch.common.settings.Settings.Builder.EMPTY_SETTINGS; import static org.elasticsearch.index.engine.Engine.Operation.Origin.PRIMARY; import static org.elasticsearch.index.engine.Engine.Operation.Origin.REPLICA; import static org.hamcrest.Matchers.equalTo; @@ -134,6 +134,7 @@ import static org.hamcrest.Matchers.nullValue; public class InternalEngineTests extends ESTestCase { protected final ShardId shardId = new ShardId(new Index("index"), 1); + private static final IndexSettings INDEX_SETTINGS = new IndexSettings(new Index("index"), Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, org.elasticsearch.Version.CURRENT).build(), Collections.emptyList()); protected ThreadPool threadPool; @@ -153,7 +154,7 @@ public class InternalEngineTests extends ESTestCase { public void setUp() throws Exception { super.setUp(); - CodecService codecService = new CodecService(shardId.index()); + CodecService codecService = new CodecService(INDEX_SETTINGS, null); 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 @@ -228,7 +229,7 @@ public class InternalEngineTests extends ESTestCase { } protected Store createStore(final Directory directory) throws IOException { - final DirectoryService directoryService = new DirectoryService(shardId, EMPTY_SETTINGS) { + final DirectoryService directoryService = new DirectoryService(shardId, INDEX_SETTINGS) { @Override public Directory newDirectory() throws IOException { return directory; @@ -239,7 +240,7 @@ public class InternalEngineTests extends ESTestCase { return 0; } }; - return new Store(shardId, EMPTY_SETTINGS, directoryService, new DummyShardLock(shardId)); + return new Store(shardId, INDEX_SETTINGS, directoryService, new DummyShardLock(shardId)); } protected Translog createTranslog() throws IOException { @@ -247,7 +248,7 @@ public class InternalEngineTests extends ESTestCase { } protected Translog createTranslog(Path translogPath) throws IOException { - TranslogConfig translogConfig = new TranslogConfig(shardId, translogPath, EMPTY_SETTINGS, Translog.Durabilty.REQUEST, BigArrays.NON_RECYCLING_INSTANCE, threadPool); + TranslogConfig translogConfig = new TranslogConfig(shardId, translogPath, INDEX_SETTINGS, Translog.Durabilty.REQUEST, BigArrays.NON_RECYCLING_INSTANCE, threadPool); return new Translog(translogConfig); } @@ -265,11 +266,11 @@ public class InternalEngineTests extends ESTestCase { public EngineConfig config(Settings indexSettings, Store store, Path translogPath, MergeSchedulerConfig mergeSchedulerConfig, MergePolicy mergePolicy) { IndexWriterConfig iwc = newIndexWriterConfig(); - TranslogConfig translogConfig = new TranslogConfig(shardId, translogPath, indexSettings, Translog.Durabilty.REQUEST, BigArrays.NON_RECYCLING_INSTANCE, threadPool); + TranslogConfig translogConfig = new TranslogConfig(shardId, translogPath, new IndexSettings(shardId.index(), indexSettings, Collections.emptyList()), Translog.Durabilty.REQUEST, BigArrays.NON_RECYCLING_INSTANCE, threadPool); - EngineConfig config = new EngineConfig(shardId, threadPool, new ShardIndexingService(shardId, indexSettings), indexSettings + EngineConfig config = new EngineConfig(shardId, threadPool, new ShardIndexingService(shardId, INDEX_SETTINGS), indexSettings , null, store, createSnapshotDeletionPolicy(), mergePolicy, mergeSchedulerConfig, - iwc.getAnalyzer(), iwc.getSimilarity(), new CodecService(shardId.index()), new Engine.EventListener() { + iwc.getAnalyzer(), iwc.getSimilarity(), new CodecService(INDEX_SETTINGS, null), new Engine.EventListener() { @Override public void onFailedEngine(String reason, @Nullable Throwable t) { // we don't need to notify anybody in this test @@ -1523,7 +1524,7 @@ public class InternalEngineTests extends ESTestCase { } public void testSettings() { - CodecService codecService = new CodecService(shardId.index()); + CodecService codecService = new CodecService(INDEX_SETTINGS, null); LiveIndexWriterConfig currentIndexWriterConfig = engine.getCurrentIndexWriterConfig(); assertEquals(engine.config().getCodec().getName(), codecService.codec(codecName).getName()); @@ -1866,11 +1867,12 @@ public class InternalEngineTests extends ESTestCase { Settings settings = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); RootObjectMapper.Builder rootBuilder = new RootObjectMapper.Builder("test"); Index index = new Index(indexName); - AnalysisService analysisService = new AnalysisService(index, settings); - SimilarityService similarityService = new SimilarityService(index, settings); - MapperService mapperService = new MapperService(index, settings, analysisService, similarityService, null); + IndexSettings indexSettings = new IndexSettings(index, settings, Collections.EMPTY_LIST); + AnalysisService analysisService = new AnalysisService(indexSettings); + SimilarityService similarityService = new SimilarityService(indexSettings, Collections.EMPTY_MAP); + MapperService mapperService = new MapperService(indexSettings, analysisService, similarityService, null); DocumentMapper.Builder b = new DocumentMapper.Builder(settings, rootBuilder, mapperService); - DocumentMapperParser parser = new DocumentMapperParser(settings, mapperService, analysisService, similarityService, null); + DocumentMapperParser parser = new DocumentMapperParser(indexSettings, mapperService, analysisService, similarityService, null); this.docMapper = b.build(mapperService, parser); } @@ -1908,18 +1910,18 @@ public class InternalEngineTests extends ESTestCase { Translog.TranslogGeneration generation = engine.getTranslog().getGeneration(); engine.close(); - Translog translog = new Translog(new TranslogConfig(shardId, createTempDir(), Settings.EMPTY, Translog.Durabilty.REQUEST, BigArrays.NON_RECYCLING_INSTANCE, threadPool)); + Translog translog = new Translog(new TranslogConfig(shardId, createTempDir(), INDEX_SETTINGS, Translog.Durabilty.REQUEST, BigArrays.NON_RECYCLING_INSTANCE, threadPool)); translog.add(new Translog.Index("test", "SomeBogusId", "{}".getBytes(Charset.forName("UTF-8")))); assertEquals(generation.translogFileGeneration, translog.currentFileGeneration()); translog.close(); EngineConfig config = engine.config(); /* create a TranslogConfig that has been created with a different UUID */ - TranslogConfig translogConfig = new TranslogConfig(shardId, translog.location(), config.getIndexSettings(), Translog.Durabilty.REQUEST, BigArrays.NON_RECYCLING_INSTANCE, threadPool); + TranslogConfig translogConfig = new TranslogConfig(shardId, translog.location(), new IndexSettings(shardId.index(), config.getIndexSettings(), Collections.EMPTY_LIST), Translog.Durabilty.REQUEST, BigArrays.NON_RECYCLING_INSTANCE, threadPool); EngineConfig brokenConfig = new EngineConfig(shardId, threadPool, config.getIndexingService(), config.getIndexSettings() , null, store, createSnapshotDeletionPolicy(), newMergePolicy(), config.getMergeSchedulerConfig(), - config.getAnalyzer(), config.getSimilarity(), new CodecService(shardId.index()), config.getEventListener() + config.getAnalyzer(), config.getSimilarity(), new CodecService(INDEX_SETTINGS, null), config.getEventListener() , config.getTranslogRecoveryPerformer(), IndexSearcher.getDefaultQueryCache(), IndexSearcher.getDefaultQueryCachingPolicy(), translogConfig); 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 525c9d416aa..a16a4863f61 100644 --- a/core/src/test/java/org/elasticsearch/index/engine/ShadowEngineTests.java +++ b/core/src/test/java/org/elasticsearch/index/engine/ShadowEngineTests.java @@ -45,6 +45,7 @@ import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.codec.CodecService; import org.elasticsearch.index.indexing.ShardIndexingService; import org.elasticsearch.index.mapper.Mapping; @@ -70,11 +71,11 @@ import org.junit.Before; import java.io.IOException; import java.nio.file.Path; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicBoolean; -import static org.elasticsearch.common.settings.Settings.Builder.EMPTY_SETTINGS; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.hasKey; @@ -87,6 +88,8 @@ import static org.hamcrest.Matchers.nullValue; */ public class ShadowEngineTests extends ESTestCase { + private static final IndexSettings INDEX_SETTINGS = new IndexSettings(new Index("index"), Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, org.elasticsearch.Version.CURRENT).build(), Collections.emptyList()); + protected final ShardId shardId = new ShardId(new Index("index"), 1); protected ThreadPool threadPool; @@ -106,7 +109,7 @@ public class ShadowEngineTests extends ESTestCase { @Before public void setUp() throws Exception { super.setUp(); - CodecService codecService = new CodecService(shardId.index()); + CodecService codecService = new CodecService(INDEX_SETTINGS, null); 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 @@ -178,8 +181,10 @@ public class ShadowEngineTests extends ESTestCase { return createStore(newMockFSDirectory(p)); } + protected Store createStore(final Directory directory) throws IOException { - final DirectoryService directoryService = new DirectoryService(shardId, EMPTY_SETTINGS) { + IndexSettings indexSettings = new IndexSettings(shardId.index(), Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(), Collections.emptyList()); + final DirectoryService directoryService = new DirectoryService(shardId, indexSettings) { @Override public Directory newDirectory() throws IOException { return directory; @@ -190,7 +195,7 @@ public class ShadowEngineTests extends ESTestCase { return 0; } }; - return new Store(shardId, EMPTY_SETTINGS, directoryService, new DummyShardLock(shardId)); + return new Store(shardId, indexSettings, directoryService, new DummyShardLock(shardId)); } protected SnapshotDeletionPolicy createSnapshotDeletionPolicy() { @@ -219,10 +224,10 @@ public class ShadowEngineTests extends ESTestCase { public EngineConfig config(Settings indexSettings, Store store, Path translogPath, MergeSchedulerConfig mergeSchedulerConfig, MergePolicy mergePolicy) { IndexWriterConfig iwc = newIndexWriterConfig(); - TranslogConfig translogConfig = new TranslogConfig(shardId, translogPath, indexSettings, Translog.Durabilty.REQUEST, BigArrays.NON_RECYCLING_INSTANCE, threadPool); - EngineConfig config = new EngineConfig(shardId, threadPool, new ShardIndexingService(shardId, indexSettings), indexSettings + TranslogConfig translogConfig = new TranslogConfig(shardId, translogPath, new IndexSettings(shardId.index(), indexSettings, Collections.EMPTY_LIST), Translog.Durabilty.REQUEST, BigArrays.NON_RECYCLING_INSTANCE, threadPool); + EngineConfig config = new EngineConfig(shardId, threadPool, new ShardIndexingService(shardId, new IndexSettings(shardId.index(), indexSettings, Collections.EMPTY_LIST)), indexSettings , null, store, createSnapshotDeletionPolicy(), mergePolicy, mergeSchedulerConfig, - iwc.getAnalyzer(), iwc.getSimilarity() , new CodecService(shardId.index()), new Engine.EventListener() { + iwc.getAnalyzer(), iwc.getSimilarity() , new CodecService(INDEX_SETTINGS, null), new Engine.EventListener() { @Override public void onFailedEngine(String reason, @Nullable Throwable t) { // we don't need to notify anybody in this test @@ -912,7 +917,7 @@ public class ShadowEngineTests extends ESTestCase { } public void testSettings() { - CodecService codecService = new CodecService(shardId.index()); + CodecService codecService = new CodecService(INDEX_SETTINGS, null); assertEquals(replicaEngine.config().getCodec().getName(), codecService.codec(codecName).getName()); } diff --git a/core/src/test/java/org/elasticsearch/index/fielddata/AbstractFieldDataTestCase.java b/core/src/test/java/org/elasticsearch/index/fielddata/AbstractFieldDataTestCase.java index 93afaf5eec6..6fb2fb7a05e 100644 --- a/core/src/test/java/org/elasticsearch/index/fielddata/AbstractFieldDataTestCase.java +++ b/core/src/test/java/org/elasticsearch/index/fielddata/AbstractFieldDataTestCase.java @@ -76,7 +76,7 @@ public abstract class AbstractFieldDataTestCase extends ESSingleNodeTestCase { public > IFD getForField(FieldDataType type, String fieldName, boolean docValues) { final MappedFieldType fieldType; - final BuilderContext context = new BuilderContext(indexService.settingsService().getSettings(), new ContentPath(1)); + final BuilderContext context = new BuilderContext(indexService.getIndexSettings().getSettings(), new ContentPath(1)); if (type.getType().equals("string")) { fieldType = MapperBuilders.stringField(fieldName).tokenized(false).docValues(docValues).fieldDataSettings(type.getSettings()).build(context).fieldType(); } else if (type.getType().equals("float")) { diff --git a/core/src/test/java/org/elasticsearch/index/fielddata/IndexFieldDataServiceTests.java b/core/src/test/java/org/elasticsearch/index/fielddata/IndexFieldDataServiceTests.java index 1168b3bc020..9f82019941d 100644 --- a/core/src/test/java/org/elasticsearch/index/fielddata/IndexFieldDataServiceTests.java +++ b/core/src/test/java/org/elasticsearch/index/fielddata/IndexFieldDataServiceTests.java @@ -26,8 +26,11 @@ import org.apache.lucene.document.StringField; import org.apache.lucene.index.*; import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.util.Accountable; +import org.elasticsearch.Version; +import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.lucene.index.ElasticsearchDirectoryReader; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.fielddata.plain.*; import org.elasticsearch.index.mapper.ContentPath; import org.elasticsearch.index.mapper.MappedFieldType; @@ -57,7 +60,7 @@ public class IndexFieldDataServiceTests extends ESSingleNodeTestCase { public void testGetForFieldDefaults() { final IndexService indexService = createIndex("test"); final IndexFieldDataService ifdService = indexService.fieldData(); - final BuilderContext ctx = new BuilderContext(indexService.settingsService().getSettings(), new ContentPath(1)); + final BuilderContext ctx = new BuilderContext(indexService.getIndexSettings().getSettings(), new ContentPath(1)); final MappedFieldType stringMapper = new StringFieldMapper.Builder("string").tokenized(false).build(ctx).fieldType(); ifdService.clear(); IndexFieldData fd = ifdService.getForField(stringMapper); @@ -88,7 +91,7 @@ public class IndexFieldDataServiceTests extends ESSingleNodeTestCase { public void testChangeFieldDataFormat() throws Exception { final IndexService indexService = createIndex("test"); final IndexFieldDataService ifdService = indexService.fieldData(); - final BuilderContext ctx = new BuilderContext(indexService.settingsService().getSettings(), new ContentPath(1)); + final BuilderContext ctx = new BuilderContext(indexService.getIndexSettings().getSettings(), new ContentPath(1)); final MappedFieldType mapper1 = MapperBuilders.stringField("s").tokenized(false).docValues(true).fieldDataSettings(Settings.builder().put(FieldDataType.FORMAT_KEY, "paged_bytes").build()).build(ctx).fieldType(); final IndexWriter writer = new IndexWriter(new RAMDirectory(), new IndexWriterConfig(new KeywordAnalyzer())); Document doc = new Document(); @@ -119,10 +122,10 @@ public class IndexFieldDataServiceTests extends ESSingleNodeTestCase { final IndexService indexService = createIndex("test"); IndexFieldDataService shardPrivateService = indexService.fieldData(); // copy the ifdService since we can set the listener only once. - final IndexFieldDataService ifdService = new IndexFieldDataService(shardPrivateService.index(), shardPrivateService.indexSettings(), + final IndexFieldDataService ifdService = new IndexFieldDataService(indexService.getIndexSettings(), getInstanceFromNode(IndicesFieldDataCache.class), getInstanceFromNode(CircuitBreakerService.class), indexService.mapperService()); - final BuilderContext ctx = new BuilderContext(indexService.settingsService().getSettings(), new ContentPath(1)); + final BuilderContext ctx = new BuilderContext(indexService.getIndexSettings().getSettings(), new ContentPath(1)); final MappedFieldType mapper1 = MapperBuilders.stringField("s").tokenized(false).docValues(true).fieldDataSettings(Settings.builder().put(FieldDataType.FORMAT_KEY, "paged_bytes").build()).build(ctx).fieldType(); final IndexWriter writer = new IndexWriter(new RAMDirectory(), new IndexWriterConfig(new KeywordAnalyzer())); Document doc = new Document(); @@ -192,7 +195,7 @@ public class IndexFieldDataServiceTests extends ESSingleNodeTestCase { ThreadPool threadPool = new ThreadPool("random_threadpool_name"); try { IndicesFieldDataCache cache = new IndicesFieldDataCache(Settings.EMPTY, null, threadPool); - IndexFieldDataService ifds = new IndexFieldDataService(new Index("test"), Settings.EMPTY, cache, null, null); + IndexFieldDataService ifds = new IndexFieldDataService(new IndexSettings(new Index("test"), Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(), Collections.EMPTY_LIST), cache, null, null); ft.setNames(new Names("some_long")); ft.setHasDocValues(true); ifds.getForField(ft); // no exception diff --git a/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/RegisterExternalTypes.java b/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/RegisterExternalTypes.java index 8fb1814a60e..5d2a79cae30 100755 --- a/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/RegisterExternalTypes.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/RegisterExternalTypes.java @@ -20,11 +20,9 @@ package org.elasticsearch.index.mapper.externalvalues; 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.index.mapper.MapperService; -import org.elasticsearch.index.settings.IndexSettings; public class RegisterExternalTypes extends AbstractIndexComponent { public static final String EXTERNAL = "external"; @@ -32,8 +30,8 @@ public class RegisterExternalTypes extends AbstractIndexComponent { public static final String EXTERNAL_UPPER = "external_upper"; @Inject - public RegisterExternalTypes(Index index, @IndexSettings Settings indexSettings, MapperService mapperService) { - super(index, indexSettings); + public RegisterExternalTypes(IndexSettings indexSettings, MapperService mapperService) { + super(indexSettings); mapperService.documentMapperParser().putRootTypeParser(ExternalMetadataMapper.CONTENT_TYPE, new ExternalMetadataMapper.TypeParser()); mapperService.documentMapperParser().putTypeParser(EXTERNAL, new ExternalMapper.TypeParser(EXTERNAL, "foo")); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/multifield/MultiFieldTests.java b/core/src/test/java/org/elasticsearch/index/mapper/multifield/MultiFieldTests.java index e1efd405df9..062df947bbe 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/multifield/MultiFieldTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/multifield/MultiFieldTests.java @@ -143,7 +143,7 @@ public class MultiFieldTests extends ESSingleNodeTestCase { public void testBuildThenParse() throws Exception { IndexService indexService = createIndex("test"); - Settings settings = indexService.settingsService().getSettings(); + Settings settings = indexService.getIndexSettings().getSettings(); DocumentMapperParser mapperParser = indexService.mapperService().documentMapperParser(); DocumentMapper builderDocMapper = doc(settings, rootObject("person").add( diff --git a/core/src/test/java/org/elasticsearch/index/mapper/simple/SimpleMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/simple/SimpleMapperTests.java index edd1f0f4a4a..0e8c74aee89 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/simple/SimpleMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/simple/SimpleMapperTests.java @@ -47,7 +47,7 @@ import static org.hamcrest.Matchers.equalTo; public class SimpleMapperTests extends ESSingleNodeTestCase { public void testSimpleMapper() throws Exception { IndexService indexService = createIndex("test"); - Settings settings = indexService.settingsService().getSettings(); + Settings settings = indexService.getIndexSettings().getSettings(); DocumentMapperParser mapperParser = indexService.mapperService().documentMapperParser(); DocumentMapper docMapper = doc(settings, rootObject("person") @@ -109,7 +109,7 @@ public class SimpleMapperTests extends ESSingleNodeTestCase { public void testNoDocumentSent() throws Exception { IndexService indexService = createIndex("test"); - Settings settings = indexService.settingsService().getSettings(); + Settings settings = indexService.getIndexSettings().getSettings(); DocumentMapperParser mapperParser = indexService.mapperService().documentMapperParser(); DocumentMapper docMapper = doc(settings, rootObject("person") diff --git a/core/src/test/java/org/elasticsearch/index/mapper/string/SimpleStringMappingTests.java b/core/src/test/java/org/elasticsearch/index/mapper/string/SimpleStringMappingTests.java index 3dfd2b4d2c0..121f100ffa6 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/string/SimpleStringMappingTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/string/SimpleStringMappingTests.java @@ -365,7 +365,7 @@ public class SimpleStringMappingTests extends ESSingleNodeTestCase { public void testDocValuesFielddata() throws Exception { IndexService indexService = createIndex("index"); DocumentMapperParser parser = indexService.mapperService().documentMapperParser(); - final BuilderContext ctx = new BuilderContext(indexService.settingsService().getSettings(), new ContentPath(1)); + final BuilderContext ctx = new BuilderContext(indexService.getIndexSettings().getSettings(), new ContentPath(1)); assertFalse(new Builder("anything").index(false).build(ctx).fieldType().hasDocValues()); assertTrue(new Builder("anything").index(false).fieldDataSettings(DOC_VALUES_SETTINGS).build(ctx).fieldType().hasDocValues()); @@ -404,7 +404,7 @@ public class SimpleStringMappingTests extends ESSingleNodeTestCase { public void testDocValues() throws Exception { // doc values only work on non-analyzed content - final BuilderContext ctx = new BuilderContext(indexService.settingsService().getSettings(), new ContentPath(1)); + final BuilderContext ctx = new BuilderContext(indexService.getIndexSettings().getSettings(), new ContentPath(1)); try { new StringFieldMapper.Builder("anything").docValues(true).build(ctx); fail(); diff --git a/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java b/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java index a37adcd808c..55f1a1ffb04 100644 --- a/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java +++ b/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java @@ -58,14 +58,13 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.env.Environment; import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexNameModule; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.analysis.AnalysisModule; import org.elasticsearch.index.cache.IndexCacheModule; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.query.functionscore.ScoreFunctionParser; import org.elasticsearch.index.query.functionscore.ScoreFunctionParserMapper; import org.elasticsearch.index.query.support.QueryParsers; -import org.elasticsearch.index.settings.IndexSettingsModule; import org.elasticsearch.index.similarity.SimilarityModule; import org.elasticsearch.indices.IndicesModule; import org.elasticsearch.indices.analysis.IndicesAnalysisService; @@ -80,6 +79,7 @@ import org.elasticsearch.script.ScriptService; import org.elasticsearch.script.mustache.MustacheScriptEngineService; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.IndexNameAndSettingsModule; import org.elasticsearch.test.TestSearchContext; import org.elasticsearch.test.VersionUtils; import org.elasticsearch.test.cluster.TestClusterService; @@ -212,11 +212,10 @@ public abstract class AbstractQueryTestCase> } }, - new IndexSettingsModule(index, indexSettings), + new IndexNameAndSettingsModule(index, indexSettings), new IndexCacheModule(indexSettings), new AnalysisModule(indexSettings, new IndicesAnalysisService(indexSettings)), - new SimilarityModule(index, indexSettings), - new IndexNameModule(index), + new SimilarityModule(new IndexSettings(index, indexSettings, Collections.EMPTY_LIST)), new AbstractModule() { @Override protected void configure() { @@ -523,7 +522,7 @@ public abstract class AbstractQueryTestCase> * @return a new {@link QueryShardContext} based on the base test index and queryParserService */ protected static QueryShardContext createShardContext() { - QueryShardContext queryCreationContext = new QueryShardContext(index, queryParserService); + QueryShardContext queryCreationContext = new QueryShardContext(queryParserService); queryCreationContext.reset(); queryCreationContext.parseFieldMatcher(ParseFieldMatcher.STRICT); return queryCreationContext; diff --git a/core/src/test/java/org/elasticsearch/index/query/TemplateQueryParserTests.java b/core/src/test/java/org/elasticsearch/index/query/TemplateQueryParserTests.java index 6e47f52afe4..d0294669420 100644 --- a/core/src/test/java/org/elasticsearch/index/query/TemplateQueryParserTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/TemplateQueryParserTests.java @@ -37,11 +37,10 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.env.Environment; import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexNameModule; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.analysis.AnalysisModule; import org.elasticsearch.index.cache.IndexCacheModule; import org.elasticsearch.index.query.functionscore.ScoreFunctionParser; -import org.elasticsearch.index.settings.IndexSettingsModule; import org.elasticsearch.index.similarity.SimilarityModule; import org.elasticsearch.indices.IndicesModule; import org.elasticsearch.indices.analysis.IndicesAnalysisService; @@ -49,6 +48,7 @@ import org.elasticsearch.indices.breaker.CircuitBreakerService; import org.elasticsearch.indices.breaker.NoneCircuitBreakerService; import org.elasticsearch.script.ScriptModule; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.IndexNameAndSettingsModule; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPoolModule; import org.junit.After; @@ -56,6 +56,7 @@ import org.junit.Before; import java.io.IOException; import java.lang.reflect.Proxy; +import java.util.Collections; import static org.hamcrest.Matchers.containsString; @@ -94,11 +95,10 @@ public class TemplateQueryParserTests extends ESTestCase { } }, new ScriptModule(settings), - new IndexSettingsModule(index, settings), + new IndexNameAndSettingsModule(index, settings), new IndexCacheModule(settings), new AnalysisModule(settings, new IndicesAnalysisService(settings)), - new SimilarityModule(index, settings), - new IndexNameModule(index), + new SimilarityModule(new IndexSettings(index, settings, Collections.EMPTY_LIST)), new AbstractModule() { @Override protected void configure() { @@ -111,7 +111,7 @@ public class TemplateQueryParserTests extends ESTestCase { ).createInjector(); IndexQueryParserService queryParserService = injector.getInstance(IndexQueryParserService.class); - context = new QueryShardContext(index, queryParserService); + context = new QueryShardContext(queryParserService); } @Override diff --git a/core/src/test/java/org/elasticsearch/index/query/WrapperQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/WrapperQueryBuilderTests.java index 0cd30208571..fb9bde7dce7 100644 --- a/core/src/test/java/org/elasticsearch/index/query/WrapperQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/WrapperQueryBuilderTests.java @@ -55,7 +55,7 @@ public class WrapperQueryBuilderTests extends AbstractQueryTestCase innerQuery = contextCopy.parseContext().parseInnerQueryBuilder(); Query expected = innerQuery.toQuery(context); diff --git a/core/src/test/java/org/elasticsearch/index/search/MultiMatchQueryTests.java b/core/src/test/java/org/elasticsearch/index/search/MultiMatchQueryTests.java index 3c3f1b44951..34a28588da0 100644 --- a/core/src/test/java/org/elasticsearch/index/search/MultiMatchQueryTests.java +++ b/core/src/test/java/org/elasticsearch/index/search/MultiMatchQueryTests.java @@ -68,7 +68,7 @@ public class MultiMatchQueryTests extends ESSingleNodeTestCase { } public void testCrossFieldMultiMatchQuery() throws IOException { - QueryShardContext queryShardContext = new QueryShardContext(new Index("test"), queryParser); + QueryShardContext queryShardContext = new QueryShardContext(queryParser); queryShardContext.setAllowUnmappedFields(true); Query parsedQuery = multiMatchQuery("banon").field("name.first", 2).field("name.last", 3).field("foobar").type(MultiMatchQueryBuilder.Type.CROSS_FIELDS).toQuery(queryShardContext); try (Engine.Searcher searcher = indexService.getShard(0).acquireSearcher("test")) { diff --git a/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java b/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java index b77c704cdcb..34b2a2ac6a7 100644 --- a/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java +++ b/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java @@ -86,7 +86,6 @@ import org.elasticsearch.index.mapper.ParseContext; import org.elasticsearch.index.mapper.ParsedDocument; import org.elasticsearch.index.mapper.Uid; import org.elasticsearch.index.mapper.internal.UidFieldMapper; -import org.elasticsearch.index.settings.IndexSettingsService; import org.elasticsearch.index.snapshots.IndexShardRepository; import org.elasticsearch.index.snapshots.IndexShardSnapshotStatus; import org.elasticsearch.index.store.Store; @@ -434,10 +433,10 @@ public class IndexShardTests extends ESSingleNodeTestCase { public void testUpdatePriority() { assertAcked(client().admin().indices().prepareCreate("test") .setSettings(IndexMetaData.SETTING_PRIORITY, 200)); - IndexSettingsService indexSettingsService = getInstanceFromNode(IndicesService.class).indexService("test").settingsService(); - assertEquals(200, indexSettingsService.getSettings().getAsInt(IndexMetaData.SETTING_PRIORITY, 0).intValue()); + IndexService indexService = getInstanceFromNode(IndicesService.class).indexService("test"); + assertEquals(200, indexService.getIndexSettings().getSettings().getAsInt(IndexMetaData.SETTING_PRIORITY, 0).intValue()); client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put(IndexMetaData.SETTING_PRIORITY, 400).build()).get(); - assertEquals(400, indexSettingsService.getSettings().getAsInt(IndexMetaData.SETTING_PRIORITY, 0).intValue()); + assertEquals(400, indexService.getIndexSettings().getSettings().getAsInt(IndexMetaData.SETTING_PRIORITY, 0).intValue()); } public void testRecoverIntoLeftover() throws IOException { @@ -897,18 +896,6 @@ public class IndexShardTests extends ESSingleNodeTestCase { assertSearchHits(client().prepareSearch("test_target").get(), "0"); } - public void testListenersAreRemoved() { - createIndex("test"); - ensureGreen(); - IndicesService indicesService = getInstanceFromNode(IndicesService.class); - IndexService indexService = indicesService.indexService("test"); - IndexShard shard = indexService.getShardOrNull(0); - IndexSettingsService settingsService = indexService.settingsService(); - assertTrue(settingsService.isRegistered(shard)); - indexService.removeShard(0, "simon says so"); - assertFalse(settingsService.isRegistered(shard)); - } - public void testSearcherWrapperIsUsed() throws IOException { createIndex("test"); ensureGreen(); @@ -1040,7 +1027,7 @@ public class IndexShardTests extends ESSingleNodeTestCase { shard.close("simon says", true); IndexServicesProvider indexServices = indexService.getIndexServices(); IndexServicesProvider newProvider = new IndexServicesProvider(indexServices.getIndexEventListener(), indexServices.getThreadPool(), indexServices.getMapperService(), indexServices.getQueryParserService(), indexServices.getIndexCache(), indexServices.getIndicesQueryCache(), indexServices.getCodecService(), indexServices.getTermVectorsService(), indexServices.getIndexFieldDataService(), indexServices.getWarmer(), indexServices.getSimilarityService(), indexServices.getFactory(), indexServices.getBigArrays(), wrapper, indexServices.getIndexingMemoryController()); - IndexShard newShard = new IndexShard(shard.shardId(), shard.indexSettings, shard.shardPath(), shard.store(), newProvider); + IndexShard newShard = new IndexShard(shard.shardId(), indexService.getIndexSettings(), shard.shardPath(), shard.store(), newProvider); ShardRoutingHelper.reinit(routing); newShard.updateRoutingEntry(routing, false); DiscoveryNode localNode = new DiscoveryNode("foo", DummyTransportAddress.INSTANCE, Version.CURRENT); diff --git a/core/src/test/java/org/elasticsearch/index/shard/MergePolicySettingsTests.java b/core/src/test/java/org/elasticsearch/index/shard/MergePolicySettingsTests.java index 76051d70d09..84fe7b1f96b 100644 --- a/core/src/test/java/org/elasticsearch/index/shard/MergePolicySettingsTests.java +++ b/core/src/test/java/org/elasticsearch/index/shard/MergePolicySettingsTests.java @@ -24,7 +24,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettingsService; import org.elasticsearch.test.ESTestCase; import java.io.IOException; @@ -56,18 +55,17 @@ public class MergePolicySettingsTests extends ESTestCase { public void testUpdateSettings() throws IOException { { - IndexSettingsService service = new IndexSettingsService(new Index("test"), EMPTY_SETTINGS); MergePolicyConfig mp = new MergePolicyConfig(logger, EMPTY_SETTINGS); - assertThat(((TieredMergePolicy) mp.getMergePolicy()).getNoCFSRatio(), equalTo(0.1)); + assertThat((mp.getMergePolicy()).getNoCFSRatio(), equalTo(0.1)); mp.onRefreshSettings(build(1.0)); - assertThat(((TieredMergePolicy) mp.getMergePolicy()).getNoCFSRatio(), equalTo(1.0)); + assertThat((mp.getMergePolicy()).getNoCFSRatio(), equalTo(1.0)); mp.onRefreshSettings(build(0.1)); - assertThat(((TieredMergePolicy) mp.getMergePolicy()).getNoCFSRatio(), equalTo(0.1)); + assertThat((mp.getMergePolicy()).getNoCFSRatio(), equalTo(0.1)); mp.onRefreshSettings(build(0.0)); - assertThat(((TieredMergePolicy) mp.getMergePolicy()).getNoCFSRatio(), equalTo(0.0)); + assertThat((mp.getMergePolicy()).getNoCFSRatio(), equalTo(0.0)); } diff --git a/core/src/test/java/org/elasticsearch/index/shard/NewPathForShardTests.java b/core/src/test/java/org/elasticsearch/index/shard/NewPathForShardTests.java index e2affa21f10..5036d25a108 100644 --- a/core/src/test/java/org/elasticsearch/index/shard/NewPathForShardTests.java +++ b/core/src/test/java/org/elasticsearch/index/shard/NewPathForShardTests.java @@ -20,13 +20,15 @@ package org.elasticsearch.index.shard; import org.apache.lucene.mockfile.FilterFileSystemProvider; -import org.apache.lucene.util.Constants; +import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.io.PathUtilsForTesting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; import org.elasticsearch.env.NodeEnvironment.NodePath; import org.elasticsearch.env.NodeEnvironment; +import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.test.ESTestCase; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -47,6 +49,8 @@ import java.util.Map; /** Separate test class from ShardPathTests because we need static (BeforeClass) setup to install mock filesystems... */ public class NewPathForShardTests extends ESTestCase { + private static final IndexSettings INDEX_SETTINGS = new IndexSettings(new Index("index"), Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, org.elasticsearch.Version.CURRENT).build(), Collections.emptyList()); + // Sneakiness to install mock file stores so we can pretend how much free space we have on each path.data: private static MockFileStore aFileStore = new MockFileStore("mocka"); private static MockFileStore bFileStore = new MockFileStore("mockb"); @@ -179,7 +183,7 @@ public class NewPathForShardTests extends ESTestCase { bFileStore.usableSpace = 1000; ShardId shardId = new ShardId("index", 0); - ShardPath result = ShardPath.selectNewPathForShard(nodeEnv, shardId, Settings.EMPTY, 100, Collections.emptyMap()); + ShardPath result = ShardPath.selectNewPathForShard(nodeEnv, shardId, INDEX_SETTINGS, 100, Collections.emptyMap()); assertTrue(result.getDataPath().toString().contains(aPathPart)); // Test the reverse: b has lots of free space, but a has little, so new shard should go to b: @@ -187,7 +191,7 @@ public class NewPathForShardTests extends ESTestCase { bFileStore.usableSpace = 100000; shardId = new ShardId("index", 0); - result = ShardPath.selectNewPathForShard(nodeEnv, shardId, Settings.EMPTY, 100, Collections.emptyMap()); + result = ShardPath.selectNewPathForShard(nodeEnv, shardId, INDEX_SETTINGS, 100, Collections.emptyMap()); assertTrue(result.getDataPath().toString().contains(bPathPart)); // Now a and be have equal usable space; we allocate two shards to the node, and each should go to different paths: @@ -195,9 +199,9 @@ public class NewPathForShardTests extends ESTestCase { bFileStore.usableSpace = 100000; Map dataPathToShardCount = new HashMap<>(); - ShardPath result1 = ShardPath.selectNewPathForShard(nodeEnv, shardId, Settings.EMPTY, 100, dataPathToShardCount); + ShardPath result1 = ShardPath.selectNewPathForShard(nodeEnv, shardId, INDEX_SETTINGS, 100, dataPathToShardCount); dataPathToShardCount.put(NodeEnvironment.shardStatePathToDataPath(result1.getDataPath()), 1); - ShardPath result2 = ShardPath.selectNewPathForShard(nodeEnv, shardId, Settings.EMPTY, 100, dataPathToShardCount); + ShardPath result2 = ShardPath.selectNewPathForShard(nodeEnv, shardId, INDEX_SETTINGS, 100, dataPathToShardCount); // #11122: this was the original failure: on a node with 2 disks that have nearly equal // free space, we would always allocate all N incoming shards to the one path that diff --git a/core/src/test/java/org/elasticsearch/index/shard/ShardPathTests.java b/core/src/test/java/org/elasticsearch/index/shard/ShardPathTests.java index 0d653c08108..51b4d2d97c4 100644 --- a/core/src/test/java/org/elasticsearch/index/shard/ShardPathTests.java +++ b/core/src/test/java/org/elasticsearch/index/shard/ShardPathTests.java @@ -18,13 +18,16 @@ */ package org.elasticsearch.index.shard; +import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.NodeEnvironment; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.test.ESTestCase; import java.io.IOException; import java.nio.file.Path; +import java.util.Collections; import static org.elasticsearch.common.settings.Settings.settingsBuilder; import static org.hamcrest.Matchers.containsString; @@ -35,13 +38,14 @@ import static org.hamcrest.Matchers.is; public class ShardPathTests extends ESTestCase { public void testLoadShardPath() throws IOException { try (final NodeEnvironment env = newNodeEnvironment(settingsBuilder().build())) { - Settings.Builder builder = settingsBuilder().put(IndexMetaData.SETTING_INDEX_UUID, "0xDEADBEEF"); + Settings.Builder builder = settingsBuilder().put(IndexMetaData.SETTING_INDEX_UUID, "0xDEADBEEF") + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT); Settings settings = builder.build(); ShardId shardId = new ShardId("foo", 0); Path[] paths = env.availableShardPaths(shardId); Path path = randomFrom(paths); ShardStateMetaData.FORMAT.write(new ShardStateMetaData(2, true, "0xDEADBEEF"), 2, path); - ShardPath shardPath = ShardPath.loadShardPath(logger, env, shardId, settings); + ShardPath shardPath = ShardPath.loadShardPath(logger, env, shardId, new IndexSettings(shardId.index(), settings, Collections.EMPTY_LIST)); assertEquals(path, shardPath.getDataPath()); assertEquals("0xDEADBEEF", shardPath.getIndexUUID()); assertEquals("foo", shardPath.getShardId().getIndex()); @@ -52,14 +56,15 @@ public class ShardPathTests extends ESTestCase { public void testFailLoadShardPathOnMultiState() throws IOException { try (final NodeEnvironment env = newNodeEnvironment(settingsBuilder().build())) { - Settings.Builder builder = settingsBuilder().put(IndexMetaData.SETTING_INDEX_UUID, "0xDEADBEEF"); + Settings.Builder builder = settingsBuilder().put(IndexMetaData.SETTING_INDEX_UUID, "0xDEADBEEF") + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT); Settings settings = builder.build(); ShardId shardId = new ShardId("foo", 0); Path[] paths = env.availableShardPaths(shardId); assumeTrue("This test tests multi data.path but we only got one", paths.length > 1); int id = randomIntBetween(1, 10); ShardStateMetaData.FORMAT.write(new ShardStateMetaData(id, true, "0xDEADBEEF"), id, paths); - ShardPath.loadShardPath(logger, env, shardId, settings); + ShardPath.loadShardPath(logger, env, shardId, new IndexSettings(shardId.index(), settings, Collections.EMPTY_LIST)); fail("Expected IllegalStateException"); } catch (IllegalStateException e) { assertThat(e.getMessage(), containsString("more than one shard state found")); @@ -68,14 +73,15 @@ public class ShardPathTests extends ESTestCase { public void testFailLoadShardPathIndexUUIDMissmatch() throws IOException { try (final NodeEnvironment env = newNodeEnvironment(settingsBuilder().build())) { - Settings.Builder builder = settingsBuilder().put(IndexMetaData.SETTING_INDEX_UUID, "foobar"); + Settings.Builder builder = settingsBuilder().put(IndexMetaData.SETTING_INDEX_UUID, "foobar") + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT); Settings settings = builder.build(); ShardId shardId = new ShardId("foo", 0); Path[] paths = env.availableShardPaths(shardId); Path path = randomFrom(paths); int id = randomIntBetween(1, 10); ShardStateMetaData.FORMAT.write(new ShardStateMetaData(id, true, "0xDEADBEEF"), id, path); - ShardPath.loadShardPath(logger, env, shardId, settings); + ShardPath.loadShardPath(logger, env, shardId, new IndexSettings(shardId.index(), settings, Collections.EMPTY_LIST)); fail("Expected IllegalStateException"); } catch (IllegalStateException e) { assertThat(e.getMessage(), containsString("expected: foobar on shard path")); @@ -104,7 +110,9 @@ public class ShardPathTests extends ESTestCase { boolean useCustomDataPath = randomBoolean(); final Settings indexSetttings; final Settings nodeSettings; - Settings.Builder indexSettingsBuilder = settingsBuilder().put(IndexMetaData.SETTING_INDEX_UUID, "0xDEADBEEF"); + Settings.Builder indexSettingsBuilder = settingsBuilder() + .put(IndexMetaData.SETTING_INDEX_UUID, "0xDEADBEEF") + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT); final Path customPath; if (useCustomDataPath) { final Path path = createTempDir(); @@ -127,7 +135,7 @@ public class ShardPathTests extends ESTestCase { Path[] paths = env.availableShardPaths(shardId); Path path = randomFrom(paths); ShardStateMetaData.FORMAT.write(new ShardStateMetaData(2, true, "0xDEADBEEF"), 2, path); - ShardPath shardPath = ShardPath.loadShardPath(logger, env, shardId, indexSetttings); + ShardPath shardPath = ShardPath.loadShardPath(logger, env, shardId, new IndexSettings(shardId.index(), indexSetttings, Collections.EMPTY_LIST)); boolean found = false; for (Path p : env.nodeDataPaths()) { if (p.equals(shardPath.getRootStatePath())) { diff --git a/core/src/test/java/org/elasticsearch/index/similarity/SimilarityModuleTests.java b/core/src/test/java/org/elasticsearch/index/similarity/SimilarityModuleTests.java index a73d2a5dac4..91d9e510bdd 100644 --- a/core/src/test/java/org/elasticsearch/index/similarity/SimilarityModuleTests.java +++ b/core/src/test/java/org/elasticsearch/index/similarity/SimilarityModuleTests.java @@ -24,20 +24,25 @@ import org.apache.lucene.search.CollectionStatistics; import org.apache.lucene.search.TermStatistics; import org.apache.lucene.search.similarities.BM25Similarity; import org.apache.lucene.search.similarities.Similarity; +import org.elasticsearch.Version; +import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.inject.ModuleTestCase; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import java.io.IOException; +import java.util.Collections; public class SimilarityModuleTests extends ModuleTestCase { public void testAddSimilarity() { Settings indexSettings = Settings.settingsBuilder() + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .put("index.similarity.my_similarity.type", "test_similarity") .put("index.similarity.my_similarity.key", "there is a key") .build(); - SimilarityModule module = new SimilarityModule(new Index("foo"), indexSettings); + SimilarityModule module = new SimilarityModule(new IndexSettings(new Index("foo"), indexSettings, Collections.EMPTY_LIST)); module.addSimilarity("test_similarity", (string, settings) -> new SimilarityProvider() { @Override public String name() { @@ -64,8 +69,9 @@ public class SimilarityModuleTests extends ModuleTestCase { public void testSetupUnknownSimilarity() { Settings indexSettings = Settings.settingsBuilder() .put("index.similarity.my_similarity.type", "test_similarity") + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .build(); - SimilarityModule module = new SimilarityModule(new Index("foo"), indexSettings); + SimilarityModule module = new SimilarityModule(new IndexSettings(new Index("foo"), indexSettings, Collections.EMPTY_LIST)); try { assertInstanceBinding(module, SimilarityService.class, (inst) -> inst instanceof SimilarityService); } catch (IllegalArgumentException ex) { @@ -77,8 +83,9 @@ public class SimilarityModuleTests extends ModuleTestCase { public void testSetupWithoutType() { Settings indexSettings = Settings.settingsBuilder() .put("index.similarity.my_similarity.foo", "bar") + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .build(); - SimilarityModule module = new SimilarityModule(new Index("foo"), indexSettings); + SimilarityModule module = new SimilarityModule(new IndexSettings(new Index("foo"), indexSettings, Collections.EMPTY_LIST)); try { assertInstanceBinding(module, SimilarityService.class, (inst) -> inst instanceof SimilarityService); } catch (IllegalArgumentException ex) { diff --git a/core/src/test/java/org/elasticsearch/index/store/CorruptedFileIT.java b/core/src/test/java/org/elasticsearch/index/store/CorruptedFileIT.java index 5f18f9980ab..044a18835ae 100644 --- a/core/src/test/java/org/elasticsearch/index/store/CorruptedFileIT.java +++ b/core/src/test/java/org/elasticsearch/index/store/CorruptedFileIT.java @@ -50,7 +50,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.discovery.Discovery; import org.elasticsearch.gateway.PrimaryShardAllocator; -import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.shard.*; import org.elasticsearch.indices.recovery.RecoveryFileChunkRequest; import org.elasticsearch.indices.recovery.RecoverySettings; @@ -191,7 +190,7 @@ public class CorruptedFileIT extends ESIntegTestCase { final CopyOnWriteArrayList exception = new CopyOnWriteArrayList<>(); final IndexEventListener listener = new IndexEventListener() { @Override - public void afterIndexShardClosed(ShardId sid, @Nullable IndexShard indexShard, @IndexSettings Settings indexSettings) { + public void afterIndexShardClosed(ShardId sid, @Nullable IndexShard indexShard, Settings indexSettings) { if (indexShard != null) { Store store = indexShard.store(); store.incRef(); diff --git a/core/src/test/java/org/elasticsearch/index/store/IndexStoreTests.java b/core/src/test/java/org/elasticsearch/index/store/IndexStoreTests.java index e921f95394c..9fca1f418d1 100644 --- a/core/src/test/java/org/elasticsearch/index/store/IndexStoreTests.java +++ b/core/src/test/java/org/elasticsearch/index/store/IndexStoreTests.java @@ -21,13 +21,18 @@ package org.elasticsearch.index.store; import com.carrotsearch.randomizedtesting.generators.RandomPicks; import org.apache.lucene.store.*; import org.apache.lucene.util.Constants; +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.IndexSettings; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardPath; import org.elasticsearch.test.ESTestCase; import java.io.IOException; import java.nio.file.Path; +import java.util.Collections; import java.util.Locale; /** @@ -38,8 +43,10 @@ public class IndexStoreTests extends ESTestCase { 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)).build(); - FsDirectoryService service = new FsDirectoryService(settings, null, new ShardPath(false, tempDir, tempDir, "foo", new ShardId("foo", 0))); + Settings settings = Settings.settingsBuilder().put(IndexStoreModule.STORE_TYPE, type.name().toLowerCase(Locale.ROOT)) + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); + IndexSettings indexSettings = new IndexSettings(new Index("foo"), settings, Collections.EMPTY_LIST); + FsDirectoryService service = new FsDirectoryService(indexSettings, null, new ShardPath(false, tempDir, tempDir, "foo", new ShardId("foo", 0))); try (final Directory directory = service.newFSDirectory(tempDir, NoLockFactory.INSTANCE)) { switch (type) { case NIOFS: @@ -71,8 +78,7 @@ public class IndexStoreTests extends ESTestCase { public void testStoreDirectoryDefault() throws IOException { final Path tempDir = createTempDir().resolve("foo").resolve("0"); - Settings settings = Settings.EMPTY; - FsDirectoryService service = new FsDirectoryService(settings, null, new ShardPath(false, tempDir, tempDir, "foo", new ShardId("foo", 0))); + FsDirectoryService service = new FsDirectoryService(new IndexSettings(new Index("foo"), Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(), Collections.EMPTY_LIST), null, new ShardPath(false, tempDir, tempDir, "foo", new ShardId("foo", 0))); try (final Directory directory = service.newFSDirectory(tempDir, NoLockFactory.INSTANCE)) { if (Constants.WINDOWS) { assertTrue(directory.toString(), directory instanceof MMapDirectory || directory instanceof SimpleFSDirectory); diff --git a/core/src/test/java/org/elasticsearch/index/store/StoreTests.java b/core/src/test/java/org/elasticsearch/index/store/StoreTests.java index 7e8186157a4..9cbbbfa2c88 100644 --- a/core/src/test/java/org/elasticsearch/index/store/StoreTests.java +++ b/core/src/test/java/org/elasticsearch/index/store/StoreTests.java @@ -58,6 +58,7 @@ import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.TestUtil; import org.apache.lucene.util.Version; import org.elasticsearch.ExceptionsHelper; +import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.InputStreamStreamInput; import org.elasticsearch.common.io.stream.OutputStreamStreamOutput; @@ -66,6 +67,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.env.ShardLock; import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.translog.Translog; @@ -80,16 +82,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.NoSuchFileException; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.Set; -import java.util.concurrent.atomic.AtomicBoolean; +import java.util.*; import java.util.concurrent.atomic.AtomicInteger; import java.util.zip.Adler32; @@ -106,10 +99,15 @@ import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; public class StoreTests extends ESTestCase { + + private static final IndexSettings INDEX_SETTINGS = new IndexSettings(new Index("index"), Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, org.elasticsearch.Version.CURRENT).build(), Collections.emptyList()); + public void testRefCount() throws IOException { final ShardId shardId = new ShardId(new Index("index"), 1); DirectoryService directoryService = new LuceneManagedDirectoryService(random()); - Store store = new Store(shardId, Settings.EMPTY, directoryService, new DummyShardLock(shardId)); + IndexSettings indexSettings = INDEX_SETTINGS; + + Store store = new Store(shardId, indexSettings, directoryService, new DummyShardLock(shardId)); int incs = randomIntBetween(1, 100); for (int i = 0; i < incs; i++) { if (randomBoolean()) { @@ -126,7 +124,6 @@ public class StoreTests extends ESTestCase { } store.incRef(); - final AtomicBoolean called = new AtomicBoolean(false); store.close(); for (int i = 0; i < incs; i++) { if (randomBoolean()) { @@ -357,7 +354,7 @@ public class StoreTests extends ESTestCase { public void testWriteLegacyChecksums() throws IOException { final ShardId shardId = new ShardId(new Index("index"), 1); DirectoryService directoryService = new LuceneManagedDirectoryService(random()); - Store store = new Store(shardId, Settings.EMPTY, directoryService, new DummyShardLock(shardId)); + Store store = new Store(shardId, INDEX_SETTINGS, directoryService, new DummyShardLock(shardId)); // set default codec - all segments need checksums final boolean usesOldCodec = randomBoolean(); IndexWriter writer = new IndexWriter(store.directory(), newIndexWriterConfig(random(), new MockAnalyzer(random())).setCodec(usesOldCodec ? new OldSIMockingCodec() : TestUtil.getDefaultCodec())); @@ -441,7 +438,7 @@ public class StoreTests extends ESTestCase { public void testNewChecksums() throws IOException { final ShardId shardId = new ShardId(new Index("index"), 1); DirectoryService directoryService = new LuceneManagedDirectoryService(random()); - Store store = new Store(shardId, Settings.EMPTY, directoryService, new DummyShardLock(shardId)); + Store store = new Store(shardId, INDEX_SETTINGS, directoryService, new DummyShardLock(shardId)); // set default codec - all segments need checksums IndexWriter writer = new IndexWriter(store.directory(), newIndexWriterConfig(random(), new MockAnalyzer(random())).setCodec(TestUtil.getDefaultCodec())); int docs = 1 + random().nextInt(100); @@ -500,7 +497,7 @@ public class StoreTests extends ESTestCase { public void testMixedChecksums() throws IOException { final ShardId shardId = new ShardId(new Index("index"), 1); DirectoryService directoryService = new LuceneManagedDirectoryService(random()); - Store store = new Store(shardId, Settings.EMPTY, directoryService, new DummyShardLock(shardId)); + Store store = new Store(shardId, INDEX_SETTINGS, directoryService, new DummyShardLock(shardId)); // this time random codec.... IndexWriter writer = new IndexWriter(store.directory(), newIndexWriterConfig(random(), new MockAnalyzer(random())).setCodec(TestUtil.getDefaultCodec())); int docs = 1 + random().nextInt(100); @@ -591,7 +588,7 @@ public class StoreTests extends ESTestCase { public void testRenameFile() throws IOException { final ShardId shardId = new ShardId(new Index("index"), 1); DirectoryService directoryService = new LuceneManagedDirectoryService(random(), false); - Store store = new Store(shardId, Settings.EMPTY, directoryService, new DummyShardLock(shardId)); + Store store = new Store(shardId, INDEX_SETTINGS, directoryService, new DummyShardLock(shardId)); { IndexOutput output = store.directory().createOutput("foo.bar", IOContext.DEFAULT); int iters = scaledRandomIntBetween(10, 100); @@ -798,7 +795,7 @@ public class StoreTests extends ESTestCase { } public LuceneManagedDirectoryService(Random random, boolean preventDoubleWrite) { - super(new ShardId("fake", 1), Settings.EMPTY); + super(new ShardId(INDEX_SETTINGS.getIndex(), 1), INDEX_SETTINGS); dir = StoreTests.newDirectory(random); if (dir instanceof MockDirectoryWrapper) { ((MockDirectoryWrapper) dir).setPreventDoubleWrite(preventDoubleWrite); @@ -863,7 +860,7 @@ public class StoreTests extends ESTestCase { iwc.setUseCompoundFile(random.nextBoolean()); final ShardId shardId = new ShardId(new Index("index"), 1); DirectoryService directoryService = new LuceneManagedDirectoryService(random); - Store store = new Store(shardId, Settings.EMPTY, directoryService, new DummyShardLock(shardId)); + Store store = new Store(shardId, INDEX_SETTINGS, directoryService, new DummyShardLock(shardId)); IndexWriter writer = new IndexWriter(store.directory(), iwc); final boolean lotsOfSegments = rarely(random); for (Document d : docs) { @@ -893,7 +890,7 @@ public class StoreTests extends ESTestCase { iwc.setUseCompoundFile(random.nextBoolean()); final ShardId shardId = new ShardId(new Index("index"), 1); DirectoryService directoryService = new LuceneManagedDirectoryService(random); - store = new Store(shardId, Settings.EMPTY, directoryService, new DummyShardLock(shardId)); + store = new Store(shardId, INDEX_SETTINGS, directoryService, new DummyShardLock(shardId)); IndexWriter writer = new IndexWriter(store.directory(), iwc); final boolean lotsOfSegments = rarely(random); for (Document d : docs) { @@ -991,7 +988,7 @@ public class StoreTests extends ESTestCase { public void testCleanupFromSnapshot() throws IOException { final ShardId shardId = new ShardId(new Index("index"), 1); DirectoryService directoryService = new LuceneManagedDirectoryService(random()); - Store store = new Store(shardId, Settings.EMPTY, directoryService, new DummyShardLock(shardId)); + Store store = new Store(shardId, INDEX_SETTINGS, directoryService, new DummyShardLock(shardId)); // this time random codec.... IndexWriterConfig indexWriterConfig = newIndexWriterConfig(random(), new MockAnalyzer(random())).setCodec(TestUtil.getDefaultCodec()); // we keep all commits and that allows us clean based on multiple snapshots @@ -1105,7 +1102,7 @@ public class StoreTests extends ESTestCase { final ShardId shardId = new ShardId(new Index("index"), 1); DirectoryService directoryService = new LuceneManagedDirectoryService(random()); - Store store = new Store(shardId, Settings.EMPTY, directoryService, new DummyShardLock(shardId)); + Store store = new Store(shardId, INDEX_SETTINGS, directoryService, new DummyShardLock(shardId)); for (String file : metaDataMap.keySet()) { try (IndexOutput output = store.directory().createOutput(file, IOContext.DEFAULT)) { BytesRef bytesRef = new BytesRef(TestUtil.randomRealisticUnicodeString(random(), 10, 1024)); @@ -1125,7 +1122,7 @@ public class StoreTests extends ESTestCase { final AtomicInteger count = new AtomicInteger(0); final ShardLock lock = new DummyShardLock(shardId); - Store store = new Store(shardId, Settings.EMPTY, directoryService, lock, new Store.OnClose() { + Store store = new Store(shardId, INDEX_SETTINGS, directoryService, lock, new Store.OnClose() { @Override public void handle(ShardLock theLock) { assertEquals(shardId, theLock.getShardId()); @@ -1146,8 +1143,10 @@ public class StoreTests extends ESTestCase { public void testStoreStats() throws IOException { final ShardId shardId = new ShardId(new Index("index"), 1); DirectoryService directoryService = new LuceneManagedDirectoryService(random()); - Settings settings = Settings.builder().put(Store.INDEX_STORE_STATS_REFRESH_INTERVAL, TimeValue.timeValueMinutes(0)).build(); - Store store = new Store(shardId, settings, directoryService, new DummyShardLock(shardId)); + Settings settings = Settings.builder() + .put(IndexMetaData.SETTING_VERSION_CREATED, org.elasticsearch.Version.CURRENT) + .put(Store.INDEX_STORE_STATS_REFRESH_INTERVAL, TimeValue.timeValueMinutes(0)).build(); + Store store = new Store(shardId, new IndexSettings(new Index("index"), settings, Collections.EMPTY_LIST), directoryService, new DummyShardLock(shardId)); long initialStoreSize = 0; for (String extraFiles : store.directory().listAll()) { assertTrue("expected extraFS file but got: " + extraFiles, extraFiles.startsWith("extra")); @@ -1238,7 +1237,7 @@ public class StoreTests extends ESTestCase { public void testUserDataRead() throws IOException { final ShardId shardId = new ShardId(new Index("index"), 1); DirectoryService directoryService = new LuceneManagedDirectoryService(random()); - Store store = new Store(shardId, Settings.EMPTY, directoryService, new DummyShardLock(shardId)); + Store store = new Store(shardId, INDEX_SETTINGS, directoryService, new DummyShardLock(shardId)); IndexWriterConfig config = newIndexWriterConfig(random(), new MockAnalyzer(random())).setCodec(TestUtil.getDefaultCodec()); SnapshotDeletionPolicy deletionPolicy = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy()); config.setIndexDeletionPolicy(deletionPolicy); @@ -1292,7 +1291,7 @@ public class StoreTests extends ESTestCase { IndexWriterConfig iwc = newIndexWriterConfig(); final ShardId shardId = new ShardId(new Index("index"), 1); DirectoryService directoryService = new LuceneManagedDirectoryService(random()); - Store store = new Store(shardId, Settings.EMPTY, directoryService, new DummyShardLock(shardId)); + Store store = new Store(shardId, INDEX_SETTINGS, directoryService, new DummyShardLock(shardId)); IndexWriter writer = new IndexWriter(store.directory(), iwc); int numDocs = 1 + random().nextInt(10); @@ -1347,7 +1346,7 @@ public class StoreTests extends ESTestCase { assertTrue(Store.canOpenIndex(logger, tempDir)); final ShardId shardId = new ShardId(new Index("index"), 1); - DirectoryService directoryService = new DirectoryService(shardId, Settings.EMPTY) { + DirectoryService directoryService = new DirectoryService(shardId, INDEX_SETTINGS) { @Override public long throttleTimeInNanos() { return 0; @@ -1358,7 +1357,7 @@ public class StoreTests extends ESTestCase { return dir; } }; - Store store = new Store(shardId, Settings.EMPTY, directoryService, new DummyShardLock(shardId)); + Store store = new Store(shardId, INDEX_SETTINGS, directoryService, new DummyShardLock(shardId)); store.markStoreCorrupted(new CorruptIndexException("foo", "bar")); assertFalse(Store.canOpenIndex(logger, tempDir)); store.close(); @@ -1367,7 +1366,7 @@ public class StoreTests extends ESTestCase { public void testDeserializeCorruptionException() throws IOException { final ShardId shardId = new ShardId(new Index("index"), 1); final Directory dir = new RAMDirectory(); // I use ram dir to prevent that virusscanner being a PITA - DirectoryService directoryService = new DirectoryService(shardId, Settings.EMPTY) { + DirectoryService directoryService = new DirectoryService(shardId, INDEX_SETTINGS) { @Override public long throttleTimeInNanos() { return 0; @@ -1378,7 +1377,7 @@ public class StoreTests extends ESTestCase { return dir; } }; - Store store = new Store(shardId, Settings.EMPTY, directoryService, new DummyShardLock(shardId)); + Store store = new Store(shardId, INDEX_SETTINGS, directoryService, new DummyShardLock(shardId)); CorruptIndexException ex = new CorruptIndexException("foo", "bar"); store.markStoreCorrupted(ex); try { @@ -1407,7 +1406,7 @@ public class StoreTests extends ESTestCase { public void testCanReadOldCorruptionMarker() throws IOException { final ShardId shardId = new ShardId(new Index("index"), 1); final Directory dir = new RAMDirectory(); // I use ram dir to prevent that virusscanner being a PITA - DirectoryService directoryService = new DirectoryService(shardId, Settings.EMPTY) { + DirectoryService directoryService = new DirectoryService(shardId, INDEX_SETTINGS) { @Override public long throttleTimeInNanos() { return 0; @@ -1418,7 +1417,7 @@ public class StoreTests extends ESTestCase { return dir; } }; - Store store = new Store(shardId, Settings.EMPTY, directoryService, new DummyShardLock(shardId)); + Store store = new Store(shardId, INDEX_SETTINGS, directoryService, new DummyShardLock(shardId)); CorruptIndexException exception = new CorruptIndexException("foo", "bar"); String uuid = Store.CORRUPTED + Strings.randomBase64UUID(); diff --git a/core/src/test/java/org/elasticsearch/index/translog/BufferedTranslogTests.java b/core/src/test/java/org/elasticsearch/index/translog/BufferedTranslogTests.java index 2e5375efd51..b24db82bcb1 100644 --- a/core/src/test/java/org/elasticsearch/index/translog/BufferedTranslogTests.java +++ b/core/src/test/java/org/elasticsearch/index/translog/BufferedTranslogTests.java @@ -19,12 +19,15 @@ package org.elasticsearch.index.translog; +import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.index.IndexSettings; import java.io.IOException; import java.nio.file.Path; +import java.util.Collections; /** * @@ -36,8 +39,9 @@ public class BufferedTranslogTests extends TranslogTests { Settings build = Settings.settingsBuilder() .put("index.translog.fs.type", TranslogWriter.Type.BUFFERED.name()) .put("index.translog.fs.buffer_size", 10 + randomInt(128 * 1024), ByteSizeUnit.BYTES) + .put(IndexMetaData.SETTING_VERSION_CREATED, org.elasticsearch.Version.CURRENT) .build(); - TranslogConfig translogConfig = new TranslogConfig(shardId, path, build, Translog.Durabilty.REQUEST, BigArrays.NON_RECYCLING_INSTANCE, null); + TranslogConfig translogConfig = new TranslogConfig(shardId, path, new IndexSettings(shardId.index(), build, Collections.EMPTY_LIST), Translog.Durabilty.REQUEST, BigArrays.NON_RECYCLING_INSTANCE, null); return new Translog(translogConfig); } } diff --git a/core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java b/core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java index 49a6f42b085..2dbabba2e6a 100644 --- a/core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java +++ b/core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java @@ -28,6 +28,7 @@ import org.apache.lucene.store.ByteArrayDataOutput; import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.LuceneTestCase; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.io.FileSystemUtils; import org.elasticsearch.common.io.stream.BytesStreamOutput; @@ -37,6 +38,7 @@ import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.concurrent.AbstractRunnable; import org.elasticsearch.common.util.concurrent.ConcurrentCollections; import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.VersionType; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.test.ESTestCase; @@ -70,7 +72,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; -import java.util.regex.Pattern; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; @@ -83,8 +84,6 @@ import static org.hamcrest.Matchers.greaterThanOrEqualTo; @LuceneTestCase.SuppressFileSystems("ExtrasFS") public class TranslogTests extends ESTestCase { - private static final Pattern PARSE_LEGACY_ID_PATTERN = Pattern.compile("^" + Translog.TRANSLOG_FILE_PREFIX + "(\\d+)((\\.recovering))?$"); - protected final ShardId shardId = new ShardId(new Index("index"), 1); protected Translog translog; @@ -129,8 +128,9 @@ public class TranslogTests extends ESTestCase { protected Translog create(Path path) throws IOException { Settings build = Settings.settingsBuilder() .put(TranslogConfig.INDEX_TRANSLOG_FS_TYPE, TranslogWriter.Type.SIMPLE.name()) + .put(IndexMetaData.SETTING_VERSION_CREATED, org.elasticsearch.Version.CURRENT) .build(); - TranslogConfig translogConfig = new TranslogConfig(shardId, path, build, Translog.Durabilty.REQUEST, BigArrays.NON_RECYCLING_INSTANCE, null); + TranslogConfig translogConfig = new TranslogConfig(shardId, path, new IndexSettings(shardId.index(), build, Collections.EMPTY_LIST), Translog.Durabilty.REQUEST, BigArrays.NON_RECYCLING_INSTANCE, null); return new Translog(translogConfig); } diff --git a/core/src/test/java/org/elasticsearch/indices/IndicesLifecycleListenerIT.java b/core/src/test/java/org/elasticsearch/indices/IndicesLifecycleListenerIT.java index 39284ff2929..8de3af25827 100644 --- a/core/src/test/java/org/elasticsearch/indices/IndicesLifecycleListenerIT.java +++ b/core/src/test/java/org/elasticsearch/indices/IndicesLifecycleListenerIT.java @@ -30,7 +30,6 @@ import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.shard.IndexEventListener; import org.elasticsearch.index.shard.IndexShard; import org.elasticsearch.index.shard.IndexShardState; @@ -40,7 +39,6 @@ import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.ESIntegTestCase.Scope; import org.elasticsearch.test.MockIndexEventListener; -import org.elasticsearch.test.transport.MockTransportService; import org.hamcrest.Matchers; import java.util.Collection; @@ -84,7 +82,7 @@ public class IndicesLifecycleListenerIT extends ESIntegTestCase { IndexEventListener listener = new IndexEventListener() { @Override - public void beforeIndexAddedToCluster(Index index, @IndexSettings Settings indexSettings) { + public void beforeIndexAddedToCluster(Index index, Settings indexSettings) { beforeAddedCount.incrementAndGet(); if (indexSettings.getAsBoolean("index.fail", false)) { throw new ElasticsearchException("failing on purpose"); @@ -92,7 +90,7 @@ public class IndicesLifecycleListenerIT extends ESIntegTestCase { } @Override - public void beforeIndexCreated(Index index, @IndexSettings Settings indexSettings) { + public void beforeIndexCreated(Index index, Settings indexSettings) { allCreatedCount.incrementAndGet(); } }; @@ -128,7 +126,7 @@ public class IndicesLifecycleListenerIT extends ESIntegTestCase { String node2 = internalCluster().startNode(); internalCluster().getInstance(MockIndexEventListener.TestEventListener.class, node2).setNewDelegate(new IndexShardStateChangeListener() { @Override - public void beforeIndexCreated(Index index, @IndexSettings Settings indexSettings) { + public void beforeIndexCreated(Index index, Settings indexSettings) { throw new RuntimeException("FAIL"); } }); @@ -253,7 +251,7 @@ public class IndicesLifecycleListenerIT extends ESIntegTestCase { } @Override - public void beforeIndexCreated(Index index, @IndexSettings Settings indexSettings) { + public void beforeIndexCreated(Index index, Settings indexSettings) { this.creationSettings = indexSettings; if (indexSettings.getAsBoolean("index.fail", false)) { throw new ElasticsearchException("failing on purpose"); @@ -261,7 +259,7 @@ public class IndicesLifecycleListenerIT extends ESIntegTestCase { } @Override - public void afterIndexShardClosed(ShardId shardId, @Nullable IndexShard indexShard, @IndexSettings Settings indexSettings) { + public void afterIndexShardClosed(ShardId shardId, @Nullable IndexShard indexShard, Settings indexSettings) { this.afterCloseSettings = indexSettings; } diff --git a/core/src/test/java/org/elasticsearch/indices/IndicesLifecycleListenerSingleNodeTests.java b/core/src/test/java/org/elasticsearch/indices/IndicesLifecycleListenerSingleNodeTests.java index 35f65dc57be..189dfdd5321 100644 --- a/core/src/test/java/org/elasticsearch/indices/IndicesLifecycleListenerSingleNodeTests.java +++ b/core/src/test/java/org/elasticsearch/indices/IndicesLifecycleListenerSingleNodeTests.java @@ -28,7 +28,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.DummyTransportAddress; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexService; -import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.shard.IndexEventListener; import org.elasticsearch.index.shard.IndexShard; import org.elasticsearch.index.shard.ShardId; @@ -52,7 +51,7 @@ public class IndicesLifecycleListenerSingleNodeTests extends ESSingleNodeTestCas final AtomicInteger counter = new AtomicInteger(1); IndexEventListener countingListener = new IndexEventListener() { @Override - public void afterIndexClosed(Index index, @IndexSettings Settings indexSettings) { + public void afterIndexClosed(Index index, Settings indexSettings) { assertEquals(counter.get(), 5); counter.incrementAndGet(); } @@ -64,7 +63,7 @@ public class IndicesLifecycleListenerSingleNodeTests extends ESSingleNodeTestCas } @Override - public void afterIndexDeleted(Index index, @IndexSettings Settings indexSettings) { + public void afterIndexDeleted(Index index, Settings indexSettings) { assertEquals(counter.get(), 6); counter.incrementAndGet(); } diff --git a/core/src/test/java/org/elasticsearch/indices/IndicesServiceTests.java b/core/src/test/java/org/elasticsearch/indices/IndicesServiceTests.java index 995deaca10c..e1811b01a17 100644 --- a/core/src/test/java/org/elasticsearch/indices/IndicesServiceTests.java +++ b/core/src/test/java/org/elasticsearch/indices/IndicesServiceTests.java @@ -142,7 +142,7 @@ public class IndicesServiceTests extends ESSingleNodeTestCase { ShardPath shardPath = ShardPath.loadShardPath(logger, getNodeEnvironment(), new ShardId(test.index(), 0), test.getIndexSettings()); assertEquals(shardPath, path); try { - indicesService.processPendingDeletes(test.index(), test.getIndexSettings(), new TimeValue(0, TimeUnit.MILLISECONDS)); + indicesService.processPendingDeletes(test.index(), test.getIndexSettings().getSettings(), new TimeValue(0, TimeUnit.MILLISECONDS)); fail("can't get lock"); } catch (LockObtainFailedException ex) { @@ -151,13 +151,13 @@ public class IndicesServiceTests extends ESSingleNodeTestCase { int numPending = 1; if (randomBoolean()) { - indicesService.addPendingDelete(new ShardId(test.index(), 0), test.getIndexSettings()); + indicesService.addPendingDelete(new ShardId(test.index(), 0), test.getIndexSettings().getSettings()); } else { if (randomBoolean()) { numPending++; - indicesService.addPendingDelete(new ShardId(test.index(), 0), test.getIndexSettings()); + indicesService.addPendingDelete(new ShardId(test.index(), 0), test.getIndexSettings().getSettings()); } - indicesService.addPendingDelete(test.index(), test.getIndexSettings()); + indicesService.addPendingDelete(test.index(), test.getIndexSettings().getSettings()); } assertAcked(client().admin().indices().prepareClose("test")); assertTrue(path.exists()); @@ -165,17 +165,17 @@ public class IndicesServiceTests extends ESSingleNodeTestCase { assertEquals(indicesService.numPendingDeletes(test.index()), numPending); // shard lock released... we can now delete - indicesService.processPendingDeletes(test.index(), test.getIndexSettings(), new TimeValue(0, TimeUnit.MILLISECONDS)); + indicesService.processPendingDeletes(test.index(), test.getIndexSettings().getSettings(), new TimeValue(0, TimeUnit.MILLISECONDS)); assertEquals(indicesService.numPendingDeletes(test.index()), 0); assertFalse(path.exists()); if (randomBoolean()) { - indicesService.addPendingDelete(new ShardId(test.index(), 0), test.getIndexSettings()); - indicesService.addPendingDelete(new ShardId(test.index(), 1), test.getIndexSettings()); - indicesService.addPendingDelete(new ShardId("bogus", 1), test.getIndexSettings()); + indicesService.addPendingDelete(new ShardId(test.index(), 0), test.getIndexSettings().getSettings()); + indicesService.addPendingDelete(new ShardId(test.index(), 1), test.getIndexSettings().getSettings()); + indicesService.addPendingDelete(new ShardId("bogus", 1), test.getIndexSettings().getSettings()); assertEquals(indicesService.numPendingDeletes(test.index()), 2); // shard lock released... we can now delete - indicesService.processPendingDeletes(test.index(), test.getIndexSettings(), new TimeValue(0, TimeUnit.MILLISECONDS)); + indicesService.processPendingDeletes(test.index(), test.getIndexSettings().getSettings(), new TimeValue(0, TimeUnit.MILLISECONDS)); assertEquals(indicesService.numPendingDeletes(test.index()), 0); } assertAcked(client().admin().indices().prepareOpen("test")); diff --git a/core/src/test/java/org/elasticsearch/indices/recovery/RecoverySourceHandlerTests.java b/core/src/test/java/org/elasticsearch/indices/recovery/RecoverySourceHandlerTests.java index d658b07de4a..59d839911fa 100644 --- a/core/src/test/java/org/elasticsearch/indices/recovery/RecoverySourceHandlerTests.java +++ b/core/src/test/java/org/elasticsearch/indices/recovery/RecoverySourceHandlerTests.java @@ -27,12 +27,14 @@ import org.apache.lucene.store.*; import org.apache.lucene.util.IOUtils; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.Version; +import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.io.FileSystemUtils; import org.elasticsearch.common.lucene.store.IndexOutputOutputStream; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.DummyTransportAddress; import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.store.DirectoryService; import org.elasticsearch.index.store.Store; @@ -43,7 +45,6 @@ import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.CorruptionUtils; import java.io.IOException; -import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.Collections; @@ -53,8 +54,8 @@ import java.util.concurrent.atomic.AtomicBoolean; import static org.hamcrest.Matchers.is; public class RecoverySourceHandlerTests extends ESTestCase { - - private final ShardId shardId = new ShardId(new Index("index"), 1); + private static final IndexSettings INDEX_SETTINGS = new IndexSettings(new Index("index"), Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, org.elasticsearch.Version.CURRENT).build(), Collections.emptyList()); + private final ShardId shardId = new ShardId(INDEX_SETTINGS.getIndex(), 1); private final NodeSettingsService service = new NodeSettingsService(Settings.EMPTY); public void testSendFiles() throws Throwable { @@ -233,7 +234,7 @@ public class RecoverySourceHandlerTests extends ESTestCase { return newStore(path, true); } private Store newStore(Path path, boolean checkIndex) throws IOException { - DirectoryService directoryService = new DirectoryService(shardId, Settings.EMPTY) { + DirectoryService directoryService = new DirectoryService(shardId, INDEX_SETTINGS) { @Override public long throttleTimeInNanos() { return 0; @@ -248,7 +249,7 @@ public class RecoverySourceHandlerTests extends ESTestCase { return baseDirectoryWrapper; } }; - return new Store(shardId, Settings.EMPTY, directoryService, new DummyShardLock(shardId)); + return new Store(shardId, INDEX_SETTINGS, directoryService, new DummyShardLock(shardId)); } diff --git a/core/src/test/java/org/elasticsearch/test/ESTokenStreamTestCase.java b/core/src/test/java/org/elasticsearch/test/ESTokenStreamTestCase.java index 29a1a3362d9..ed54ae60fbd 100644 --- a/core/src/test/java/org/elasticsearch/test/ESTokenStreamTestCase.java +++ b/core/src/test/java/org/elasticsearch/test/ESTokenStreamTestCase.java @@ -54,4 +54,5 @@ public abstract class ESTokenStreamTestCase extends BaseTokenStreamTestCase { public Settings.Builder newAnalysisSettingsBuilder() { return Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT); } + } diff --git a/core/src/main/java/org/elasticsearch/index/settings/IndexSettingsModule.java b/core/src/test/java/org/elasticsearch/test/IndexNameAndSettingsModule.java similarity index 70% rename from core/src/main/java/org/elasticsearch/index/settings/IndexSettingsModule.java rename to core/src/test/java/org/elasticsearch/test/IndexNameAndSettingsModule.java index d4a0637358f..dfe190f03b8 100644 --- a/core/src/main/java/org/elasticsearch/index/settings/IndexSettingsModule.java +++ b/core/src/test/java/org/elasticsearch/test/IndexNameAndSettingsModule.java @@ -16,31 +16,27 @@ * specific language governing permissions and limitations * under the License. */ - -package org.elasticsearch.index.settings; +package org.elasticsearch.test; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; -/** - * - */ -public class IndexSettingsModule extends AbstractModule { +import java.util.Collections; + +public class IndexNameAndSettingsModule extends AbstractModule { private final Index index; - private final Settings settings; - public IndexSettingsModule(Index index, Settings settings) { - this.index = index; + public IndexNameAndSettingsModule(Index index, Settings settings) { this.settings = settings; - } + this.index = index; + } @Override protected void configure() { - IndexSettingsService indexSettingsService = new IndexSettingsService(index, settings); - bind(IndexSettingsService.class).toInstance(indexSettingsService); - bind(Settings.class).annotatedWith(IndexSettings.class).toProvider(new IndexSettingsProvider(indexSettingsService)); + bind(IndexSettings.class).toInstance(new IndexSettings(index, settings, Collections.EMPTY_LIST)); } } diff --git a/core/src/test/java/org/elasticsearch/test/InternalTestCluster.java b/core/src/test/java/org/elasticsearch/test/InternalTestCluster.java index 19ded47bdbc..4bbde1cdbe4 100644 --- a/core/src/test/java/org/elasticsearch/test/InternalTestCluster.java +++ b/core/src/test/java/org/elasticsearch/test/InternalTestCluster.java @@ -1734,7 +1734,7 @@ public final class InternalTestCluster extends TestCluster { ClusterService clusterService = getInstanceFromNode(ClusterService.class, node); IndexService indexService = indicesService.indexService(index); if (indexService != null) { - assertThat(indexService.settingsService().getSettings().getAsInt(IndexMetaData.SETTING_NUMBER_OF_SHARDS, -1), greaterThan(shard)); + assertThat(indexService.getIndexSettings().getSettings().getAsInt(IndexMetaData.SETTING_NUMBER_OF_SHARDS, -1), greaterThan(shard)); OperationRouting operationRouting = getInstanceFromNode(OperationRouting.class, node); while (true) { String routing = RandomStrings.randomAsciiOfLength(random, 10); diff --git a/core/src/test/java/org/elasticsearch/test/store/MockFSDirectoryService.java b/core/src/test/java/org/elasticsearch/test/store/MockFSDirectoryService.java index c897011d0e9..c3ba399def7 100644 --- a/core/src/test/java/org/elasticsearch/test/store/MockFSDirectoryService.java +++ b/core/src/test/java/org/elasticsearch/test/store/MockFSDirectoryService.java @@ -27,14 +27,12 @@ import org.apache.lucene.index.IndexWriter; import org.apache.lucene.store.*; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.TestRuleMarkFailure; -import org.elasticsearch.cluster.metadata.IndexMetaData; -import org.elasticsearch.common.Nullable; import org.elasticsearch.common.inject.Inject; 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.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.shard.*; import org.elasticsearch.index.store.FsDirectoryService; import org.elasticsearch.index.store.IndexStore; @@ -69,8 +67,9 @@ public class MockFSDirectoryService extends FsDirectoryService { private final boolean crashIndex; @Inject - public MockFSDirectoryService(@IndexSettings Settings indexSettings, IndexStore indexStore, final IndicesService service, final ShardPath path) { - super(indexSettings, indexStore, path); + public MockFSDirectoryService(IndexSettings idxSettings, IndexStore indexStore, final IndicesService service, final ShardPath path) { + super(idxSettings, indexStore, path); + Settings indexSettings = idxSettings.getSettings(); final long seed = indexSettings.getAsLong(ESIntegTestCase.SETTING_INDEX_SEED, 0l); this.random = new Random(seed); @@ -176,7 +175,7 @@ public class MockFSDirectoryService extends FsDirectoryService { Settings.Builder builder = Settings.settingsBuilder(); builder.put(indexSettings); builder.put(IndexStoreModule.STORE_TYPE, RandomPicks.randomFrom(random, IndexStoreModule.Type.values()).getSettingsKey()); - return new FsDirectoryService(builder.build(), indexStore, path); + return new FsDirectoryService(new IndexSettings(shardId.index(), builder.build(), Collections.EMPTY_LIST), indexStore, path); } public static final class ElasticsearchMockDirectoryWrapper extends MockDirectoryWrapper { diff --git a/core/src/test/java/org/elasticsearch/test/store/MockFSIndexStore.java b/core/src/test/java/org/elasticsearch/test/store/MockFSIndexStore.java index cc9cb696c58..a94a71d1325 100644 --- a/core/src/test/java/org/elasticsearch/test/store/MockFSIndexStore.java +++ b/core/src/test/java/org/elasticsearch/test/store/MockFSIndexStore.java @@ -25,10 +25,8 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.IndexModule; -import org.elasticsearch.index.settings.IndexSettings; -import org.elasticsearch.index.settings.IndexSettingsService; import org.elasticsearch.index.shard.*; import org.elasticsearch.index.store.DirectoryService; import org.elasticsearch.index.store.IndexStore; @@ -37,7 +35,7 @@ import org.elasticsearch.indices.IndicesService; import org.elasticsearch.indices.store.IndicesStore; import org.elasticsearch.plugins.Plugin; -import java.util.EnumSet; +import java.util.*; public class MockFSIndexStore extends IndexStore { @@ -72,9 +70,9 @@ public class MockFSIndexStore extends IndexStore { } @Inject - public MockFSIndexStore(Index index, @IndexSettings Settings indexSettings, IndexSettingsService indexSettingsService, + public MockFSIndexStore(IndexSettings indexSettings, IndicesStore indicesStore, IndicesService indicesService) { - super(index, indexSettings, indexSettingsService, indicesStore); + super(indexSettings, indicesStore); this.indicesService = indicesService; } @@ -86,11 +84,23 @@ public class MockFSIndexStore extends IndexStore { IndexShardState.STARTED, IndexShardState.RELOCATED, IndexShardState.POST_RECOVERY ); private static final class Listener implements IndexEventListener { + + private final Map shardSet = Collections.synchronizedMap(new IdentityHashMap<>()); + @Override + public void afterIndexShardClosed(ShardId shardId, @Nullable IndexShard indexShard, Settings indexSettings) { + if (indexShard != null) { + Boolean remove = shardSet.remove(indexShard); + if (remove == Boolean.TRUE) { + ESLogger logger = Loggers.getLogger(getClass(), indexShard.indexSettings(), indexShard.shardId()); + MockFSDirectoryService.checkIndex(logger, indexShard.store(), indexShard.shardId()); + } + } + } + @Override public void indexShardStateChanged(IndexShard indexShard, @Nullable IndexShardState previousState, IndexShardState currentState, @Nullable String reason) { if (currentState == IndexShardState.CLOSED && validCheckIndexStates.contains(previousState) && IndexMetaData.isOnSharedFilesystem(indexShard.indexSettings()) == false) { - ESLogger logger = Loggers.getLogger(getClass(), indexShard.indexSettings(), indexShard.shardId()); - MockFSDirectoryService.checkIndex(logger, indexShard.store(), indexShard.shardId()); + shardSet.put(indexShard, Boolean.TRUE); } } diff --git a/plugins/analysis-icu/src/main/java/org/elasticsearch/index/analysis/IcuCollationTokenFilterFactory.java b/plugins/analysis-icu/src/main/java/org/elasticsearch/index/analysis/IcuCollationTokenFilterFactory.java index ca4be807278..6a9fb44cf2b 100644 --- a/plugins/analysis-icu/src/main/java/org/elasticsearch/index/analysis/IcuCollationTokenFilterFactory.java +++ b/plugins/analysis-icu/src/main/java/org/elasticsearch/index/analysis/IcuCollationTokenFilterFactory.java @@ -28,8 +28,7 @@ import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.io.Streams; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; import java.io.IOException; import java.nio.charset.Charset; @@ -49,8 +48,8 @@ public class IcuCollationTokenFilterFactory extends AbstractTokenFilterFactory { private final Collator collator; @Inject - public IcuCollationTokenFilterFactory(Index index, @IndexSettings Settings indexSettings, Environment environment, @Assisted String name, @Assisted Settings settings) { - super(index, indexSettings, name, settings); + public IcuCollationTokenFilterFactory(IndexSettings indexSettings, Environment environment, @Assisted String name, @Assisted Settings settings) { + super(indexSettings, name, settings); Collator collator; String rules = settings.get("rules"); diff --git a/plugins/analysis-icu/src/main/java/org/elasticsearch/index/analysis/IcuFoldingTokenFilterFactory.java b/plugins/analysis-icu/src/main/java/org/elasticsearch/index/analysis/IcuFoldingTokenFilterFactory.java index 7abfd702ac3..aac49ec8217 100644 --- a/plugins/analysis-icu/src/main/java/org/elasticsearch/index/analysis/IcuFoldingTokenFilterFactory.java +++ b/plugins/analysis-icu/src/main/java/org/elasticsearch/index/analysis/IcuFoldingTokenFilterFactory.java @@ -24,12 +24,11 @@ import org.apache.lucene.analysis.icu.ICUFoldingFilter; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; import com.ibm.icu.text.FilteredNormalizer2; import com.ibm.icu.text.Normalizer2; import com.ibm.icu.text.UnicodeSet; +import org.elasticsearch.index.IndexSettings; /** @@ -46,8 +45,8 @@ import com.ibm.icu.text.UnicodeSet; public class IcuFoldingTokenFilterFactory extends AbstractTokenFilterFactory { private final String unicodeSetFilter; - @Inject public IcuFoldingTokenFilterFactory(Index index, @IndexSettings Settings indexSettings, @Assisted String name, @Assisted Settings settings) { - super(index, indexSettings, name, settings); + @Inject public IcuFoldingTokenFilterFactory(IndexSettings indexSettings, @Assisted String name, @Assisted Settings settings) { + super(indexSettings, name, settings); this.unicodeSetFilter = settings.get("unicodeSetFilter"); } diff --git a/plugins/analysis-icu/src/main/java/org/elasticsearch/index/analysis/IcuNormalizerCharFilterFactory.java b/plugins/analysis-icu/src/main/java/org/elasticsearch/index/analysis/IcuNormalizerCharFilterFactory.java index d8fec090a3f..a3ae823cb74 100644 --- a/plugins/analysis-icu/src/main/java/org/elasticsearch/index/analysis/IcuNormalizerCharFilterFactory.java +++ b/plugins/analysis-icu/src/main/java/org/elasticsearch/index/analysis/IcuNormalizerCharFilterFactory.java @@ -25,8 +25,7 @@ import org.apache.lucene.analysis.icu.ICUNormalizer2CharFilter; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; import java.io.Reader; @@ -44,8 +43,8 @@ public class IcuNormalizerCharFilterFactory extends AbstractCharFilterFactory { @Inject - public IcuNormalizerCharFilterFactory(Index index, @IndexSettings Settings indexSettings, @Assisted String name, @Assisted Settings settings) { - super(index, indexSettings, name); + public IcuNormalizerCharFilterFactory(IndexSettings indexSettings, @Assisted String name, @Assisted Settings settings) { + super(indexSettings, name); this.name = settings.get("name", "nfkc_cf"); String mode = settings.get("mode"); if (!"compose".equals(mode) && !"decompose".equals(mode)) { diff --git a/plugins/analysis-icu/src/main/java/org/elasticsearch/index/analysis/IcuNormalizerTokenFilterFactory.java b/plugins/analysis-icu/src/main/java/org/elasticsearch/index/analysis/IcuNormalizerTokenFilterFactory.java index c27fc1d16a9..ebd68615ee1 100644 --- a/plugins/analysis-icu/src/main/java/org/elasticsearch/index/analysis/IcuNormalizerTokenFilterFactory.java +++ b/plugins/analysis-icu/src/main/java/org/elasticsearch/index/analysis/IcuNormalizerTokenFilterFactory.java @@ -24,8 +24,7 @@ import org.apache.lucene.analysis.TokenStream; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; /** @@ -39,8 +38,8 @@ public class IcuNormalizerTokenFilterFactory extends AbstractTokenFilterFactory private final String name; @Inject - public IcuNormalizerTokenFilterFactory(Index index, @IndexSettings Settings indexSettings, @Assisted String name, @Assisted Settings settings) { - super(index, indexSettings, name, settings); + public IcuNormalizerTokenFilterFactory(IndexSettings indexSettings, @Assisted String name, @Assisted Settings settings) { + super(indexSettings, name, settings); this.name = settings.get("name", "nfkc_cf"); } diff --git a/plugins/analysis-icu/src/main/java/org/elasticsearch/index/analysis/IcuTokenizerFactory.java b/plugins/analysis-icu/src/main/java/org/elasticsearch/index/analysis/IcuTokenizerFactory.java index fe20d93069e..c5c220e51b9 100644 --- a/plugins/analysis-icu/src/main/java/org/elasticsearch/index/analysis/IcuTokenizerFactory.java +++ b/plugins/analysis-icu/src/main/java/org/elasticsearch/index/analysis/IcuTokenizerFactory.java @@ -24,18 +24,15 @@ import org.apache.lucene.analysis.icu.segmentation.ICUTokenizer; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; - -import java.io.Reader; +import org.elasticsearch.index.IndexSettings; /** */ public class IcuTokenizerFactory extends AbstractTokenizerFactory { @Inject - public IcuTokenizerFactory(Index index, @IndexSettings Settings indexSettings, @Assisted String name, @Assisted Settings settings) { - super(index, indexSettings, name, settings); + public IcuTokenizerFactory(IndexSettings indexSettings, @Assisted String name, @Assisted Settings settings) { + super(indexSettings, name, settings); } @Override diff --git a/plugins/analysis-icu/src/main/java/org/elasticsearch/index/analysis/IcuTransformTokenFilterFactory.java b/plugins/analysis-icu/src/main/java/org/elasticsearch/index/analysis/IcuTransformTokenFilterFactory.java index 8ef48539daf..9be90ba2ab4 100644 --- a/plugins/analysis-icu/src/main/java/org/elasticsearch/index/analysis/IcuTransformTokenFilterFactory.java +++ b/plugins/analysis-icu/src/main/java/org/elasticsearch/index/analysis/IcuTransformTokenFilterFactory.java @@ -25,8 +25,7 @@ import org.apache.lucene.analysis.icu.ICUTransformFilter; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; /** @@ -38,8 +37,8 @@ public class IcuTransformTokenFilterFactory extends AbstractTokenFilterFactory { private final Transliterator transliterator; @Inject - public IcuTransformTokenFilterFactory(Index index, @IndexSettings Settings indexSettings, @Assisted String name, @Assisted Settings settings) { - super(index, indexSettings, name, settings); + public IcuTransformTokenFilterFactory(IndexSettings indexSettings, @Assisted String name, @Assisted Settings settings) { + super(indexSettings, name, settings); this.id = settings.get("id", "Null"); String s = settings.get("dir", "forward"); this.dir = "forward".equals(s) ? Transliterator.FORWARD : Transliterator.REVERSE; diff --git a/plugins/analysis-icu/src/test/java/org/elasticsearch/index/analysis/AnalysisTestUtils.java b/plugins/analysis-icu/src/test/java/org/elasticsearch/index/analysis/AnalysisTestUtils.java index eceee3ef404..61122b74329 100644 --- a/plugins/analysis-icu/src/test/java/org/elasticsearch/index/analysis/AnalysisTestUtils.java +++ b/plugins/analysis-icu/src/test/java/org/elasticsearch/index/analysis/AnalysisTestUtils.java @@ -28,9 +28,8 @@ import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.env.Environment; import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexNameModule; -import org.elasticsearch.index.settings.IndexSettingsModule; import org.elasticsearch.indices.analysis.IndicesAnalysisService; +import org.elasticsearch.test.IndexNameAndSettingsModule; import static org.elasticsearch.common.settings.Settings.settingsBuilder; @@ -43,8 +42,7 @@ public class AnalysisTestUtils { .build(); Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings))).createInjector(); Injector injector = new ModulesBuilder().add( - new IndexSettingsModule(index, indexSettings), - new IndexNameModule(index), + new IndexNameAndSettingsModule(index, indexSettings), new AnalysisModule(settings, parentInjector.getInstance(IndicesAnalysisService.class)).addProcessor(new IcuAnalysisBinderProcessor())) .createChildInjector(parentInjector); diff --git a/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/index/analysis/JapaneseStopTokenFilterFactory.java b/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/index/analysis/JapaneseStopTokenFilterFactory.java index 951597111e5..8e574296a39 100644 --- a/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/index/analysis/JapaneseStopTokenFilterFactory.java +++ b/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/index/analysis/JapaneseStopTokenFilterFactory.java @@ -29,8 +29,7 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; import java.util.Map; import java.util.Set; @@ -47,8 +46,8 @@ public class JapaneseStopTokenFilterFactory extends AbstractTokenFilterFactory{ private final boolean removeTrailing; @Inject - public JapaneseStopTokenFilterFactory(Index index, @IndexSettings Settings indexSettings, Environment env, @Assisted String name, @Assisted Settings settings) { - super(index, indexSettings, name, settings); + public JapaneseStopTokenFilterFactory(IndexSettings indexSettings, Environment env, @Assisted String name, @Assisted Settings settings) { + super(indexSettings, name, settings); this.ignoreCase = settings.getAsBoolean("ignore_case", false); this.removeTrailing = settings.getAsBoolean("remove_trailing", true); this.stopWords = Analysis.parseWords(env, settings, "stopwords", JapaneseAnalyzer.getDefaultStopSet(), NAMED_STOP_WORDS, ignoreCase); diff --git a/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/index/analysis/KuromojiAnalyzerProvider.java b/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/index/analysis/KuromojiAnalyzerProvider.java index 43fd2f75a73..c6bf5df8b29 100644 --- a/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/index/analysis/KuromojiAnalyzerProvider.java +++ b/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/index/analysis/KuromojiAnalyzerProvider.java @@ -27,8 +27,7 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; import java.util.Set; @@ -39,8 +38,8 @@ public class KuromojiAnalyzerProvider extends AbstractIndexAnalyzerProvider stopWords = Analysis.parseStopWords(env, settings, JapaneseAnalyzer.getDefaultStopSet()); final JapaneseTokenizer.Mode mode = KuromojiTokenizerFactory.getMode(settings); final UserDictionary userDictionary = KuromojiTokenizerFactory.getUserDictionary(env, settings); diff --git a/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/index/analysis/KuromojiBaseFormFilterFactory.java b/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/index/analysis/KuromojiBaseFormFilterFactory.java index 0db43bd429a..7922aa966d2 100644 --- a/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/index/analysis/KuromojiBaseFormFilterFactory.java +++ b/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/index/analysis/KuromojiBaseFormFilterFactory.java @@ -24,14 +24,13 @@ import org.apache.lucene.analysis.ja.JapaneseBaseFormFilter; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; public class KuromojiBaseFormFilterFactory extends AbstractTokenFilterFactory { @Inject - public KuromojiBaseFormFilterFactory(Index index, @IndexSettings Settings indexSettings, @Assisted String name, @Assisted Settings settings) { - super(index, indexSettings, name, settings); + public KuromojiBaseFormFilterFactory(IndexSettings indexSettings, @Assisted String name, @Assisted Settings settings) { + super(indexSettings, name, settings); } @Override diff --git a/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/index/analysis/KuromojiIterationMarkCharFilterFactory.java b/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/index/analysis/KuromojiIterationMarkCharFilterFactory.java index 74b63c32afd..916a0091b9f 100644 --- a/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/index/analysis/KuromojiIterationMarkCharFilterFactory.java +++ b/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/index/analysis/KuromojiIterationMarkCharFilterFactory.java @@ -23,8 +23,7 @@ import org.apache.lucene.analysis.ja.JapaneseIterationMarkCharFilter; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; import java.io.Reader; @@ -34,9 +33,9 @@ public class KuromojiIterationMarkCharFilterFactory extends AbstractCharFilterFa private final boolean normalizeKana; @Inject - public KuromojiIterationMarkCharFilterFactory(Index index, @IndexSettings Settings indexSettings, + public KuromojiIterationMarkCharFilterFactory(IndexSettings indexSettings, @Assisted String name, @Assisted Settings settings) { - super(index, indexSettings, name); + super(indexSettings, name); normalizeKanji = settings.getAsBoolean("normalize_kanji", JapaneseIterationMarkCharFilter.NORMALIZE_KANJI_DEFAULT); normalizeKana = settings.getAsBoolean("normalize_kana", JapaneseIterationMarkCharFilter.NORMALIZE_KANA_DEFAULT); } diff --git a/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/index/analysis/KuromojiKatakanaStemmerFactory.java b/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/index/analysis/KuromojiKatakanaStemmerFactory.java index 93db459b865..f1986d6cce6 100644 --- a/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/index/analysis/KuromojiKatakanaStemmerFactory.java +++ b/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/index/analysis/KuromojiKatakanaStemmerFactory.java @@ -24,16 +24,15 @@ import org.apache.lucene.analysis.ja.JapaneseKatakanaStemFilter; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; public class KuromojiKatakanaStemmerFactory extends AbstractTokenFilterFactory { private final int minimumLength; @Inject - public KuromojiKatakanaStemmerFactory(Index index, @IndexSettings Settings indexSettings, @Assisted String name, @Assisted Settings settings) { - super(index, indexSettings, name, settings); + public KuromojiKatakanaStemmerFactory(IndexSettings indexSettings, @Assisted String name, @Assisted Settings settings) { + super(indexSettings, name, settings); minimumLength = settings.getAsInt("minimum_length", JapaneseKatakanaStemFilter.DEFAULT_MINIMUM_LENGTH); } diff --git a/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/index/analysis/KuromojiPartOfSpeechFilterFactory.java b/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/index/analysis/KuromojiPartOfSpeechFilterFactory.java index 12a29a0741a..5fb293daec9 100644 --- a/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/index/analysis/KuromojiPartOfSpeechFilterFactory.java +++ b/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/index/analysis/KuromojiPartOfSpeechFilterFactory.java @@ -25,8 +25,7 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; import java.util.HashSet; import java.util.List; @@ -37,8 +36,8 @@ public class KuromojiPartOfSpeechFilterFactory extends AbstractTokenFilterFactor private final Set stopTags = new HashSet(); @Inject - public KuromojiPartOfSpeechFilterFactory(Index index, @IndexSettings Settings indexSettings, Environment env, @Assisted String name, @Assisted Settings settings) { - super(index, indexSettings, name, settings); + public KuromojiPartOfSpeechFilterFactory(IndexSettings indexSettings, Environment env, @Assisted String name, @Assisted Settings settings) { + super(indexSettings, name, settings); List wordList = Analysis.getWordList(env, settings, "stoptags"); if (wordList != null) { stopTags.addAll(wordList); diff --git a/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/index/analysis/KuromojiReadingFormFilterFactory.java b/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/index/analysis/KuromojiReadingFormFilterFactory.java index a87ac8c8256..55251a1a93d 100644 --- a/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/index/analysis/KuromojiReadingFormFilterFactory.java +++ b/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/index/analysis/KuromojiReadingFormFilterFactory.java @@ -24,16 +24,15 @@ import org.apache.lucene.analysis.ja.JapaneseReadingFormFilter; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; public class KuromojiReadingFormFilterFactory extends AbstractTokenFilterFactory { private final boolean useRomaji; @Inject - public KuromojiReadingFormFilterFactory(Index index, @IndexSettings Settings indexSettings, @Assisted String name, @Assisted Settings settings) { - super(index, indexSettings, name, settings); + public KuromojiReadingFormFilterFactory(IndexSettings indexSettings, @Assisted String name, @Assisted Settings settings) { + super(indexSettings, name, settings); useRomaji = settings.getAsBoolean("use_romaji", false); } diff --git a/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/index/analysis/KuromojiTokenizerFactory.java b/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/index/analysis/KuromojiTokenizerFactory.java index 31b759c5e65..6a9bc617bc9 100644 --- a/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/index/analysis/KuromojiTokenizerFactory.java +++ b/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/index/analysis/KuromojiTokenizerFactory.java @@ -28,8 +28,7 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; import java.io.IOException; import java.io.Reader; @@ -46,8 +45,8 @@ public class KuromojiTokenizerFactory extends AbstractTokenizerFactory { private boolean discartPunctuation; @Inject - public KuromojiTokenizerFactory(Index index, @IndexSettings Settings indexSettings, Environment env, @Assisted String name, @Assisted Settings settings) { - super(index, indexSettings, name, settings); + public KuromojiTokenizerFactory(IndexSettings indexSettings, Environment env, @Assisted String name, @Assisted Settings settings) { + super(indexSettings, name, settings); mode = getMode(settings); userDictionary = getUserDictionary(env, settings); discartPunctuation = settings.getAsBoolean("discard_punctuation", true); diff --git a/plugins/analysis-kuromoji/src/test/java/org/elasticsearch/index/analysis/KuromojiAnalysisTests.java b/plugins/analysis-kuromoji/src/test/java/org/elasticsearch/index/analysis/KuromojiAnalysisTests.java index 212ab0d7cb8..f910328012c 100644 --- a/plugins/analysis-kuromoji/src/test/java/org/elasticsearch/index/analysis/KuromojiAnalysisTests.java +++ b/plugins/analysis-kuromoji/src/test/java/org/elasticsearch/index/analysis/KuromojiAnalysisTests.java @@ -33,11 +33,10 @@ import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.env.Environment; import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexNameModule; -import org.elasticsearch.index.settings.IndexSettingsModule; import org.elasticsearch.indices.analysis.IndicesAnalysisService; import org.elasticsearch.plugin.analysis.kuromoji.AnalysisKuromojiPlugin; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.IndexNameAndSettingsModule; import java.io.IOException; import java.io.InputStream; @@ -213,8 +212,7 @@ public class KuromojiAnalysisTests extends ESTestCase { new AnalysisKuromojiPlugin().onModule(analysisModule); Injector injector = new ModulesBuilder().add( - new IndexSettingsModule(index, settings), - new IndexNameModule(index), + new IndexNameAndSettingsModule(index, settings), analysisModule) .createChildInjector(parentInjector); diff --git a/plugins/analysis-phonetic/src/main/java/org/elasticsearch/index/analysis/PhoneticTokenFilterFactory.java b/plugins/analysis-phonetic/src/main/java/org/elasticsearch/index/analysis/PhoneticTokenFilterFactory.java index b23f311268a..05093772647 100644 --- a/plugins/analysis-phonetic/src/main/java/org/elasticsearch/index/analysis/PhoneticTokenFilterFactory.java +++ b/plugins/analysis-phonetic/src/main/java/org/elasticsearch/index/analysis/PhoneticTokenFilterFactory.java @@ -32,11 +32,10 @@ import org.apache.lucene.analysis.phonetic.PhoneticFilter; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.analysis.phonetic.HaasePhonetik; import org.elasticsearch.index.analysis.phonetic.KoelnerPhonetik; import org.elasticsearch.index.analysis.phonetic.Nysiis; -import org.elasticsearch.index.settings.IndexSettings; import java.util.Arrays; import java.util.HashSet; @@ -54,8 +53,8 @@ public class PhoneticTokenFilterFactory extends AbstractTokenFilterFactory { private RuleType ruletype; @Inject - public PhoneticTokenFilterFactory(Index index, @IndexSettings Settings indexSettings, @Assisted String name, @Assisted Settings settings) { - super(index, indexSettings, name, settings); + public PhoneticTokenFilterFactory(IndexSettings indexSettings, @Assisted String name, @Assisted Settings settings) { + super(indexSettings, name, settings); this.languageset = null; this.nametype = null; this.ruletype = null; diff --git a/plugins/analysis-phonetic/src/test/java/org/elasticsearch/index/analysis/SimplePhoneticAnalysisTests.java b/plugins/analysis-phonetic/src/test/java/org/elasticsearch/index/analysis/SimplePhoneticAnalysisTests.java index bf763cf7cc0..ea4983caf34 100644 --- a/plugins/analysis-phonetic/src/test/java/org/elasticsearch/index/analysis/SimplePhoneticAnalysisTests.java +++ b/plugins/analysis-phonetic/src/test/java/org/elasticsearch/index/analysis/SimplePhoneticAnalysisTests.java @@ -28,10 +28,9 @@ import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.env.Environment; import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexNameModule; -import org.elasticsearch.index.settings.IndexSettingsModule; import org.elasticsearch.indices.analysis.IndicesAnalysisService; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.IndexNameAndSettingsModule; import org.hamcrest.MatcherAssert; import static org.elasticsearch.common.settings.Settings.settingsBuilder; @@ -57,8 +56,7 @@ public class SimplePhoneticAnalysisTests extends ESTestCase { Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings))).createInjector(); Injector injector = new ModulesBuilder().add( - new IndexSettingsModule(index, settings), - new IndexNameModule(index), + new IndexNameAndSettingsModule(index, settings), new AnalysisModule(settings, parentInjector.getInstance(IndicesAnalysisService.class)) .addProcessor(new PhoneticAnalysisBinderProcessor())).createChildInjector(parentInjector); diff --git a/plugins/analysis-smartcn/src/main/java/org/elasticsearch/index/analysis/SmartChineseAnalyzerProvider.java b/plugins/analysis-smartcn/src/main/java/org/elasticsearch/index/analysis/SmartChineseAnalyzerProvider.java index 1c6e23d6134..61ef93f5a3d 100644 --- a/plugins/analysis-smartcn/src/main/java/org/elasticsearch/index/analysis/SmartChineseAnalyzerProvider.java +++ b/plugins/analysis-smartcn/src/main/java/org/elasticsearch/index/analysis/SmartChineseAnalyzerProvider.java @@ -23,9 +23,7 @@ import org.apache.lucene.analysis.cn.smart.SmartChineseAnalyzer; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.env.Environment; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; /** */ @@ -34,8 +32,8 @@ public class SmartChineseAnalyzerProvider extends AbstractIndexAnalyzerProvider< private final SmartChineseAnalyzer analyzer; @Inject - public SmartChineseAnalyzerProvider(Index index, @IndexSettings Settings indexSettings, Environment env, @Assisted String name, @Assisted Settings settings) { - super(index, indexSettings, name, settings); + public SmartChineseAnalyzerProvider(IndexSettings indexSettings, @Assisted String name, @Assisted Settings settings) { + super(indexSettings, name, settings); analyzer = new SmartChineseAnalyzer(SmartChineseAnalyzer.getDefaultStopSet()); } diff --git a/plugins/analysis-smartcn/src/main/java/org/elasticsearch/index/analysis/SmartChineseNoOpTokenFilterFactory.java b/plugins/analysis-smartcn/src/main/java/org/elasticsearch/index/analysis/SmartChineseNoOpTokenFilterFactory.java index ddd30bd8542..a4d6b9e45e1 100644 --- a/plugins/analysis-smartcn/src/main/java/org/elasticsearch/index/analysis/SmartChineseNoOpTokenFilterFactory.java +++ b/plugins/analysis-smartcn/src/main/java/org/elasticsearch/index/analysis/SmartChineseNoOpTokenFilterFactory.java @@ -23,14 +23,13 @@ import org.apache.lucene.analysis.TokenStream; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.index.IndexSettings; public class SmartChineseNoOpTokenFilterFactory extends AbstractTokenFilterFactory { @Inject - public SmartChineseNoOpTokenFilterFactory(Index index, @IndexSettings Settings indexSettings, @Assisted String name, @Assisted Settings settings) { - super(index, indexSettings, name, settings); + public SmartChineseNoOpTokenFilterFactory(IndexSettings indexSettings, @Assisted String name, @Assisted Settings settings) { + super(indexSettings, name, settings); } @Override diff --git a/plugins/analysis-smartcn/src/main/java/org/elasticsearch/index/analysis/SmartChineseTokenizerTokenizerFactory.java b/plugins/analysis-smartcn/src/main/java/org/elasticsearch/index/analysis/SmartChineseTokenizerTokenizerFactory.java index e73e72f2493..ee78aa4547c 100644 --- a/plugins/analysis-smartcn/src/main/java/org/elasticsearch/index/analysis/SmartChineseTokenizerTokenizerFactory.java +++ b/plugins/analysis-smartcn/src/main/java/org/elasticsearch/index/analysis/SmartChineseTokenizerTokenizerFactory.java @@ -24,16 +24,13 @@ import org.apache.lucene.analysis.cn.smart.HMMChineseTokenizer; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; - -import java.io.Reader; +import org.elasticsearch.index.IndexSettings; public class SmartChineseTokenizerTokenizerFactory extends AbstractTokenizerFactory { @Inject - public SmartChineseTokenizerTokenizerFactory(Index index, @IndexSettings Settings indexSettings, @Assisted String name, @Assisted Settings settings) { - super(index, indexSettings, name, settings); + public SmartChineseTokenizerTokenizerFactory(IndexSettings indexSettings, @Assisted String name, @Assisted Settings settings) { + super(indexSettings, name, settings); } @Override diff --git a/plugins/analysis-smartcn/src/test/java/org/elasticsearch/index/analysis/SimpleSmartChineseAnalysisTests.java b/plugins/analysis-smartcn/src/test/java/org/elasticsearch/index/analysis/SimpleSmartChineseAnalysisTests.java index 7c6f3584c4a..afdce6b607f 100644 --- a/plugins/analysis-smartcn/src/test/java/org/elasticsearch/index/analysis/SimpleSmartChineseAnalysisTests.java +++ b/plugins/analysis-smartcn/src/test/java/org/elasticsearch/index/analysis/SimpleSmartChineseAnalysisTests.java @@ -28,10 +28,9 @@ import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.env.Environment; import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexNameModule; -import org.elasticsearch.index.settings.IndexSettingsModule; import org.elasticsearch.indices.analysis.IndicesAnalysisService; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.IndexNameAndSettingsModule; import org.hamcrest.MatcherAssert; import static org.elasticsearch.common.settings.Settings.settingsBuilder; @@ -49,8 +48,7 @@ public class SimpleSmartChineseAnalysisTests extends ESTestCase { .build(); Injector parentInjector = new ModulesBuilder().add(new SettingsModule(EMPTY_SETTINGS), new EnvironmentModule(new Environment(settings))).createInjector(); Injector injector = new ModulesBuilder().add( - new IndexSettingsModule(index, settings), - new IndexNameModule(index), + new IndexNameAndSettingsModule(index, settings), new AnalysisModule(EMPTY_SETTINGS, parentInjector.getInstance(IndicesAnalysisService.class)).addProcessor(new SmartChineseAnalysisBinderProcessor())) .createChildInjector(parentInjector); diff --git a/plugins/analysis-stempel/src/main/java/org/elasticsearch/index/analysis/pl/PolishAnalyzerProvider.java b/plugins/analysis-stempel/src/main/java/org/elasticsearch/index/analysis/pl/PolishAnalyzerProvider.java index 57207a80b6e..4c6ea0188a3 100644 --- a/plugins/analysis-stempel/src/main/java/org/elasticsearch/index/analysis/pl/PolishAnalyzerProvider.java +++ b/plugins/analysis-stempel/src/main/java/org/elasticsearch/index/analysis/pl/PolishAnalyzerProvider.java @@ -23,10 +23,8 @@ import org.apache.lucene.analysis.pl.PolishAnalyzer; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.env.Environment; -import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.analysis.AbstractIndexAnalyzerProvider; -import org.elasticsearch.index.settings.IndexSettings; /** */ @@ -35,8 +33,8 @@ public class PolishAnalyzerProvider extends AbstractIndexAnalyzerProvider shardDirectory() { - return SmbSimpleFsDirectoryService.class; + public SmbSimpleFsIndexStore(IndexSettings indexSettings, IndicesStore indicesStore) { + super(indexSettings, indicesStore); } @Override public DirectoryService newDirectoryService(ShardPath path) { - return new SmbSimpleFsDirectoryService(indexSettings(), this, path); + return new SmbSimpleFsDirectoryService(indexSettings, this, path); } } From 2245f480c93f5b8cef3b3f049213636e67850128 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Thu, 22 Oct 2015 22:26:24 +0200 Subject: [PATCH 02/11] add unittests & javadocs --- .../org/elasticsearch/index/IndexModule.java | 26 +++++- .../elasticsearch/index/IndexSettings.java | 62 +++++++++++-- .../index/analysis/AnalysisService.java | 4 +- .../analysis/CustomAnalyzerProvider.java | 2 +- .../analysis/EdgeNGramTokenizerFactory.java | 2 +- .../index/analysis/NGramTokenizerFactory.java | 2 +- .../analysis/PatternAnalyzerProvider.java | 2 +- .../analysis/StandardAnalyzerProvider.java | 2 +- .../StandardHtmlStripAnalyzerProvider.java | 2 +- .../analysis/StemmerTokenFilterFactory.java | 2 +- .../index/mapper/MapperService.java | 4 +- .../index/query/IndexQueryParserService.java | 2 +- .../index/IndexSettingsTests.java | 93 +++++++++++++++++++ .../test/store/MockFSIndexStore.java | 2 +- 14 files changed, 184 insertions(+), 23 deletions(-) create mode 100644 core/src/test/java/org/elasticsearch/index/IndexSettingsTests.java diff --git a/core/src/main/java/org/elasticsearch/index/IndexModule.java b/core/src/main/java/org/elasticsearch/index/IndexModule.java index b1148ddbac3..db350bd875a 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexModule.java +++ b/core/src/main/java/org/elasticsearch/index/IndexModule.java @@ -54,6 +54,9 @@ public class IndexModule extends AbstractModule { this.indexSettings = indexSettings; } + /** + * Adds a settings consumer for this index + */ public void addIndexSettingsListener(Consumer listener) { if (listener == null) { throw new IllegalArgumentException("listener must not be null"); @@ -65,10 +68,31 @@ public class IndexModule extends AbstractModule { settingsConsumers.add(listener); } - public Settings getIndexSettings() { + /** + * Returns the index {@link Settings} for this index + */ + public Settings getSettings() { return indexSettings.getSettings(); } + /** + * Returns the index this module is associated with + */ + public Index getIndex() { + return indexSettings.getIndex(); + } + + /** + * Adds an {@link IndexEventListener} for this index. All listeners added here + * are maintained for the entire index lifecycle on this node. Once an index is closed or deleted these + * listeners go out of scope. + *

+ * Note: an index might be created on a node multiple times. For instance if the last shard from an index is + * relocated to another node the internal representation will be destroyed which includes the registered listeners. + * Once the node holds at least one shard of an index all modules are reloaded and listeners are registered again. + * Listeners can't be unregistered the will stay alive for the entire time the index is allocated on a node. + *

+ */ public void addIndexEventListener(IndexEventListener listener) { if (this.listener != null) { throw new IllegalStateException("can't add listener after listeners are frozen"); diff --git a/core/src/main/java/org/elasticsearch/index/IndexSettings.java b/core/src/main/java/org/elasticsearch/index/IndexSettings.java index 71c95436587..4da6b7433df 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexSettings.java +++ b/core/src/main/java/org/elasticsearch/index/IndexSettings.java @@ -31,53 +31,94 @@ import java.util.Collections; import java.util.List; import java.util.function.Consumer; -// TODO add javadocs - this also needs a dedicated unit test +/** + * This class encapsulates all index level settings and handles settings updates. + * It's created per index and available to all index level classes and allows them to retrieve + * the latest updated settings instance. Classes that need to listen to settings updates can register + * a settings consumer at index creation via {@link IndexModule#addIndexSettingsListener(Consumer)} that will + * be called for each settings update. + */ public final class IndexSettings { + private final String uuid; private volatile Settings settings; private final List> updateListeners; private final Index index; private final Version version; private final ESLogger logger; + private final String nodeName; - public IndexSettings(Index index) { - this(index, Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(), Collections.EMPTY_LIST); - } - + /** + * Creates a new {@link IndexSettings} instance + * @param index the index this settings object is associated with + * @param settings the actual settings including the node level settings + * @param updateListeners a collection of listeners / consumers that should be notified if one or more settings are updated + */ public IndexSettings(Index index, Settings settings, Collection> updateListeners) { this.settings = settings; this.updateListeners = Collections.unmodifiableList(new ArrayList<>(updateListeners)); this.index = index; version = Version.indexCreated(settings); + uuid = settings.get(IndexMetaData.SETTING_INDEX_UUID, IndexMetaData.INDEX_UUID_NA_VALUE); logger = Loggers.getLogger(getClass(), settings, index); + nodeName = settings.get("name", ""); } + /** + * Returns the settings for this index. These settings contain the node and index level settings where + * settings that are specified on both index and node level are overwritten by the index settings. + */ public Settings getSettings() { return settings; } + /** + * Returns the index this settings object belongs to + */ public Index getIndex() { return index; } + /** + * Returns the indexes UUID + */ public String getUUID() { - return settings.get(IndexMetaData.SETTING_INDEX_UUID, IndexMetaData.INDEX_UUID_NA_VALUE); + return uuid; } + /** + * Returns true if the index has a custom data path + */ public boolean hasCustomDataPath() { return NodeEnvironment.hasCustomDataPath(settings); } - public Version getVersion() { + /** + * Returns the version the index was created on. + * @see Version#indexCreated(Settings) + */ + public Version getIndexVersionCreated() { return version; } + /** + * Returns the current node name + */ public String getNodeName() { - return settings.get("name", ""); + return nodeName; } + /** + * Notifies all registered settings consumers with the new settings iff at least one setting has changed. + * + * @return true iff any setting has been updated otherwise false. + */ synchronized boolean updateSettings(Settings settings) { if (Version.indexCreated(settings) != version) { - throw new IllegalStateException("version mismatch on settings update"); + throw new IllegalArgumentException("version mismatch on settings update expected: " + version + " but was: " + Version.indexCreated(settings)); + } + final String newUUID = settings.get(IndexMetaData.SETTING_INDEX_UUID, IndexMetaData.INDEX_UUID_NA_VALUE); + if (newUUID.equals(getUUID()) == false) { + throw new IllegalArgumentException("uuid mismatch on settings update expected: " + uuid + " but was: " + newUUID); } if (this.settings.getByPrefix(IndexMetaData.INDEX_SETTING_PREFIX).getAsMap().equals(settings.getByPrefix(IndexMetaData.INDEX_SETTING_PREFIX).getAsMap())) { @@ -95,6 +136,9 @@ public final class IndexSettings { return true; } + /** + * Returns all settings update consumers + */ List> getUpdateListeners() { // for testing return updateListeners; } diff --git a/core/src/main/java/org/elasticsearch/index/analysis/AnalysisService.java b/core/src/main/java/org/elasticsearch/index/analysis/AnalysisService.java index 25792bf70e7..8c8565124b8 100644 --- a/core/src/main/java/org/elasticsearch/index/analysis/AnalysisService.java +++ b/core/src/main/java/org/elasticsearch/index/analysis/AnalysisService.java @@ -63,7 +63,7 @@ public class AnalysisService extends AbstractIndexComponent implements Closeable @Nullable Map charFilterFactoryFactories, @Nullable Map tokenFilterFactoryFactories) { super(indexSettings); - Settings defaultSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, indexSettings.getVersion()).build(); + Settings defaultSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, indexSettings.getIndexVersionCreated()).build(); Map tokenizers = new HashMap<>(); if (tokenizerFactoryFactories != null) { Map tokenizersSettings = this.indexSettings.getSettings().getGroups("index.analysis.tokenizer"); @@ -266,7 +266,7 @@ public class AnalysisService extends AbstractIndexComponent implements Closeable throw new IllegalArgumentException("no default analyzer configured"); } if (analyzers.containsKey("default_index")) { - final Version createdVersion = indexSettings.getVersion(); + final Version createdVersion = indexSettings.getIndexVersionCreated(); if (createdVersion.onOrAfter(Version.V_3_0_0)) { throw new IllegalArgumentException("setting [index.analysis.analyzer.default_index] is not supported anymore, use [index.analysis.analyzer.default] instead for index [" + index().getName() + "]"); } else { diff --git a/core/src/main/java/org/elasticsearch/index/analysis/CustomAnalyzerProvider.java b/core/src/main/java/org/elasticsearch/index/analysis/CustomAnalyzerProvider.java index 3ba8676536e..6036eba4b36 100644 --- a/core/src/main/java/org/elasticsearch/index/analysis/CustomAnalyzerProvider.java +++ b/core/src/main/java/org/elasticsearch/index/analysis/CustomAnalyzerProvider.java @@ -80,7 +80,7 @@ public class CustomAnalyzerProvider extends AbstractIndexAnalyzerProvider 255) { + if (indexSettings.getIndexVersionCreated().onOrAfter(Version.V_2_0_0_beta1) && mapper.type().length() > 255) { throw new InvalidTypeNameException("mapping type name [" + mapper.type() + "] is too long; limit is length 255 but was [" + mapper.type().length() + "]"); } if (mapper.type().charAt(0) == '_') { @@ -236,7 +236,7 @@ public class MapperService extends AbstractIndexComponent implements Closeable { throw new IllegalArgumentException("The [_parent.type] option can't point to the same type"); } if (typeNameStartsWithIllegalDot(mapper)) { - if (indexSettings.getVersion().onOrAfter(Version.V_2_0_0_beta1)) { + if (indexSettings.getIndexVersionCreated().onOrAfter(Version.V_2_0_0_beta1)) { throw new IllegalArgumentException("mapping type name [" + mapper.type() + "] must not start with a '.'"); } else { logger.warn("Type [{}] starts with a '.', it is recommended not to start a type name with a '.'", mapper.type()); diff --git a/core/src/main/java/org/elasticsearch/index/query/IndexQueryParserService.java b/core/src/main/java/org/elasticsearch/index/query/IndexQueryParserService.java index df8be3f2219..ede4fa98a76 100644 --- a/core/src/main/java/org/elasticsearch/index/query/IndexQueryParserService.java +++ b/core/src/main/java/org/elasticsearch/index/query/IndexQueryParserService.java @@ -207,7 +207,7 @@ public class IndexQueryParserService extends AbstractIndexComponent { * @return The lowest node version in the cluster when the index was created or null if that was unknown */ public Version getIndexCreatedVersion() { - return indexSettings.getVersion(); + return indexSettings.getIndexVersionCreated(); } /** diff --git a/core/src/test/java/org/elasticsearch/index/IndexSettingsTests.java b/core/src/test/java/org/elasticsearch/index/IndexSettingsTests.java new file mode 100644 index 00000000000..2c06e768f0a --- /dev/null +++ b/core/src/test/java/org/elasticsearch/index/IndexSettingsTests.java @@ -0,0 +1,93 @@ +/* + * 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; + +import org.elasticsearch.Version; +import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.VersionUtils; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Consumer; + +public class IndexSettingsTests extends ESTestCase { + + public void testRunListener() { + Version version = VersionUtils.getPreviousVersion(); + Settings theSettings = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, version).put(IndexMetaData.SETTING_INDEX_UUID, "0xdeadbeef").build(); + final AtomicInteger integer = new AtomicInteger(0); + Consumer settingsConsumer = (s) -> integer.set(s.getAsInt("index.test.setting.int", -1)); + IndexSettings settings = new IndexSettings(new Index("index"), theSettings, Collections.singleton(settingsConsumer)); + assertEquals(version, settings.getIndexVersionCreated()); + assertEquals("0xdeadbeef", settings.getUUID()); + + assertEquals(1, settings.getUpdateListeners().size()); + assertFalse(settings.updateSettings(theSettings)); + assertSame(theSettings, settings.getSettings()); + assertEquals(0, integer.get()); + assertTrue(settings.updateSettings(Settings.builder().put(theSettings).put("index.test.setting.int", 42).build())); + assertEquals(42, integer.get()); + } + + public void testListenerCanThrowException() { + Version version = VersionUtils.getPreviousVersion(); + Settings theSettings = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, version).put(IndexMetaData.SETTING_INDEX_UUID, "0xdeadbeef").build(); + final AtomicInteger integer = new AtomicInteger(0); + Consumer settingsConsumer = (s) -> integer.set(s.getAsInt("index.test.setting.int", -1)); + Consumer exceptionConsumer = (s) -> {throw new RuntimeException("boom");}; + List> list = new ArrayList<>(); + list.add(settingsConsumer); + list.add(exceptionConsumer); + Collections.shuffle(list, random()); + IndexSettings settings = new IndexSettings(new Index("index"), theSettings, list); + assertEquals(0, integer.get()); + assertTrue(settings.updateSettings(Settings.builder().put(theSettings).put("index.test.setting.int", 42).build())); + assertEquals(42, integer.get()); + } + + public void testSettingsConsistency() { + Version version = VersionUtils.getPreviousVersion(); + Settings theSettings = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); + IndexSettings settings = new IndexSettings(new Index("index"), theSettings, Collections.EMPTY_LIST); + assertEquals(version, settings.getIndexVersionCreated()); + assertEquals("_na_", settings.getUUID()); + try { + settings.updateSettings(Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put("index.test.setting.int", 42).build()); + fail("version has changed"); + } catch (IllegalArgumentException ex) { + assertTrue(ex.getMessage(), ex.getMessage().startsWith("version mismatch on settings update expected: ")); + } + + theSettings = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexMetaData.SETTING_INDEX_UUID, "0xdeadbeef").build(); + settings = new IndexSettings(new Index("index"), theSettings, Collections.EMPTY_LIST); + try { + settings.updateSettings(Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put("index.test.setting.int", 42).build()); + fail("uuid missing/change"); + } catch (IllegalArgumentException ex) { + assertEquals("uuid mismatch on settings update expected: 0xdeadbeef but was: _na_", ex.getMessage()); + } + assertSame(theSettings, settings.getSettings()); + } + + +} diff --git a/core/src/test/java/org/elasticsearch/test/store/MockFSIndexStore.java b/core/src/test/java/org/elasticsearch/test/store/MockFSIndexStore.java index a94a71d1325..4898ac164d1 100644 --- a/core/src/test/java/org/elasticsearch/test/store/MockFSIndexStore.java +++ b/core/src/test/java/org/elasticsearch/test/store/MockFSIndexStore.java @@ -60,7 +60,7 @@ public class MockFSIndexStore extends IndexStore { } public void onModule(IndexModule module) { - Settings indexSettings = module.getIndexSettings(); + Settings indexSettings = module.getSettings(); if ("mock".equals(indexSettings.get(IndexStoreModule.STORE_TYPE))) { if (indexSettings.getAsBoolean(CHECK_INDEX_ON_CLOSE, true)) { module.addIndexEventListener(new Listener()); From f8248eda61930953b5f40339b98f47d96dc56b66 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Thu, 22 Oct 2015 23:06:59 +0200 Subject: [PATCH 03/11] apply review comments --- ...ransportNodesListGatewayStartedShards.java | 2 +- .../org/elasticsearch/index/IndexModule.java | 2 +- .../org/elasticsearch/index/IndexService.java | 3 +- .../elasticsearch/index/IndexSettings.java | 19 ++++++----- .../index/IndexSettingsTests.java | 33 ++++++++++++++++--- 5 files changed, 41 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/gateway/TransportNodesListGatewayStartedShards.java b/core/src/main/java/org/elasticsearch/gateway/TransportNodesListGatewayStartedShards.java index 33740d5528a..3e324d4bea7 100644 --- a/core/src/main/java/org/elasticsearch/gateway/TransportNodesListGatewayStartedShards.java +++ b/core/src/main/java/org/elasticsearch/gateway/TransportNodesListGatewayStartedShards.java @@ -131,7 +131,7 @@ public class TransportNodesListGatewayStartedShards extends TransportNodesAction if (metaData != null) { ShardPath shardPath = null; try { - IndexSettings indexSettings = new IndexSettings(new Index(metaData.getIndex()), Settings.settingsBuilder().put(settings).put(metaData.getSettings()).build(), Collections.EMPTY_LIST); + IndexSettings indexSettings = new IndexSettings(shardId.index(), Settings.settingsBuilder().put(settings).put(metaData.getSettings()).build(), Collections.EMPTY_LIST); shardPath = ShardPath.loadShardPath(logger, nodeEnv, shardId, indexSettings); if (shardPath == null) { throw new IllegalStateException(shardId + " no shard path found"); diff --git a/core/src/main/java/org/elasticsearch/index/IndexModule.java b/core/src/main/java/org/elasticsearch/index/IndexModule.java index db350bd875a..ed7e0754e34 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexModule.java +++ b/core/src/main/java/org/elasticsearch/index/IndexModule.java @@ -90,7 +90,7 @@ public class IndexModule extends AbstractModule { * Note: an index might be created on a node multiple times. For instance if the last shard from an index is * relocated to another node the internal representation will be destroyed which includes the registered listeners. * Once the node holds at least one shard of an index all modules are reloaded and listeners are registered again. - * Listeners can't be unregistered the will stay alive for the entire time the index is allocated on a node. + * Listeners can't be unregistered they will stay alive for the entire time the index is allocated on a node. *

*/ public void addIndexEventListener(IndexEventListener listener) { diff --git a/core/src/main/java/org/elasticsearch/index/IndexService.java b/core/src/main/java/org/elasticsearch/index/IndexService.java index ec5e52b21b6..0139298fe08 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexService.java +++ b/core/src/main/java/org/elasticsearch/index/IndexService.java @@ -57,7 +57,6 @@ import java.nio.file.Path; import java.util.*; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.function.Consumer; import static java.util.Collections.emptyMap; import static java.util.Collections.unmodifiableMap; @@ -509,7 +508,7 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone public synchronized void updateMetaData(final IndexMetaData metadata) { this.indexMetaData = metadata; Settings settings = metadata.getSettings(); - if (this.indexSettings.updateSettings(metadata.getSettings())) { + if (this.indexSettings.updateIndexSettings(metadata.getSettings())) { for (final IndexShard shard : this.shards.values()) { try { shard.onRefreshSettings(settings); diff --git a/core/src/main/java/org/elasticsearch/index/IndexSettings.java b/core/src/main/java/org/elasticsearch/index/IndexSettings.java index 4da6b7433df..afd1f9f97e4 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexSettings.java +++ b/core/src/main/java/org/elasticsearch/index/IndexSettings.java @@ -112,25 +112,26 @@ public final class IndexSettings { * * @return true iff any setting has been updated otherwise false. */ - synchronized boolean updateSettings(Settings settings) { - if (Version.indexCreated(settings) != version) { - throw new IllegalArgumentException("version mismatch on settings update expected: " + version + " but was: " + Version.indexCreated(settings)); + synchronized boolean updateIndexSettings(Settings newSettings) { + if (Version.indexCreated(newSettings) != version) { + throw new IllegalArgumentException("version mismatch on settings update expected: " + version + " but was: " + Version.indexCreated(newSettings)); } - final String newUUID = settings.get(IndexMetaData.SETTING_INDEX_UUID, IndexMetaData.INDEX_UUID_NA_VALUE); + final String newUUID = newSettings.get(IndexMetaData.SETTING_INDEX_UUID, IndexMetaData.INDEX_UUID_NA_VALUE); if (newUUID.equals(getUUID()) == false) { throw new IllegalArgumentException("uuid mismatch on settings update expected: " + uuid + " but was: " + newUUID); } - - if (this.settings.getByPrefix(IndexMetaData.INDEX_SETTING_PREFIX).getAsMap().equals(settings.getByPrefix(IndexMetaData.INDEX_SETTING_PREFIX).getAsMap())) { + final Settings existingSettings = this.settings; + if (existingSettings.getByPrefix(IndexMetaData.INDEX_SETTING_PREFIX).getAsMap().equals(newSettings.getByPrefix(IndexMetaData.INDEX_SETTING_PREFIX).getAsMap())) { // nothing to update, same settings return false; } - this.settings = Settings.builder().put(this.settings).put(settings).build(); + this.settings = Settings.builder().put(existingSettings).put(newSettings).build(); + final Settings mergedSettings = this.settings; for (final Consumer consumer : updateListeners) { try { - consumer.accept(settings); + consumer.accept(mergedSettings); } catch (Exception e) { - logger.warn("failed to refresh index settings for [{}]", e, settings); + logger.warn("failed to refresh index settings for [{}]", e, mergedSettings); } } return true; diff --git a/core/src/test/java/org/elasticsearch/index/IndexSettingsTests.java b/core/src/test/java/org/elasticsearch/index/IndexSettingsTests.java index 2c06e768f0a..56d724ced92 100644 --- a/core/src/test/java/org/elasticsearch/index/IndexSettingsTests.java +++ b/core/src/test/java/org/elasticsearch/index/IndexSettingsTests.java @@ -42,13 +42,36 @@ public class IndexSettingsTests extends ESTestCase { assertEquals("0xdeadbeef", settings.getUUID()); assertEquals(1, settings.getUpdateListeners().size()); - assertFalse(settings.updateSettings(theSettings)); + assertFalse(settings.updateIndexSettings(theSettings)); assertSame(theSettings, settings.getSettings()); assertEquals(0, integer.get()); - assertTrue(settings.updateSettings(Settings.builder().put(theSettings).put("index.test.setting.int", 42).build())); + assertTrue(settings.updateIndexSettings(Settings.builder().put(theSettings).put("index.test.setting.int", 42).build())); assertEquals(42, integer.get()); } + public void testMergedSettingsArePassed() { + Version version = VersionUtils.getPreviousVersion(); + Settings theSettings = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, version) + .put(IndexMetaData.SETTING_INDEX_UUID, "0xdeadbeef").build(); + final AtomicInteger integer = new AtomicInteger(0); + final StringBuilder builder = new StringBuilder(); + Consumer settingsConsumer = (s) -> { + integer.set(s.getAsInt("index.test.setting.int", -1)); + builder.append(s.get("not.updated", "")); + }; + IndexSettings settings = new IndexSettings(new Index("index"), theSettings, Collections.singleton(settingsConsumer)); + assertEquals(0, integer.get()); + assertEquals("", builder.toString()); + assertTrue(settings.updateIndexSettings(Settings.builder().put(theSettings).put("index.test.setting.int", 42).build())); + assertEquals(42, integer.get()); + assertEquals("", builder.toString()); + integer.set(0); + assertTrue(settings.updateIndexSettings(Settings.builder().put(theSettings).put("not.updated", "boom").build())); + assertEquals("boom", builder.toString()); + assertEquals(42, integer.get()); + + } + public void testListenerCanThrowException() { Version version = VersionUtils.getPreviousVersion(); Settings theSettings = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, version).put(IndexMetaData.SETTING_INDEX_UUID, "0xdeadbeef").build(); @@ -61,7 +84,7 @@ public class IndexSettingsTests extends ESTestCase { Collections.shuffle(list, random()); IndexSettings settings = new IndexSettings(new Index("index"), theSettings, list); assertEquals(0, integer.get()); - assertTrue(settings.updateSettings(Settings.builder().put(theSettings).put("index.test.setting.int", 42).build())); + assertTrue(settings.updateIndexSettings(Settings.builder().put(theSettings).put("index.test.setting.int", 42).build())); assertEquals(42, integer.get()); } @@ -72,7 +95,7 @@ public class IndexSettingsTests extends ESTestCase { assertEquals(version, settings.getIndexVersionCreated()); assertEquals("_na_", settings.getUUID()); try { - settings.updateSettings(Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put("index.test.setting.int", 42).build()); + settings.updateIndexSettings(Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put("index.test.setting.int", 42).build()); fail("version has changed"); } catch (IllegalArgumentException ex) { assertTrue(ex.getMessage(), ex.getMessage().startsWith("version mismatch on settings update expected: ")); @@ -81,7 +104,7 @@ public class IndexSettingsTests extends ESTestCase { theSettings = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexMetaData.SETTING_INDEX_UUID, "0xdeadbeef").build(); settings = new IndexSettings(new Index("index"), theSettings, Collections.EMPTY_LIST); try { - settings.updateSettings(Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put("index.test.setting.int", 42).build()); + settings.updateIndexSettings(Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put("index.test.setting.int", 42).build()); fail("uuid missing/change"); } catch (IllegalArgumentException ex) { assertEquals("uuid mismatch on settings update expected: 0xdeadbeef but was: _na_", ex.getMessage()); From 8a9dd871d3193d54fa60fe0bbccbbb5c448a8273 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Fri, 23 Oct 2015 10:53:39 +0200 Subject: [PATCH 04/11] Make IndexSettings also own the IndexMetaData and separate node settings --- .../metadata/MetaDataIndexUpgradeService.java | 4 +- ...ransportNodesListGatewayStartedShards.java | 2 +- .../org/elasticsearch/index/IndexModule.java | 7 +- .../org/elasticsearch/index/IndexService.java | 14 ++-- .../elasticsearch/index/IndexSettings.java | 82 +++++++++++++++---- .../elasticsearch/indices/IndicesService.java | 23 ++---- .../TransportNodesListShardStoreMetaData.java | 2 +- .../elasticsearch/index/IndexModuleTests.java | 24 +++--- .../index/IndexSettingsTests.java | 79 ++++++++++++++---- .../index/analysis/AnalysisModuleTests.java | 4 +- .../index/analysis/AnalysisServiceTests.java | 20 ++--- .../index/analysis/AnalysisTestsHelper.java | 4 +- .../index/analysis/CharFilterTests.java | 6 +- .../index/analysis/CompoundAnalysisTests.java | 6 +- .../analysis/NGramTokenizerFactoryTests.java | 29 +++---- .../PatternCaptureTokenFilterTests.java | 6 +- .../index/analysis/StopAnalyzerTests.java | 4 +- .../synonyms/SynonymsAnalysisTests.java | 4 +- .../cache/bitset/BitSetFilterCacheTests.java | 3 +- .../index/engine/InternalEngineTests.java | 9 +- .../index/engine/ShadowEngineTests.java | 9 +- .../fielddata/IndexFieldDataServiceTests.java | 3 +- .../index/query/AbstractQueryTestCase.java | 6 +- .../index/query/TemplateQueryParserTests.java | 6 +- .../index/shard/NewPathForShardTests.java | 3 +- .../index/shard/ShardPathTests.java | 9 +- .../similarity/SimilarityModuleTests.java | 7 +- .../index/store/IndexStoreTests.java | 5 +- .../elasticsearch/index/store/StoreTests.java | 5 +- .../index/translog/BufferedTranslogTests.java | 3 +- .../index/translog/TranslogTests.java | 3 +- .../recovery/RecoverySourceHandlerTests.java | 3 +- ...gsModule.java => IndexSettingsModule.java} | 20 ++++- .../test/store/MockFSDirectoryService.java | 10 ++- .../index/analysis/AnalysisTestUtils.java | 4 +- .../index/analysis/KuromojiAnalysisTests.java | 4 +- .../analysis/SimplePhoneticAnalysisTests.java | 4 +- .../SimpleSmartChineseAnalysisTests.java | 4 +- .../index/analysis/PolishAnalysisTests.java | 4 +- .../SimplePolishTokenFilterTests.java | 4 +- 40 files changed, 274 insertions(+), 174 deletions(-) rename core/src/test/java/org/elasticsearch/test/{IndexNameAndSettingsModule.java => IndexSettingsModule.java} (55%) diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java index 6860b937554..0c70b99d699 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java @@ -215,12 +215,10 @@ public class MetaDataIndexUpgradeService extends AbstractComponent { * Checks the mappings for compatibility with the current version */ private void checkMappingsCompatibility(IndexMetaData indexMetaData) { - Index index = new Index(indexMetaData.getIndex()); - Settings settings = indexMetaData.getSettings(); try { // We cannot instantiate real analysis server at this point because the node might not have // been started yet. However, we don't really need real analyzers at this stage - so we can fake it - IndexSettings indexSettings = new IndexSettings(new Index(indexMetaData.getIndex()), Settings.settingsBuilder().put(settings).put(indexMetaData.getSettings()).build(), Collections.EMPTY_LIST); + IndexSettings indexSettings = new IndexSettings(indexMetaData, this.settings, Collections.EMPTY_LIST); SimilarityService similarityService = new SimilarityService(indexSettings, Collections.EMPTY_MAP); diff --git a/core/src/main/java/org/elasticsearch/gateway/TransportNodesListGatewayStartedShards.java b/core/src/main/java/org/elasticsearch/gateway/TransportNodesListGatewayStartedShards.java index 3e324d4bea7..bfc078a6679 100644 --- a/core/src/main/java/org/elasticsearch/gateway/TransportNodesListGatewayStartedShards.java +++ b/core/src/main/java/org/elasticsearch/gateway/TransportNodesListGatewayStartedShards.java @@ -131,7 +131,7 @@ public class TransportNodesListGatewayStartedShards extends TransportNodesAction if (metaData != null) { ShardPath shardPath = null; try { - IndexSettings indexSettings = new IndexSettings(shardId.index(), Settings.settingsBuilder().put(settings).put(metaData.getSettings()).build(), Collections.EMPTY_LIST); + IndexSettings indexSettings = new IndexSettings(metaData, settings, Collections.EMPTY_LIST); shardPath = ShardPath.loadShardPath(logger, nodeEnv, shardId, indexSettings); if (shardPath == null) { throw new IllegalStateException(shardId + " no shard path found"); diff --git a/core/src/main/java/org/elasticsearch/index/IndexModule.java b/core/src/main/java/org/elasticsearch/index/IndexModule.java index ed7e0754e34..58b673a209f 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexModule.java +++ b/core/src/main/java/org/elasticsearch/index/IndexModule.java @@ -39,7 +39,6 @@ import java.util.function.Consumer; */ public class IndexModule extends AbstractModule { - private final IndexMetaData indexMetaData; private final IndexSettings indexSettings; // pkg private so tests can mock Class engineFactoryImpl = InternalEngineFactory.class; @@ -49,8 +48,7 @@ public class IndexModule extends AbstractModule { private IndexEventListener listener; - public IndexModule(IndexSettings indexSettings, IndexMetaData indexMetaData) { - this.indexMetaData = indexMetaData; + public IndexModule(IndexSettings indexSettings) { this.indexSettings = indexSettings; } @@ -124,12 +122,11 @@ public class IndexModule extends AbstractModule { bind(IndexSearcherWrapper.class).to(indexSearcherWrapper).asEagerSingleton(); } bind(IndexEventListener.class).toInstance(freeze()); - bind(IndexMetaData.class).toInstance(indexMetaData); bind(IndexService.class).asEagerSingleton(); bind(IndexServicesProvider.class).asEagerSingleton(); bind(MapperService.class).asEagerSingleton(); bind(IndexFieldDataService.class).asEagerSingleton(); - bind(IndexSettings.class).toInstance(new IndexSettings(indexSettings.getIndex(), indexSettings.getSettings(), settingsConsumers)); + bind(IndexSettings.class).toInstance(new IndexSettings(indexSettings.getIndexMetaData(), indexSettings.getNodeSettings(), settingsConsumers)); } } diff --git a/core/src/main/java/org/elasticsearch/index/IndexService.java b/core/src/main/java/org/elasticsearch/index/IndexService.java index 0139298fe08..70ff320ebbe 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexService.java +++ b/core/src/main/java/org/elasticsearch/index/IndexService.java @@ -78,11 +78,10 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone private volatile Map shards = emptyMap(); private final AtomicBoolean closed = new AtomicBoolean(false); private final AtomicBoolean deleted = new AtomicBoolean(false); - private volatile IndexMetaData indexMetaData; private final IndexSettings indexSettings; @Inject - public IndexService(IndexSettings indexSettings, IndexMetaData indexMetaData, NodeEnvironment nodeEnv, + public IndexService(IndexSettings indexSettings, NodeEnvironment nodeEnv, AnalysisService analysisService, IndexFieldDataService indexFieldData, BitsetFilterCache bitSetFilterCache, @@ -91,7 +90,6 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone IndexStore indexStore, IndexEventListener eventListener) { super(indexSettings); - assert indexMetaData != null; this.indexSettings = indexSettings; this.analysisService = analysisService; this.indexFieldData = indexFieldData; @@ -101,7 +99,6 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone this.nodeEnv = nodeEnv; this.indexServicesProvider = indexServicesProvider; this.indexStore = indexStore; - this.indexMetaData = indexMetaData; indexFieldData.setListener(new FieldDataCacheListener(this)); bitSetFilterCache.setListener(new BitsetCacheListener(this)); } @@ -457,7 +454,7 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone return null; } final IndexQueryParserService indexQueryParser = queryParserService(); - final ImmutableOpenMap aliases = this.indexMetaData.getAliases(); + final ImmutableOpenMap aliases = indexSettings.getIndexMetaData().getAliases(); if (aliasNames.length == 1) { AliasMetaData alias = aliases.get(aliasNames[0]); if (alias == null) { @@ -502,13 +499,12 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone } public IndexMetaData getMetaData() { - return indexMetaData; + return indexSettings.getIndexMetaData(); } public synchronized void updateMetaData(final IndexMetaData metadata) { - this.indexMetaData = metadata; - Settings settings = metadata.getSettings(); - if (this.indexSettings.updateIndexSettings(metadata.getSettings())) { + if (indexSettings.updateIndexMetaData(metadata)) { + final Settings settings = indexSettings.getSettings(); for (final IndexShard shard : this.shards.values()) { try { shard.onRefreshSettings(settings); diff --git a/core/src/main/java/org/elasticsearch/index/IndexSettings.java b/core/src/main/java/org/elasticsearch/index/IndexSettings.java index afd1f9f97e4..dc00ad06798 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexSettings.java +++ b/core/src/main/java/org/elasticsearch/index/IndexSettings.java @@ -40,36 +40,45 @@ import java.util.function.Consumer; */ public final class IndexSettings { private final String uuid; - private volatile Settings settings; private final List> updateListeners; private final Index index; private final Version version; private final ESLogger logger; private final String nodeName; + private final Settings nodeSettings; + private final int numberOfShards; + private final boolean isShadowReplicaIndex; + + // updated via #updateIndexMetaData(IndexMetaData) + private volatile Settings settings; + private volatile IndexMetaData indexMetaData; + /** * Creates a new {@link IndexSettings} instance - * @param index the index this settings object is associated with - * @param settings the actual settings including the node level settings + * @param indexMetaData the index this settings object is associated with + * @param nodeSettings the actual settings including the node level settings * @param updateListeners a collection of listeners / consumers that should be notified if one or more settings are updated */ - public IndexSettings(Index index, Settings settings, Collection> updateListeners) { - this.settings = settings; + public IndexSettings(final IndexMetaData indexMetaData, final Settings nodeSettings, final Collection> updateListeners) { + this.nodeSettings = nodeSettings; + this.settings = Settings.builder().put(nodeSettings).put(indexMetaData.getSettings()).build(); this.updateListeners = Collections.unmodifiableList(new ArrayList<>(updateListeners)); - this.index = index; + this.index = new Index(indexMetaData.getIndex()); version = Version.indexCreated(settings); uuid = settings.get(IndexMetaData.SETTING_INDEX_UUID, IndexMetaData.INDEX_UUID_NA_VALUE); logger = Loggers.getLogger(getClass(), settings, index); nodeName = settings.get("name", ""); + this.indexMetaData = indexMetaData; + numberOfShards = settings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_SHARDS, null); + isShadowReplicaIndex = IndexMetaData.isIndexUsingShadowReplicas(settings); } /** * Returns the settings for this index. These settings contain the node and index level settings where * settings that are specified on both index and node level are overwritten by the index settings. */ - public Settings getSettings() { - return settings; - } + public Settings getSettings() { return settings; } /** * Returns the index this settings object belongs to @@ -107,12 +116,55 @@ public final class IndexSettings { return nodeName; } + /** + * Returns all settings update consumers + */ + List> getUpdateListeners() { // for testing + return updateListeners; + } + + /** + * Returns the current IndexMetaData for this index + */ + public IndexMetaData getIndexMetaData() { + return indexMetaData; + } + + /** + * Returns the number of shards this index has. + */ + public int getNumberOfShards() { return numberOfShards; } + + /** + * Returns the number of replicas this index has. + */ + public int getNumberOfReplicas() { + return settings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, null); + } + + /** + * Returns true iff this index uses shadow replicas. + * @see IndexMetaData#isIndexUsingShadowReplicas(Settings) + */ + public boolean isShadowReplicaIndex() { + return isShadowReplicaIndex; + } + + /** + * Returns the node settings. The settings retured from {@link #getSettings()} are a merged version of the + * index settings and the node settings where node settings are overwritten by index settings. + */ + public Settings getNodeSettings() { + return nodeSettings; + } + /** * Notifies all registered settings consumers with the new settings iff at least one setting has changed. * * @return true iff any setting has been updated otherwise false. */ - synchronized boolean updateIndexSettings(Settings newSettings) { + synchronized boolean updateIndexMetaData(IndexMetaData indexMetaData) { + final Settings newSettings = indexMetaData.getSettings(); if (Version.indexCreated(newSettings) != version) { throw new IllegalArgumentException("version mismatch on settings update expected: " + version + " but was: " + Version.indexCreated(newSettings)); } @@ -120,12 +172,13 @@ public final class IndexSettings { if (newUUID.equals(getUUID()) == false) { throw new IllegalArgumentException("uuid mismatch on settings update expected: " + uuid + " but was: " + newUUID); } + this.indexMetaData = indexMetaData; final Settings existingSettings = this.settings; if (existingSettings.getByPrefix(IndexMetaData.INDEX_SETTING_PREFIX).getAsMap().equals(newSettings.getByPrefix(IndexMetaData.INDEX_SETTING_PREFIX).getAsMap())) { // nothing to update, same settings return false; } - this.settings = Settings.builder().put(existingSettings).put(newSettings).build(); + this.settings = Settings.builder().put(nodeSettings).put(newSettings).build(); final Settings mergedSettings = this.settings; for (final Consumer consumer : updateListeners) { try { @@ -136,11 +189,4 @@ public final class IndexSettings { } return true; } - - /** - * Returns all settings update consumers - */ - List> getUpdateListeners() { // for testing - return updateListeners; - } } diff --git a/core/src/main/java/org/elasticsearch/indices/IndicesService.java b/core/src/main/java/org/elasticsearch/indices/IndicesService.java index a9000ca1576..845950025b6 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndicesService.java +++ b/core/src/main/java/org/elasticsearch/indices/IndicesService.java @@ -290,37 +290,32 @@ public class IndicesService extends AbstractLifecycleComponent i if (!lifecycle.started()) { throw new IllegalStateException("Can't create an index [" + indexMetaData.getIndex() + "], node is closed"); } - final Settings settings = indexMetaData.getSettings(); + final IndexSettings idxSettings = new IndexSettings(indexMetaData, this.settings, Collections.EMPTY_LIST); Index index = new Index(indexMetaData.getIndex()); if (indices.containsKey(index.name())) { throw new IndexAlreadyExistsException(index); } logger.debug("creating Index [{}], shards [{}]/[{}{}]", indexMetaData.getIndex(), - settings.get(SETTING_NUMBER_OF_SHARDS), - settings.get(SETTING_NUMBER_OF_REPLICAS), - IndexMetaData.isIndexUsingShadowReplicas(settings) ? "s" : ""); + idxSettings.getNumberOfShards(), + idxSettings.getNumberOfReplicas(), + idxSettings.isShadowReplicaIndex() ? "s" : ""); - Settings indexSettings = settingsBuilder() - .put(this.settings) - .put(indexMetaData.getSettings()) - .build(); ModulesBuilder modules = new ModulesBuilder(); // plugin modules must be added here, before others or we can get crazy injection errors... - for (Module pluginModule : pluginsService.indexModules(indexSettings)) { + for (Module pluginModule : pluginsService.indexModules(idxSettings.getSettings())) { modules.add(pluginModule); } - final IndexSettings idxSettings = new IndexSettings(index, indexSettings, Collections.EMPTY_LIST); - final IndexModule indexModule = new IndexModule(idxSettings, indexMetaData); + final IndexModule indexModule = new IndexModule(idxSettings); for (IndexEventListener listener : builtInListeners) { indexModule.addIndexEventListener(listener); } indexModule.addIndexEventListener(oldShardsStats); - modules.add(new IndexStoreModule(indexSettings)); - modules.add(new AnalysisModule(indexSettings, indicesAnalysisService)); + modules.add(new IndexStoreModule(idxSettings.getSettings())); + modules.add(new AnalysisModule(idxSettings.getSettings(), indicesAnalysisService)); modules.add(new SimilarityModule(idxSettings)); - modules.add(new IndexCacheModule(indexSettings)); + modules.add(new IndexCacheModule(idxSettings.getSettings())); modules.add(indexModule); pluginsService.processModules(modules); final IndexEventListener listener = indexModule.freeze(); diff --git a/core/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetaData.java b/core/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetaData.java index d033f0096df..2972fcfa6cf 100644 --- a/core/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetaData.java +++ b/core/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetaData.java @@ -172,7 +172,7 @@ public class TransportNodesListShardStoreMetaData extends TransportNodesAction x == null); module.indexSearcherWrapper = Wrapper.class; assertBinding(module, IndexSearcherWrapper.class, Wrapper.class); @@ -51,8 +52,8 @@ public class IndexModuleTests extends ModuleTestCase { public void testEngineFactoryBound() { final Index index = new Index("foo"); final Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); - IndexSettings indexSettings = new IndexSettings(index, settings, Collections.EMPTY_LIST); - IndexModule module = new IndexModule(indexSettings, IndexMetaData.PROTO); + IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings, Collections.EMPTY_LIST); + IndexModule module = new IndexModule(indexSettings); assertBinding(module, EngineFactory.class, InternalEngineFactory.class); module.engineFactoryImpl = MockEngineFactory.class; assertBinding(module, EngineFactory.class, MockEngineFactory.class); @@ -66,30 +67,27 @@ public class IndexModuleTests extends ModuleTestCase { atomicBoolean.set(true); } }; - final IndexMetaData meta = IndexMetaData.builder(IndexMetaData.PROTO).index("foo").build(); final Index index = new Index("foo"); final Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); - IndexSettings indexSettings = new IndexSettings(index, settings, Collections.EMPTY_LIST); - IndexModule module = new IndexModule(indexSettings, meta); + IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings, Collections.EMPTY_LIST); + IndexModule module = new IndexModule(indexSettings); Consumer listener = (s) -> {}; module.addIndexSettingsListener(listener); module.addIndexEventListener(eventListener); assertBinding(module, IndexService.class, IndexService.class); assertBinding(module, IndexServicesProvider.class, IndexServicesProvider.class); - assertInstanceBinding(module, IndexMetaData.class, (x) -> x == meta); assertInstanceBinding(module, IndexEventListener.class, (x) -> {x.beforeIndexDeleted(null); return atomicBoolean.get();}); - assertInstanceBinding(module, IndexSettings.class, (x) -> x.getSettings() == indexSettings.getSettings()); - assertInstanceBinding(module, IndexSettings.class, (x) -> x.getIndex() == indexSettings.getIndex()); + 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); } public void testListener() { - final IndexMetaData meta = IndexMetaData.builder(IndexMetaData.PROTO).index("foo").build(); final Index index = new Index("foo"); final Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); - IndexSettings indexSettings = new IndexSettings(index, settings, Collections.EMPTY_LIST); - IndexModule module = new IndexModule(indexSettings, meta); + IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings, Collections.EMPTY_LIST); + IndexModule module = new IndexModule(indexSettings); Consumer listener = (s) -> { }; module.addIndexSettingsListener(listener); diff --git a/core/src/test/java/org/elasticsearch/index/IndexSettingsTests.java b/core/src/test/java/org/elasticsearch/index/IndexSettingsTests.java index 56d724ced92..9a1dc3587a9 100644 --- a/core/src/test/java/org/elasticsearch/index/IndexSettingsTests.java +++ b/core/src/test/java/org/elasticsearch/index/IndexSettingsTests.java @@ -32,20 +32,22 @@ import java.util.function.Consumer; public class IndexSettingsTests extends ESTestCase { + public void testRunListener() { Version version = VersionUtils.getPreviousVersion(); Settings theSettings = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, version).put(IndexMetaData.SETTING_INDEX_UUID, "0xdeadbeef").build(); final AtomicInteger integer = new AtomicInteger(0); Consumer settingsConsumer = (s) -> integer.set(s.getAsInt("index.test.setting.int", -1)); - IndexSettings settings = new IndexSettings(new Index("index"), theSettings, Collections.singleton(settingsConsumer)); + IndexMetaData metaData = newIndexMeta("index", theSettings); + IndexSettings settings = new IndexSettings(metaData, Settings.EMPTY, Collections.singleton(settingsConsumer)); assertEquals(version, settings.getIndexVersionCreated()); assertEquals("0xdeadbeef", settings.getUUID()); assertEquals(1, settings.getUpdateListeners().size()); - assertFalse(settings.updateIndexSettings(theSettings)); - assertSame(theSettings, settings.getSettings()); + assertFalse(settings.updateIndexMetaData(metaData)); + assertEquals(metaData.getSettings().getAsMap(), settings.getSettings().getAsMap()); assertEquals(0, integer.get()); - assertTrue(settings.updateIndexSettings(Settings.builder().put(theSettings).put("index.test.setting.int", 42).build())); + assertTrue(settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(theSettings).put("index.test.setting.int", 42).build()))); assertEquals(42, integer.get()); } @@ -57,16 +59,18 @@ public class IndexSettingsTests extends ESTestCase { final StringBuilder builder = new StringBuilder(); Consumer settingsConsumer = (s) -> { integer.set(s.getAsInt("index.test.setting.int", -1)); - builder.append(s.get("not.updated", "")); + builder.append(s.get("index.not.updated", "")); }; - IndexSettings settings = new IndexSettings(new Index("index"), theSettings, Collections.singleton(settingsConsumer)); + IndexSettings settings = new IndexSettings(newIndexMeta("index", theSettings), Settings.EMPTY, Collections.singleton(settingsConsumer)); assertEquals(0, integer.get()); assertEquals("", builder.toString()); - assertTrue(settings.updateIndexSettings(Settings.builder().put(theSettings).put("index.test.setting.int", 42).build())); + IndexMetaData newMetaData = newIndexMeta("index", Settings.builder().put(settings.getIndexMetaData().getSettings()).put("index.test.setting.int", 42).build()); + assertTrue(settings.updateIndexMetaData(newMetaData)); + assertSame(settings.getIndexMetaData(), newMetaData); assertEquals(42, integer.get()); assertEquals("", builder.toString()); integer.set(0); - assertTrue(settings.updateIndexSettings(Settings.builder().put(theSettings).put("not.updated", "boom").build())); + assertTrue(settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(settings.getIndexMetaData().getSettings()).put("index.not.updated", "boom").build()))); assertEquals("boom", builder.toString()); assertEquals(42, integer.get()); @@ -82,34 +86,75 @@ public class IndexSettingsTests extends ESTestCase { list.add(settingsConsumer); list.add(exceptionConsumer); Collections.shuffle(list, random()); - IndexSettings settings = new IndexSettings(new Index("index"), theSettings, list); + IndexSettings settings = new IndexSettings(newIndexMeta("index", theSettings), Settings.EMPTY, list); assertEquals(0, integer.get()); - assertTrue(settings.updateIndexSettings(Settings.builder().put(theSettings).put("index.test.setting.int", 42).build())); + assertTrue(settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(theSettings).put("index.test.setting.int", 42).build()))); assertEquals(42, integer.get()); } public void testSettingsConsistency() { Version version = VersionUtils.getPreviousVersion(); - Settings theSettings = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); - IndexSettings settings = new IndexSettings(new Index("index"), theSettings, Collections.EMPTY_LIST); + IndexMetaData metaData = newIndexMeta("index", Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build()); + IndexSettings settings = new IndexSettings(metaData, Settings.EMPTY, Collections.EMPTY_LIST); assertEquals(version, settings.getIndexVersionCreated()); assertEquals("_na_", settings.getUUID()); try { - settings.updateIndexSettings(Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put("index.test.setting.int", 42).build()); + settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put("index.test.setting.int", 42).build())); fail("version has changed"); } catch (IllegalArgumentException ex) { assertTrue(ex.getMessage(), ex.getMessage().startsWith("version mismatch on settings update expected: ")); } - theSettings = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexMetaData.SETTING_INDEX_UUID, "0xdeadbeef").build(); - settings = new IndexSettings(new Index("index"), theSettings, Collections.EMPTY_LIST); + metaData = newIndexMeta("index", Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexMetaData.SETTING_INDEX_UUID, "0xdeadbeef").build()); + settings = new IndexSettings(metaData, Settings.EMPTY, Collections.EMPTY_LIST); try { - settings.updateIndexSettings(Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put("index.test.setting.int", 42).build()); + settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put("index.test.setting.int", 42).build())); fail("uuid missing/change"); } catch (IllegalArgumentException ex) { assertEquals("uuid mismatch on settings update expected: 0xdeadbeef but was: _na_", ex.getMessage()); } - assertSame(theSettings, settings.getSettings()); + assertEquals(metaData.getSettings().getAsMap(), settings.getSettings().getAsMap()); + } + + + public void testNodeSettingsAreContained() { + final int numShards = randomIntBetween(1, 10); + final int numReplicas = randomIntBetween(0, 10); + Settings theSettings = Settings.settingsBuilder(). + put("index.foo.bar", 42) + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, numReplicas) + .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, numShards).build(); + + Settings nodeSettings = Settings.settingsBuilder().put("node.foo.bar", 43).build(); + final AtomicInteger indexValue = new AtomicInteger(0); + final AtomicInteger nodeValue = new AtomicInteger(0); + Consumer settingsConsumer = (s) -> {indexValue.set(s.getAsInt("index.foo.bar", -1)); nodeValue.set(s.getAsInt("node.foo.bar", -1));}; + IndexSettings settings = new IndexSettings(newIndexMeta("index", theSettings), nodeSettings, Collections.singleton(settingsConsumer)); + assertEquals(numReplicas, settings.getNumberOfReplicas()); + assertEquals(numShards, settings.getNumberOfShards()); + assertEquals(0, indexValue.get()); + assertEquals(0, nodeValue.get()); + + assertTrue(settings.updateIndexMetaData(newIndexMeta("index", Settings.settingsBuilder(). + put("index.foo.bar", 42) + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, numReplicas + 1) + .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, numShards).build()))); + + assertEquals(42, indexValue.get()); + assertEquals(43, nodeValue.get()); + assertSame(nodeSettings, settings.getNodeSettings()); + + + } + + private IndexMetaData newIndexMeta(String name, Settings indexSettings) { + Settings build = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1) + .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) + .put(indexSettings) + .build(); + IndexMetaData metaData = IndexMetaData.builder(name).settings(build).build(); + return metaData; } diff --git a/core/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java b/core/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java index 9e5f847fa1e..5c738501a03 100644 --- a/core/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java +++ b/core/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java @@ -40,7 +40,7 @@ import org.elasticsearch.index.Index; import org.elasticsearch.index.analysis.filter1.MyFilterTokenFilterFactory; import org.elasticsearch.indices.analysis.IndicesAnalysisService; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.test.IndexNameAndSettingsModule; +import org.elasticsearch.test.IndexSettingsModule; import org.elasticsearch.test.VersionUtils; import org.hamcrest.MatcherAssert; @@ -68,7 +68,7 @@ public class AnalysisModuleTests extends ESTestCase { AnalysisModule analysisModule = new AnalysisModule(settings, parentInjector.getInstance(IndicesAnalysisService.class)); analysisModule.addTokenFilter("myfilter", MyFilterTokenFilterFactory.class); injector = new ModulesBuilder().add( - new IndexNameAndSettingsModule(index, settings), + new IndexSettingsModule(index, settings), analysisModule) .createChildInjector(parentInjector); diff --git a/core/src/test/java/org/elasticsearch/index/analysis/AnalysisServiceTests.java b/core/src/test/java/org/elasticsearch/index/analysis/AnalysisServiceTests.java index 20f4733faa3..981deeccf46 100644 --- a/core/src/test/java/org/elasticsearch/index/analysis/AnalysisServiceTests.java +++ b/core/src/test/java/org/elasticsearch/index/analysis/AnalysisServiceTests.java @@ -28,6 +28,7 @@ import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.indices.analysis.IndicesAnalysisService; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.IndexSettingsModule; import org.elasticsearch.test.VersionUtils; import java.util.Collections; @@ -39,19 +40,14 @@ import static org.hamcrest.Matchers.instanceOf; public class AnalysisServiceTests extends ESTestCase { private static AnalyzerProviderFactory analyzerProvider(final String name) { - return new AnalyzerProviderFactory() { - @Override - public AnalyzerProvider create(String name, Settings settings) { - return new PreBuiltAnalyzerProvider(name, AnalyzerScope.INDEX, new EnglishAnalyzer()); - } - }; + return (name1, settings) -> new PreBuiltAnalyzerProvider(name1, AnalyzerScope.INDEX, new EnglishAnalyzer()); } public void testDefaultAnalyzers() { Version version = VersionUtils.randomVersion(getRandom()); Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); IndicesAnalysisService indicesAnalysisService = new IndicesAnalysisService(settings); - AnalysisService analysisService = new AnalysisService(new IndexSettings(new Index("index"), settings, Collections.EMPTY_LIST), indicesAnalysisService, + AnalysisService analysisService = new AnalysisService(IndexSettingsModule.newIndexSettings(new Index("index"), settings, Collections.EMPTY_LIST), indicesAnalysisService, Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap()); assertThat(analysisService.defaultIndexAnalyzer().analyzer(), instanceOf(StandardAnalyzer.class)); assertThat(analysisService.defaultSearchAnalyzer().analyzer(), instanceOf(StandardAnalyzer.class)); @@ -62,7 +58,7 @@ public class AnalysisServiceTests extends ESTestCase { Version version = VersionUtils.randomVersion(getRandom()); Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); IndicesAnalysisService indicesAnalysisService = new IndicesAnalysisService(settings); - AnalysisService analysisService = new AnalysisService(new IndexSettings(new Index("index"), settings, Collections.EMPTY_LIST), indicesAnalysisService, + AnalysisService analysisService = new AnalysisService(IndexSettingsModule.newIndexSettings(new Index("index"), settings, Collections.EMPTY_LIST), indicesAnalysisService, Collections.singletonMap("default", analyzerProvider("default")), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap()); assertThat(analysisService.defaultIndexAnalyzer().analyzer(), instanceOf(EnglishAnalyzer.class)); @@ -75,7 +71,7 @@ public class AnalysisServiceTests extends ESTestCase { Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); IndicesAnalysisService indicesAnalysisService = new IndicesAnalysisService(settings); try { - AnalysisService analysisService = new AnalysisService(new IndexSettings(new Index("index"), settings, Collections.EMPTY_LIST), indicesAnalysisService, + AnalysisService analysisService = new AnalysisService(IndexSettingsModule.newIndexSettings(new Index("index"), settings, Collections.EMPTY_LIST), indicesAnalysisService, Collections.singletonMap("default_index", new PreBuiltAnalyzerProviderFactory("default_index", AnalyzerScope.INDEX, new EnglishAnalyzer())), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap()); fail("Expected ISE"); @@ -89,7 +85,7 @@ public class AnalysisServiceTests extends ESTestCase { Version version = VersionUtils.randomVersionBetween(getRandom(), VersionUtils.getFirstVersion(), VersionUtils.getPreviousVersion(Version.V_3_0_0)); Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); IndicesAnalysisService indicesAnalysisService = new IndicesAnalysisService(settings); - AnalysisService analysisService = new AnalysisService(new IndexSettings(new Index("index"), settings, Collections.EMPTY_LIST), indicesAnalysisService, + AnalysisService analysisService = new AnalysisService(IndexSettingsModule.newIndexSettings(new Index("index"), settings, Collections.EMPTY_LIST), indicesAnalysisService, Collections.singletonMap("default_index", analyzerProvider("default_index")), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap()); assertThat(analysisService.defaultIndexAnalyzer().analyzer(), instanceOf(EnglishAnalyzer.class)); @@ -101,7 +97,7 @@ public class AnalysisServiceTests extends ESTestCase { Version version = VersionUtils.randomVersion(getRandom()); Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); IndicesAnalysisService indicesAnalysisService = new IndicesAnalysisService(settings); - AnalysisService analysisService = new AnalysisService(new IndexSettings(new Index("index"), settings, Collections.EMPTY_LIST), indicesAnalysisService, + AnalysisService analysisService = new AnalysisService(IndexSettingsModule.newIndexSettings(new Index("index"), settings, Collections.EMPTY_LIST), indicesAnalysisService, Collections.singletonMap("default_search", analyzerProvider("default_search")), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap()); assertThat(analysisService.defaultIndexAnalyzer().analyzer(), instanceOf(StandardAnalyzer.class)); @@ -116,7 +112,7 @@ public class AnalysisServiceTests extends ESTestCase { Map analyzers = new HashMap<>(); analyzers.put("default_index", analyzerProvider("default_index")); analyzers.put("default_search", analyzerProvider("default_search")); - AnalysisService analysisService = new AnalysisService(new IndexSettings(new Index("index"), settings, Collections.EMPTY_LIST), indicesAnalysisService, + AnalysisService analysisService = new AnalysisService(IndexSettingsModule.newIndexSettings(new Index("index"), settings, Collections.EMPTY_LIST), indicesAnalysisService, analyzers, Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap()); assertThat(analysisService.defaultIndexAnalyzer().analyzer(), instanceOf(EnglishAnalyzer.class)); assertThat(analysisService.defaultSearchAnalyzer().analyzer(), instanceOf(EnglishAnalyzer.class)); diff --git a/core/src/test/java/org/elasticsearch/index/analysis/AnalysisTestsHelper.java b/core/src/test/java/org/elasticsearch/index/analysis/AnalysisTestsHelper.java index 67367ac11aa..8459341dac4 100644 --- a/core/src/test/java/org/elasticsearch/index/analysis/AnalysisTestsHelper.java +++ b/core/src/test/java/org/elasticsearch/index/analysis/AnalysisTestsHelper.java @@ -30,7 +30,7 @@ import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.index.Index; import org.elasticsearch.indices.IndicesModule; import org.elasticsearch.indices.analysis.IndicesAnalysisService; -import org.elasticsearch.test.IndexNameAndSettingsModule; +import org.elasticsearch.test.IndexSettingsModule; import java.nio.file.Path; @@ -64,7 +64,7 @@ public class AnalysisTestsHelper { AnalysisModule analysisModule = new AnalysisModule(settings, parentInjector.getInstance(IndicesAnalysisService.class)); - Injector injector = new ModulesBuilder().add(new IndexNameAndSettingsModule(index, settings), + Injector injector = new ModulesBuilder().add(new IndexSettingsModule(index, settings), analysisModule).createChildInjector(parentInjector); return injector.getInstance(AnalysisService.class); diff --git a/core/src/test/java/org/elasticsearch/index/analysis/CharFilterTests.java b/core/src/test/java/org/elasticsearch/index/analysis/CharFilterTests.java index f15d2fe4683..aa95a305433 100644 --- a/core/src/test/java/org/elasticsearch/index/analysis/CharFilterTests.java +++ b/core/src/test/java/org/elasticsearch/index/analysis/CharFilterTests.java @@ -29,7 +29,7 @@ import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.index.Index; import org.elasticsearch.indices.analysis.IndicesAnalysisService; import org.elasticsearch.test.ESTokenStreamTestCase; -import org.elasticsearch.test.IndexNameAndSettingsModule; +import org.elasticsearch.test.IndexSettingsModule; import static org.elasticsearch.common.settings.Settings.settingsBuilder; @@ -48,7 +48,7 @@ public class CharFilterTests extends ESTokenStreamTestCase { .build(); Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings))).createInjector(); Injector injector = new ModulesBuilder().add( - new IndexNameAndSettingsModule(index, settings), + new IndexSettingsModule(index, settings), new AnalysisModule(settings, parentInjector.getInstance(IndicesAnalysisService.class))) .createChildInjector(parentInjector); @@ -72,7 +72,7 @@ public class CharFilterTests extends ESTokenStreamTestCase { .build(); Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings))).createInjector(); Injector injector = new ModulesBuilder().add( - new IndexNameAndSettingsModule(index, settings), + new IndexSettingsModule(index, settings), new AnalysisModule(settings, parentInjector.getInstance(IndicesAnalysisService.class))) .createChildInjector(parentInjector); diff --git a/core/src/test/java/org/elasticsearch/index/analysis/CompoundAnalysisTests.java b/core/src/test/java/org/elasticsearch/index/analysis/CompoundAnalysisTests.java index 0a968a12410..0c7150ec471 100644 --- a/core/src/test/java/org/elasticsearch/index/analysis/CompoundAnalysisTests.java +++ b/core/src/test/java/org/elasticsearch/index/analysis/CompoundAnalysisTests.java @@ -37,7 +37,7 @@ import org.elasticsearch.index.analysis.compound.DictionaryCompoundWordTokenFilt import org.elasticsearch.index.analysis.filter1.MyFilterTokenFilterFactory; import org.elasticsearch.indices.analysis.IndicesAnalysisService; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.test.IndexNameAndSettingsModule; +import org.elasticsearch.test.IndexSettingsModule; import org.hamcrest.MatcherAssert; import java.io.IOException; @@ -59,7 +59,7 @@ public class CompoundAnalysisTests extends ESTestCase { AnalysisModule analysisModule = new AnalysisModule(settings, parentInjector.getInstance(IndicesAnalysisService.class)); analysisModule.addTokenFilter("myfilter", MyFilterTokenFilterFactory.class); Injector injector = new ModulesBuilder().add( - new IndexNameAndSettingsModule(index, settings), + new IndexSettingsModule(index, settings), analysisModule) .createChildInjector(parentInjector); @@ -84,7 +84,7 @@ public class CompoundAnalysisTests extends ESTestCase { AnalysisModule analysisModule = new AnalysisModule(settings, parentInjector.getInstance(IndicesAnalysisService.class)); analysisModule.addTokenFilter("myfilter", MyFilterTokenFilterFactory.class); Injector injector = new ModulesBuilder().add( - new IndexNameAndSettingsModule(index, settings), + new IndexSettingsModule(index, settings), analysisModule) .createChildInjector(parentInjector); diff --git a/core/src/test/java/org/elasticsearch/index/analysis/NGramTokenizerFactoryTests.java b/core/src/test/java/org/elasticsearch/index/analysis/NGramTokenizerFactoryTests.java index dd588f1fae9..b7d3201778d 100644 --- a/core/src/test/java/org/elasticsearch/index/analysis/NGramTokenizerFactoryTests.java +++ b/core/src/test/java/org/elasticsearch/index/analysis/NGramTokenizerFactoryTests.java @@ -36,6 +36,7 @@ import org.elasticsearch.common.settings.Settings.Builder; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.test.ESTokenStreamTestCase; +import org.elasticsearch.test.IndexSettingsModule; import java.io.IOException; import java.io.StringReader; @@ -51,7 +52,7 @@ public class NGramTokenizerFactoryTests extends ESTokenStreamTestCase { final Index index = new Index("test"); final String name = "ngr"; final Settings indexSettings = newAnalysisSettingsBuilder().build(); - IndexSettings indexProperties = new IndexSettings(index, indexSettings, Collections.EMPTY_LIST); + IndexSettings indexProperties = IndexSettingsModule.newIndexSettings(index, indexSettings, Collections.EMPTY_LIST); for (String tokenChars : Arrays.asList("letters", "number", "DIRECTIONALITY_UNDEFINED")) { final Settings settings = newAnalysisSettingsBuilder().put("min_gram", 2).put("max_gram", 3).put("token_chars", tokenChars).build(); try { @@ -63,7 +64,7 @@ public class NGramTokenizerFactoryTests extends ESTokenStreamTestCase { } for (String tokenChars : Arrays.asList("letter", " digit ", "punctuation", "DIGIT", "CoNtRoL", "dash_punctuation")) { final Settings settings = newAnalysisSettingsBuilder().put("min_gram", 2).put("max_gram", 3).put("token_chars", tokenChars).build(); - indexProperties = new IndexSettings(index, indexSettings, Collections.EMPTY_LIST); + indexProperties = IndexSettingsModule.newIndexSettings(index, indexSettings, Collections.EMPTY_LIST); new NGramTokenizerFactory(indexProperties, name, settings).create(); // no exception @@ -75,7 +76,7 @@ public class NGramTokenizerFactoryTests extends ESTokenStreamTestCase { final String name = "ngr"; final Settings indexSettings = newAnalysisSettingsBuilder().build(); final Settings settings = newAnalysisSettingsBuilder().put("min_gram", 2).put("max_gram", 4).putArray("token_chars", new String[0]).build(); - Tokenizer tokenizer = new NGramTokenizerFactory(new IndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(); + Tokenizer tokenizer = new NGramTokenizerFactory(IndexSettingsModule.newIndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(); tokenizer.setReader(new StringReader("1.34")); assertTokenStreamContents(tokenizer, new String[] {"1.", "1.3", "1.34", ".3", ".34", "34"}); } @@ -86,12 +87,12 @@ public class NGramTokenizerFactoryTests extends ESTokenStreamTestCase { final String name = "ngr"; final Settings indexSettings = newAnalysisSettingsBuilder().build(); Settings settings = newAnalysisSettingsBuilder().put("min_gram", 2).put("max_gram", 3).put("token_chars", "letter,digit").build(); - Tokenizer tokenizer = new NGramTokenizerFactory(new IndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(); + Tokenizer tokenizer = new NGramTokenizerFactory(IndexSettingsModule.newIndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(); tokenizer.setReader(new StringReader("Åbc déf g\uD801\uDC00f ")); assertTokenStreamContents(tokenizer, new String[] {"Åb", "Åbc", "bc", "dé", "déf", "éf", "g\uD801\uDC00", "g\uD801\uDC00f", "\uD801\uDC00f"}); settings = newAnalysisSettingsBuilder().put("min_gram", 2).put("max_gram", 3).put("token_chars", "letter,digit,punctuation,whitespace,symbol").build(); - tokenizer = new NGramTokenizerFactory(new IndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(); + tokenizer = new NGramTokenizerFactory(IndexSettingsModule.newIndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(); tokenizer.setReader(new StringReader(" a!$ 9")); assertTokenStreamContents(tokenizer, new String[] {" a", " a!", "a!", "a!$", "!$", "!$ ", "$ ", "$ 9", " 9"}); @@ -103,12 +104,12 @@ public class NGramTokenizerFactoryTests extends ESTokenStreamTestCase { final String name = "ngr"; final Settings indexSettings = newAnalysisSettingsBuilder().build(); Settings settings = newAnalysisSettingsBuilder().put("min_gram", 2).put("max_gram", 3).put("token_chars", "letter,digit").build(); - Tokenizer tokenizer = new EdgeNGramTokenizerFactory(new IndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(); + Tokenizer tokenizer = new EdgeNGramTokenizerFactory(IndexSettingsModule.newIndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(); tokenizer.setReader(new StringReader("Åbc déf g\uD801\uDC00f ")); assertTokenStreamContents(tokenizer, new String[] {"Åb", "Åbc", "dé", "déf", "g\uD801\uDC00", "g\uD801\uDC00f"}); settings = newAnalysisSettingsBuilder().put("min_gram", 2).put("max_gram", 3).put("token_chars", "letter,digit,punctuation,whitespace,symbol").build(); - tokenizer = new EdgeNGramTokenizerFactory(new IndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(); + tokenizer = new EdgeNGramTokenizerFactory(IndexSettingsModule.newIndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(); tokenizer.setReader(new StringReader(" a!$ 9")); assertTokenStreamContents(tokenizer, new String[] {" a", " a!"}); @@ -129,7 +130,7 @@ public class NGramTokenizerFactoryTests extends ESTokenStreamTestCase { } Settings settings = builder.build(); Settings indexSettings = newAnalysisSettingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, v.id).build(); - Tokenizer edgeNGramTokenizer = new EdgeNGramTokenizerFactory(new IndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(); + Tokenizer edgeNGramTokenizer = new EdgeNGramTokenizerFactory(IndexSettingsModule.newIndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(); edgeNGramTokenizer.setReader(new StringReader("foo bar")); if (compatVersion) { assertThat(edgeNGramTokenizer, instanceOf(Lucene43EdgeNGramTokenizer.class)); @@ -140,7 +141,7 @@ public class NGramTokenizerFactoryTests extends ESTokenStreamTestCase { } else { Settings settings = newAnalysisSettingsBuilder().put("min_gram", 2).put("max_gram", 3).put("side", "back").build(); Settings indexSettings = newAnalysisSettingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, v.id).build(); - Tokenizer edgeNGramTokenizer = new EdgeNGramTokenizerFactory(new IndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(); + Tokenizer edgeNGramTokenizer = new EdgeNGramTokenizerFactory(IndexSettingsModule.newIndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(); edgeNGramTokenizer.setReader(new StringReader("foo bar")); assertThat(edgeNGramTokenizer, instanceOf(Lucene43EdgeNGramTokenizer.class)); } @@ -148,7 +149,7 @@ public class NGramTokenizerFactoryTests extends ESTokenStreamTestCase { Settings settings = newAnalysisSettingsBuilder().put("min_gram", 2).put("max_gram", 3).put("side", "back").build(); Settings indexSettings = newAnalysisSettingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); try { - new EdgeNGramTokenizerFactory(new IndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(); + new EdgeNGramTokenizerFactory(IndexSettingsModule.newIndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(); fail("should fail side:back is not supported anymore"); } catch (IllegalArgumentException ex) { } @@ -169,7 +170,7 @@ public class NGramTokenizerFactoryTests extends ESTokenStreamTestCase { } Settings settings = builder.build(); Settings indexSettings = newAnalysisSettingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, v.id).build(); - Tokenizer nGramTokenizer = new NGramTokenizerFactory(new IndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(); + Tokenizer nGramTokenizer = new NGramTokenizerFactory(IndexSettingsModule.newIndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(); nGramTokenizer.setReader(new StringReader("foo bar")); if (compatVersion) { assertThat(nGramTokenizer, instanceOf(Lucene43NGramTokenizer.class)); @@ -180,7 +181,7 @@ public class NGramTokenizerFactoryTests extends ESTokenStreamTestCase { } else { Settings settings = newAnalysisSettingsBuilder().put("min_gram", 2).put("max_gram", 3).build(); Settings indexSettings = newAnalysisSettingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, v.id).build(); - Tokenizer nGramTokenizer = new NGramTokenizerFactory(new IndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(); + Tokenizer nGramTokenizer = new NGramTokenizerFactory(IndexSettingsModule.newIndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(); nGramTokenizer.setReader(new StringReader("foo bar")); assertThat(nGramTokenizer, instanceOf(Lucene43NGramTokenizer.class)); } @@ -207,7 +208,7 @@ public class NGramTokenizerFactoryTests extends ESTokenStreamTestCase { Settings indexSettings = newAnalysisSettingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, v.id).build(); Tokenizer tokenizer = new MockTokenizer(); tokenizer.setReader(new StringReader("foo bar")); - TokenStream edgeNGramTokenFilter = new EdgeNGramTokenFilterFactory(new IndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(tokenizer); + TokenStream edgeNGramTokenFilter = new EdgeNGramTokenFilterFactory(IndexSettingsModule.newIndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(tokenizer); if (reverse) { assertThat(edgeNGramTokenFilter, instanceOf(ReverseStringFilter.class)); } else if (compatVersion) { @@ -226,7 +227,7 @@ public class NGramTokenizerFactoryTests extends ESTokenStreamTestCase { Settings indexSettings = newAnalysisSettingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, v.id).build(); Tokenizer tokenizer = new MockTokenizer(); tokenizer.setReader(new StringReader("foo bar")); - TokenStream edgeNGramTokenFilter = new EdgeNGramTokenFilterFactory(new IndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(tokenizer); + TokenStream edgeNGramTokenFilter = new EdgeNGramTokenFilterFactory(IndexSettingsModule.newIndexSettings(index, indexSettings, Collections.EMPTY_LIST), name, settings).create(tokenizer); if (reverse) { assertThat(edgeNGramTokenFilter, instanceOf(ReverseStringFilter.class)); } else { diff --git a/core/src/test/java/org/elasticsearch/index/analysis/PatternCaptureTokenFilterTests.java b/core/src/test/java/org/elasticsearch/index/analysis/PatternCaptureTokenFilterTests.java index 12984741c6b..a74079ec285 100644 --- a/core/src/test/java/org/elasticsearch/index/analysis/PatternCaptureTokenFilterTests.java +++ b/core/src/test/java/org/elasticsearch/index/analysis/PatternCaptureTokenFilterTests.java @@ -31,7 +31,7 @@ import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.indices.analysis.IndicesAnalysisService; import org.elasticsearch.test.ESTokenStreamTestCase; -import org.elasticsearch.test.IndexNameAndSettingsModule; +import org.elasticsearch.test.IndexSettingsModule; import java.util.Collections; @@ -49,7 +49,7 @@ public class PatternCaptureTokenFilterTests extends ESTokenStreamTestCase { .build(); Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings))).createInjector(); Injector injector = new ModulesBuilder().add( - new IndexNameAndSettingsModule(index, settings), + new IndexSettingsModule(index, settings), new AnalysisModule(settings, parentInjector.getInstance(IndicesAnalysisService.class))) .createChildInjector(parentInjector); @@ -70,7 +70,7 @@ public class PatternCaptureTokenFilterTests extends ESTokenStreamTestCase { public void testNoPatterns() { try { - new PatternCaptureGroupTokenFilterFactory(new IndexSettings(new Index("test"), settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(), Collections.EMPTY_LIST), "pattern_capture", settingsBuilder().put("pattern", "foobar").build()); + new PatternCaptureGroupTokenFilterFactory(IndexSettingsModule.newIndexSettings(new Index("test"), Settings.EMPTY, Collections.EMPTY_LIST), "pattern_capture", settingsBuilder().put("pattern", "foobar").build()); fail ("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), containsString("required setting 'patterns' is missing")); diff --git a/core/src/test/java/org/elasticsearch/index/analysis/StopAnalyzerTests.java b/core/src/test/java/org/elasticsearch/index/analysis/StopAnalyzerTests.java index 1e48756d179..0379fced877 100644 --- a/core/src/test/java/org/elasticsearch/index/analysis/StopAnalyzerTests.java +++ b/core/src/test/java/org/elasticsearch/index/analysis/StopAnalyzerTests.java @@ -30,7 +30,7 @@ import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.index.Index; import org.elasticsearch.indices.analysis.IndicesAnalysisService; import org.elasticsearch.test.ESTokenStreamTestCase; -import org.elasticsearch.test.IndexNameAndSettingsModule; +import org.elasticsearch.test.IndexSettingsModule; import static org.elasticsearch.common.settings.Settings.settingsBuilder; @@ -45,7 +45,7 @@ public class StopAnalyzerTests extends ESTokenStreamTestCase { .build(); Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings))).createInjector(); Injector injector = new ModulesBuilder().add( - new IndexNameAndSettingsModule(index, settings), + new IndexSettingsModule(index, settings), new AnalysisModule(settings, parentInjector.getInstance(IndicesAnalysisService.class))) .createChildInjector(parentInjector); diff --git a/core/src/test/java/org/elasticsearch/index/analysis/synonyms/SynonymsAnalysisTests.java b/core/src/test/java/org/elasticsearch/index/analysis/synonyms/SynonymsAnalysisTests.java index 23c77390f30..de67c578b01 100644 --- a/core/src/test/java/org/elasticsearch/index/analysis/synonyms/SynonymsAnalysisTests.java +++ b/core/src/test/java/org/elasticsearch/index/analysis/synonyms/SynonymsAnalysisTests.java @@ -39,7 +39,7 @@ import org.elasticsearch.index.analysis.AnalysisModule; import org.elasticsearch.index.analysis.AnalysisService; import org.elasticsearch.indices.analysis.IndicesAnalysisService; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.test.IndexNameAndSettingsModule; +import org.elasticsearch.test.IndexSettingsModule; import org.hamcrest.MatcherAssert; import java.io.IOException; @@ -78,7 +78,7 @@ public class SynonymsAnalysisTests extends ESTestCase { new EnvironmentModule(new Environment(settings))) .createInjector(); Injector injector = new ModulesBuilder().add( - new IndexNameAndSettingsModule(index, settings), + new IndexSettingsModule(index, settings), new AnalysisModule(settings, parentInjector.getInstance(IndicesAnalysisService.class))) .createChildInjector(parentInjector); diff --git a/core/src/test/java/org/elasticsearch/index/cache/bitset/BitSetFilterCacheTests.java b/core/src/test/java/org/elasticsearch/index/cache/bitset/BitSetFilterCacheTests.java index f658bbe6a14..3d2a001c049 100644 --- a/core/src/test/java/org/elasticsearch/index/cache/bitset/BitSetFilterCacheTests.java +++ b/core/src/test/java/org/elasticsearch/index/cache/bitset/BitSetFilterCacheTests.java @@ -44,6 +44,7 @@ import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.IndexSettingsModule; import java.io.IOException; import java.util.Collections; @@ -54,7 +55,7 @@ import static org.hamcrest.Matchers.equalTo; public class BitSetFilterCacheTests extends ESTestCase { - private static final IndexSettings INDEX_SETTINGS = new IndexSettings(new Index("test"), Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, org.elasticsearch.Version.CURRENT).build(), Collections.emptyList()); + private static final IndexSettings INDEX_SETTINGS = IndexSettingsModule.newIndexSettings(new Index("test"), Settings.EMPTY, Collections.emptyList()); private static int matchCount(BitSetProducer producer, IndexReader reader) throws IOException { int count = 0; 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 dbb54e9c26b..8c72483fb60 100644 --- a/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java +++ b/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java @@ -97,6 +97,7 @@ import org.elasticsearch.index.translog.Translog; import org.elasticsearch.index.translog.TranslogConfig; import org.elasticsearch.test.DummyShardLock; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.IndexSettingsModule; import org.elasticsearch.threadpool.ThreadPool; import org.hamcrest.MatcherAssert; import org.junit.After; @@ -134,7 +135,7 @@ import static org.hamcrest.Matchers.nullValue; public class InternalEngineTests extends ESTestCase { protected final ShardId shardId = new ShardId(new Index("index"), 1); - private static final IndexSettings INDEX_SETTINGS = new IndexSettings(new Index("index"), Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, org.elasticsearch.Version.CURRENT).build(), Collections.emptyList()); + private static final IndexSettings INDEX_SETTINGS = IndexSettingsModule.newIndexSettings(new Index("index"), Settings.EMPTY, Collections.emptyList()); protected ThreadPool threadPool; @@ -266,7 +267,7 @@ public class InternalEngineTests extends ESTestCase { public EngineConfig config(Settings indexSettings, Store store, Path translogPath, MergeSchedulerConfig mergeSchedulerConfig, MergePolicy mergePolicy) { IndexWriterConfig iwc = newIndexWriterConfig(); - TranslogConfig translogConfig = new TranslogConfig(shardId, translogPath, new IndexSettings(shardId.index(), indexSettings, Collections.emptyList()), Translog.Durabilty.REQUEST, BigArrays.NON_RECYCLING_INSTANCE, threadPool); + TranslogConfig translogConfig = new TranslogConfig(shardId, translogPath, IndexSettingsModule.newIndexSettings(shardId.index(), indexSettings, Collections.emptyList()), Translog.Durabilty.REQUEST, BigArrays.NON_RECYCLING_INSTANCE, threadPool); EngineConfig config = new EngineConfig(shardId, threadPool, new ShardIndexingService(shardId, INDEX_SETTINGS), indexSettings , null, store, createSnapshotDeletionPolicy(), mergePolicy, mergeSchedulerConfig, @@ -1867,7 +1868,7 @@ public class InternalEngineTests extends ESTestCase { Settings settings = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); RootObjectMapper.Builder rootBuilder = new RootObjectMapper.Builder("test"); Index index = new Index(indexName); - IndexSettings indexSettings = new IndexSettings(index, settings, Collections.EMPTY_LIST); + IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings, Collections.EMPTY_LIST); AnalysisService analysisService = new AnalysisService(indexSettings); SimilarityService similarityService = new SimilarityService(indexSettings, Collections.EMPTY_MAP); MapperService mapperService = new MapperService(indexSettings, analysisService, similarityService, null); @@ -1917,7 +1918,7 @@ public class InternalEngineTests extends ESTestCase { EngineConfig config = engine.config(); /* create a TranslogConfig that has been created with a different UUID */ - TranslogConfig translogConfig = new TranslogConfig(shardId, translog.location(), new IndexSettings(shardId.index(), config.getIndexSettings(), Collections.EMPTY_LIST), Translog.Durabilty.REQUEST, BigArrays.NON_RECYCLING_INSTANCE, threadPool); + TranslogConfig translogConfig = new TranslogConfig(shardId, translog.location(), IndexSettingsModule.newIndexSettings(shardId.index(), config.getIndexSettings(), Collections.EMPTY_LIST), Translog.Durabilty.REQUEST, BigArrays.NON_RECYCLING_INSTANCE, threadPool); EngineConfig brokenConfig = new EngineConfig(shardId, threadPool, config.getIndexingService(), config.getIndexSettings() , null, store, createSnapshotDeletionPolicy(), newMergePolicy(), config.getMergeSchedulerConfig(), 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 a16a4863f61..8808c576cdb 100644 --- a/core/src/test/java/org/elasticsearch/index/engine/ShadowEngineTests.java +++ b/core/src/test/java/org/elasticsearch/index/engine/ShadowEngineTests.java @@ -63,6 +63,7 @@ import org.elasticsearch.index.translog.Translog; import org.elasticsearch.index.translog.TranslogConfig; import org.elasticsearch.test.DummyShardLock; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.IndexSettingsModule; import org.elasticsearch.threadpool.ThreadPool; import org.hamcrest.MatcherAssert; import org.junit.After; @@ -88,7 +89,7 @@ import static org.hamcrest.Matchers.nullValue; */ public class ShadowEngineTests extends ESTestCase { - private static final IndexSettings INDEX_SETTINGS = new IndexSettings(new Index("index"), Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, org.elasticsearch.Version.CURRENT).build(), Collections.emptyList()); + private static final IndexSettings INDEX_SETTINGS = IndexSettingsModule.newIndexSettings(new Index("index"), Settings.EMPTY, Collections.emptyList()); protected final ShardId shardId = new ShardId(new Index("index"), 1); @@ -183,7 +184,7 @@ public class ShadowEngineTests extends ESTestCase { protected Store createStore(final Directory directory) throws IOException { - IndexSettings indexSettings = new IndexSettings(shardId.index(), Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(), Collections.emptyList()); + IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(shardId.index(), Settings.EMPTY, Collections.emptyList()); final DirectoryService directoryService = new DirectoryService(shardId, indexSettings) { @Override public Directory newDirectory() throws IOException { @@ -224,8 +225,8 @@ public class ShadowEngineTests extends ESTestCase { public EngineConfig config(Settings indexSettings, Store store, Path translogPath, MergeSchedulerConfig mergeSchedulerConfig, MergePolicy mergePolicy) { IndexWriterConfig iwc = newIndexWriterConfig(); - TranslogConfig translogConfig = new TranslogConfig(shardId, translogPath, new IndexSettings(shardId.index(), indexSettings, Collections.EMPTY_LIST), Translog.Durabilty.REQUEST, BigArrays.NON_RECYCLING_INSTANCE, threadPool); - EngineConfig config = new EngineConfig(shardId, threadPool, new ShardIndexingService(shardId, new IndexSettings(shardId.index(), indexSettings, Collections.EMPTY_LIST)), indexSettings + 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() { @Override diff --git a/core/src/test/java/org/elasticsearch/index/fielddata/IndexFieldDataServiceTests.java b/core/src/test/java/org/elasticsearch/index/fielddata/IndexFieldDataServiceTests.java index 9f82019941d..24422870794 100644 --- a/core/src/test/java/org/elasticsearch/index/fielddata/IndexFieldDataServiceTests.java +++ b/core/src/test/java/org/elasticsearch/index/fielddata/IndexFieldDataServiceTests.java @@ -44,6 +44,7 @@ import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.indices.breaker.CircuitBreakerService; import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache; import org.elasticsearch.test.ESSingleNodeTestCase; +import org.elasticsearch.test.IndexSettingsModule; import org.elasticsearch.threadpool.ThreadPool; import java.util.Arrays; @@ -195,7 +196,7 @@ public class IndexFieldDataServiceTests extends ESSingleNodeTestCase { ThreadPool threadPool = new ThreadPool("random_threadpool_name"); try { IndicesFieldDataCache cache = new IndicesFieldDataCache(Settings.EMPTY, null, threadPool); - IndexFieldDataService ifds = new IndexFieldDataService(new IndexSettings(new Index("test"), Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(), Collections.EMPTY_LIST), cache, null, null); + IndexFieldDataService ifds = new IndexFieldDataService(IndexSettingsModule.newIndexSettings(new Index("test"), Settings.EMPTY, Collections.EMPTY_LIST), cache, null, null); ft.setNames(new Names("some_long")); ft.setHasDocValues(true); ifds.getForField(ft); // no exception diff --git a/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java b/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java index 55f1a1ffb04..e45ba75b018 100644 --- a/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java +++ b/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java @@ -79,7 +79,7 @@ import org.elasticsearch.script.ScriptService; import org.elasticsearch.script.mustache.MustacheScriptEngineService; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.test.IndexNameAndSettingsModule; +import org.elasticsearch.test.IndexSettingsModule; import org.elasticsearch.test.TestSearchContext; import org.elasticsearch.test.VersionUtils; import org.elasticsearch.test.cluster.TestClusterService; @@ -212,10 +212,10 @@ public abstract class AbstractQueryTestCase> } }, - new IndexNameAndSettingsModule(index, indexSettings), + new IndexSettingsModule(index, indexSettings), new IndexCacheModule(indexSettings), new AnalysisModule(indexSettings, new IndicesAnalysisService(indexSettings)), - new SimilarityModule(new IndexSettings(index, indexSettings, Collections.EMPTY_LIST)), + new SimilarityModule(IndexSettingsModule.newIndexSettings(index, indexSettings, Collections.EMPTY_LIST)), new AbstractModule() { @Override protected void configure() { diff --git a/core/src/test/java/org/elasticsearch/index/query/TemplateQueryParserTests.java b/core/src/test/java/org/elasticsearch/index/query/TemplateQueryParserTests.java index d0294669420..5a936745f02 100644 --- a/core/src/test/java/org/elasticsearch/index/query/TemplateQueryParserTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/TemplateQueryParserTests.java @@ -48,7 +48,7 @@ import org.elasticsearch.indices.breaker.CircuitBreakerService; import org.elasticsearch.indices.breaker.NoneCircuitBreakerService; import org.elasticsearch.script.ScriptModule; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.test.IndexNameAndSettingsModule; +import org.elasticsearch.test.IndexSettingsModule; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPoolModule; import org.junit.After; @@ -95,10 +95,10 @@ public class TemplateQueryParserTests extends ESTestCase { } }, new ScriptModule(settings), - new IndexNameAndSettingsModule(index, settings), + new IndexSettingsModule(index, settings), new IndexCacheModule(settings), new AnalysisModule(settings, new IndicesAnalysisService(settings)), - new SimilarityModule(new IndexSettings(index, settings, Collections.EMPTY_LIST)), + new SimilarityModule(IndexSettingsModule.newIndexSettings(index, settings, Collections.EMPTY_LIST)), new AbstractModule() { @Override protected void configure() { diff --git a/core/src/test/java/org/elasticsearch/index/shard/NewPathForShardTests.java b/core/src/test/java/org/elasticsearch/index/shard/NewPathForShardTests.java index 5036d25a108..2013aa058ec 100644 --- a/core/src/test/java/org/elasticsearch/index/shard/NewPathForShardTests.java +++ b/core/src/test/java/org/elasticsearch/index/shard/NewPathForShardTests.java @@ -30,6 +30,7 @@ import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.IndexSettingsModule; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -49,7 +50,7 @@ import java.util.Map; /** Separate test class from ShardPathTests because we need static (BeforeClass) setup to install mock filesystems... */ public class NewPathForShardTests extends ESTestCase { - private static final IndexSettings INDEX_SETTINGS = new IndexSettings(new Index("index"), Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, org.elasticsearch.Version.CURRENT).build(), Collections.emptyList()); + private static final IndexSettings INDEX_SETTINGS = IndexSettingsModule.newIndexSettings(new Index("index"), Settings.EMPTY, Collections.emptyList()); // Sneakiness to install mock file stores so we can pretend how much free space we have on each path.data: private static MockFileStore aFileStore = new MockFileStore("mocka"); diff --git a/core/src/test/java/org/elasticsearch/index/shard/ShardPathTests.java b/core/src/test/java/org/elasticsearch/index/shard/ShardPathTests.java index 51b4d2d97c4..3e973080416 100644 --- a/core/src/test/java/org/elasticsearch/index/shard/ShardPathTests.java +++ b/core/src/test/java/org/elasticsearch/index/shard/ShardPathTests.java @@ -24,6 +24,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.IndexSettingsModule; import java.io.IOException; import java.nio.file.Path; @@ -45,7 +46,7 @@ public class ShardPathTests extends ESTestCase { Path[] paths = env.availableShardPaths(shardId); Path path = randomFrom(paths); ShardStateMetaData.FORMAT.write(new ShardStateMetaData(2, true, "0xDEADBEEF"), 2, path); - ShardPath shardPath = ShardPath.loadShardPath(logger, env, shardId, new IndexSettings(shardId.index(), settings, Collections.EMPTY_LIST)); + ShardPath shardPath = ShardPath.loadShardPath(logger, env, shardId, IndexSettingsModule.newIndexSettings(shardId.index(), settings, Collections.EMPTY_LIST)); assertEquals(path, shardPath.getDataPath()); assertEquals("0xDEADBEEF", shardPath.getIndexUUID()); assertEquals("foo", shardPath.getShardId().getIndex()); @@ -64,7 +65,7 @@ public class ShardPathTests extends ESTestCase { assumeTrue("This test tests multi data.path but we only got one", paths.length > 1); int id = randomIntBetween(1, 10); ShardStateMetaData.FORMAT.write(new ShardStateMetaData(id, true, "0xDEADBEEF"), id, paths); - ShardPath.loadShardPath(logger, env, shardId, new IndexSettings(shardId.index(), settings, Collections.EMPTY_LIST)); + ShardPath.loadShardPath(logger, env, shardId, IndexSettingsModule.newIndexSettings(shardId.index(), settings, Collections.EMPTY_LIST)); fail("Expected IllegalStateException"); } catch (IllegalStateException e) { assertThat(e.getMessage(), containsString("more than one shard state found")); @@ -81,7 +82,7 @@ public class ShardPathTests extends ESTestCase { Path path = randomFrom(paths); int id = randomIntBetween(1, 10); ShardStateMetaData.FORMAT.write(new ShardStateMetaData(id, true, "0xDEADBEEF"), id, path); - ShardPath.loadShardPath(logger, env, shardId, new IndexSettings(shardId.index(), settings, Collections.EMPTY_LIST)); + ShardPath.loadShardPath(logger, env, shardId, IndexSettingsModule.newIndexSettings(shardId.index(), settings, Collections.EMPTY_LIST)); fail("Expected IllegalStateException"); } catch (IllegalStateException e) { assertThat(e.getMessage(), containsString("expected: foobar on shard path")); @@ -135,7 +136,7 @@ public class ShardPathTests extends ESTestCase { Path[] paths = env.availableShardPaths(shardId); Path path = randomFrom(paths); ShardStateMetaData.FORMAT.write(new ShardStateMetaData(2, true, "0xDEADBEEF"), 2, path); - ShardPath shardPath = ShardPath.loadShardPath(logger, env, shardId, new IndexSettings(shardId.index(), indexSetttings, Collections.EMPTY_LIST)); + ShardPath shardPath = ShardPath.loadShardPath(logger, env, shardId, IndexSettingsModule.newIndexSettings(shardId.index(), indexSetttings, Collections.EMPTY_LIST)); boolean found = false; for (Path p : env.nodeDataPaths()) { if (p.equals(shardPath.getRootStatePath())) { diff --git a/core/src/test/java/org/elasticsearch/index/similarity/SimilarityModuleTests.java b/core/src/test/java/org/elasticsearch/index/similarity/SimilarityModuleTests.java index 91d9e510bdd..c7860d2c094 100644 --- a/core/src/test/java/org/elasticsearch/index/similarity/SimilarityModuleTests.java +++ b/core/src/test/java/org/elasticsearch/index/similarity/SimilarityModuleTests.java @@ -30,6 +30,7 @@ import org.elasticsearch.common.inject.ModuleTestCase; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexSettings; +import org.elasticsearch.test.IndexSettingsModule; import java.io.IOException; import java.util.Collections; @@ -42,7 +43,7 @@ public class SimilarityModuleTests extends ModuleTestCase { .put("index.similarity.my_similarity.type", "test_similarity") .put("index.similarity.my_similarity.key", "there is a key") .build(); - SimilarityModule module = new SimilarityModule(new IndexSettings(new Index("foo"), indexSettings, Collections.EMPTY_LIST)); + SimilarityModule module = new SimilarityModule(IndexSettingsModule.newIndexSettings(new Index("foo"), indexSettings, Collections.EMPTY_LIST)); module.addSimilarity("test_similarity", (string, settings) -> new SimilarityProvider() { @Override public String name() { @@ -71,7 +72,7 @@ public class SimilarityModuleTests extends ModuleTestCase { .put("index.similarity.my_similarity.type", "test_similarity") .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .build(); - SimilarityModule module = new SimilarityModule(new IndexSettings(new Index("foo"), indexSettings, Collections.EMPTY_LIST)); + SimilarityModule module = new SimilarityModule(IndexSettingsModule.newIndexSettings(new Index("foo"), indexSettings, Collections.EMPTY_LIST)); try { assertInstanceBinding(module, SimilarityService.class, (inst) -> inst instanceof SimilarityService); } catch (IllegalArgumentException ex) { @@ -85,7 +86,7 @@ public class SimilarityModuleTests extends ModuleTestCase { .put("index.similarity.my_similarity.foo", "bar") .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .build(); - SimilarityModule module = new SimilarityModule(new IndexSettings(new Index("foo"), indexSettings, Collections.EMPTY_LIST)); + SimilarityModule module = new SimilarityModule(IndexSettingsModule.newIndexSettings(new Index("foo"), indexSettings, Collections.EMPTY_LIST)); try { assertInstanceBinding(module, SimilarityService.class, (inst) -> inst instanceof SimilarityService); } catch (IllegalArgumentException ex) { diff --git a/core/src/test/java/org/elasticsearch/index/store/IndexStoreTests.java b/core/src/test/java/org/elasticsearch/index/store/IndexStoreTests.java index 9fca1f418d1..9228f075d61 100644 --- a/core/src/test/java/org/elasticsearch/index/store/IndexStoreTests.java +++ b/core/src/test/java/org/elasticsearch/index/store/IndexStoreTests.java @@ -29,6 +29,7 @@ import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardPath; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.IndexSettingsModule; import java.io.IOException; import java.nio.file.Path; @@ -45,7 +46,7 @@ public class IndexStoreTests extends ESTestCase { final IndexStoreModule.Type type = RandomPicks.randomFrom(random(), values); Settings settings = Settings.settingsBuilder().put(IndexStoreModule.STORE_TYPE, type.name().toLowerCase(Locale.ROOT)) .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); - IndexSettings indexSettings = new IndexSettings(new Index("foo"), settings, Collections.EMPTY_LIST); + 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))); try (final Directory directory = service.newFSDirectory(tempDir, NoLockFactory.INSTANCE)) { switch (type) { @@ -78,7 +79,7 @@ public class IndexStoreTests extends ESTestCase { public void testStoreDirectoryDefault() throws IOException { final Path tempDir = createTempDir().resolve("foo").resolve("0"); - FsDirectoryService service = new FsDirectoryService(new IndexSettings(new Index("foo"), Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(), Collections.EMPTY_LIST), null, new ShardPath(false, tempDir, tempDir, "foo", new ShardId("foo", 0))); + FsDirectoryService service = new FsDirectoryService(IndexSettingsModule.newIndexSettings(new Index("foo"), Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(), Collections.EMPTY_LIST), null, new ShardPath(false, tempDir, tempDir, "foo", new ShardId("foo", 0))); try (final Directory directory = service.newFSDirectory(tempDir, NoLockFactory.INSTANCE)) { if (Constants.WINDOWS) { assertTrue(directory.toString(), directory instanceof MMapDirectory || directory instanceof SimpleFSDirectory); diff --git a/core/src/test/java/org/elasticsearch/index/store/StoreTests.java b/core/src/test/java/org/elasticsearch/index/store/StoreTests.java index 9cbbbfa2c88..ef19eeee2f3 100644 --- a/core/src/test/java/org/elasticsearch/index/store/StoreTests.java +++ b/core/src/test/java/org/elasticsearch/index/store/StoreTests.java @@ -74,6 +74,7 @@ import org.elasticsearch.index.translog.Translog; import org.elasticsearch.indices.store.TransportNodesListShardStoreMetaData; import org.elasticsearch.test.DummyShardLock; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.IndexSettingsModule; import org.hamcrest.Matchers; import java.io.ByteArrayInputStream; @@ -100,7 +101,7 @@ import static org.hamcrest.Matchers.nullValue; public class StoreTests extends ESTestCase { - private static final IndexSettings INDEX_SETTINGS = new IndexSettings(new Index("index"), Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, org.elasticsearch.Version.CURRENT).build(), Collections.emptyList()); + private static final IndexSettings INDEX_SETTINGS = IndexSettingsModule.newIndexSettings(new Index("index"), Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, org.elasticsearch.Version.CURRENT).build(), Collections.emptyList()); public void testRefCount() throws IOException { final ShardId shardId = new ShardId(new Index("index"), 1); @@ -1146,7 +1147,7 @@ public class StoreTests extends ESTestCase { Settings settings = Settings.builder() .put(IndexMetaData.SETTING_VERSION_CREATED, org.elasticsearch.Version.CURRENT) .put(Store.INDEX_STORE_STATS_REFRESH_INTERVAL, TimeValue.timeValueMinutes(0)).build(); - Store store = new Store(shardId, new IndexSettings(new Index("index"), settings, Collections.EMPTY_LIST), directoryService, new DummyShardLock(shardId)); + Store store = new Store(shardId, IndexSettingsModule.newIndexSettings(new Index("index"), settings, Collections.EMPTY_LIST), directoryService, new DummyShardLock(shardId)); long initialStoreSize = 0; for (String extraFiles : store.directory().listAll()) { assertTrue("expected extraFS file but got: " + extraFiles, extraFiles.startsWith("extra")); diff --git a/core/src/test/java/org/elasticsearch/index/translog/BufferedTranslogTests.java b/core/src/test/java/org/elasticsearch/index/translog/BufferedTranslogTests.java index b24db82bcb1..8a0c3a8d6f9 100644 --- a/core/src/test/java/org/elasticsearch/index/translog/BufferedTranslogTests.java +++ b/core/src/test/java/org/elasticsearch/index/translog/BufferedTranslogTests.java @@ -24,6 +24,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.index.IndexSettings; +import org.elasticsearch.test.IndexSettingsModule; import java.io.IOException; import java.nio.file.Path; @@ -41,7 +42,7 @@ public class BufferedTranslogTests extends TranslogTests { .put("index.translog.fs.buffer_size", 10 + randomInt(128 * 1024), ByteSizeUnit.BYTES) .put(IndexMetaData.SETTING_VERSION_CREATED, org.elasticsearch.Version.CURRENT) .build(); - TranslogConfig translogConfig = new TranslogConfig(shardId, path, new IndexSettings(shardId.index(), build, Collections.EMPTY_LIST), Translog.Durabilty.REQUEST, BigArrays.NON_RECYCLING_INSTANCE, null); + TranslogConfig translogConfig = new TranslogConfig(shardId, path, IndexSettingsModule.newIndexSettings(shardId.index(), build, Collections.EMPTY_LIST), Translog.Durabilty.REQUEST, BigArrays.NON_RECYCLING_INSTANCE, null); return new Translog(translogConfig); } } diff --git a/core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java b/core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java index 2dbabba2e6a..10d79bbbddd 100644 --- a/core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java +++ b/core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java @@ -42,6 +42,7 @@ import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.VersionType; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.IndexSettingsModule; import org.hamcrest.Matchers; import org.junit.After; import org.junit.Before; @@ -130,7 +131,7 @@ public class TranslogTests extends ESTestCase { .put(TranslogConfig.INDEX_TRANSLOG_FS_TYPE, TranslogWriter.Type.SIMPLE.name()) .put(IndexMetaData.SETTING_VERSION_CREATED, org.elasticsearch.Version.CURRENT) .build(); - TranslogConfig translogConfig = new TranslogConfig(shardId, path, new IndexSettings(shardId.index(), build, Collections.EMPTY_LIST), Translog.Durabilty.REQUEST, BigArrays.NON_RECYCLING_INSTANCE, null); + TranslogConfig translogConfig = new TranslogConfig(shardId, path, IndexSettingsModule.newIndexSettings(shardId.index(), build, Collections.EMPTY_LIST), Translog.Durabilty.REQUEST, BigArrays.NON_RECYCLING_INSTANCE, null); return new Translog(translogConfig); } diff --git a/core/src/test/java/org/elasticsearch/indices/recovery/RecoverySourceHandlerTests.java b/core/src/test/java/org/elasticsearch/indices/recovery/RecoverySourceHandlerTests.java index 59d839911fa..27fa30d6a24 100644 --- a/core/src/test/java/org/elasticsearch/indices/recovery/RecoverySourceHandlerTests.java +++ b/core/src/test/java/org/elasticsearch/indices/recovery/RecoverySourceHandlerTests.java @@ -43,6 +43,7 @@ import org.elasticsearch.node.settings.NodeSettingsService; import org.elasticsearch.test.DummyShardLock; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.CorruptionUtils; +import org.elasticsearch.test.IndexSettingsModule; import java.io.IOException; import java.nio.file.Path; @@ -54,7 +55,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import static org.hamcrest.Matchers.is; public class RecoverySourceHandlerTests extends ESTestCase { - private static final IndexSettings INDEX_SETTINGS = new IndexSettings(new Index("index"), Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, org.elasticsearch.Version.CURRENT).build(), Collections.emptyList()); + private static final IndexSettings INDEX_SETTINGS = IndexSettingsModule.newIndexSettings(new Index("index"), Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, org.elasticsearch.Version.CURRENT).build(), Collections.emptyList()); private final ShardId shardId = new ShardId(INDEX_SETTINGS.getIndex(), 1); private final NodeSettingsService service = new NodeSettingsService(Settings.EMPTY); diff --git a/core/src/test/java/org/elasticsearch/test/IndexNameAndSettingsModule.java b/core/src/test/java/org/elasticsearch/test/IndexSettingsModule.java similarity index 55% rename from core/src/test/java/org/elasticsearch/test/IndexNameAndSettingsModule.java rename to core/src/test/java/org/elasticsearch/test/IndexSettingsModule.java index dfe190f03b8..ce83ffd3746 100644 --- a/core/src/test/java/org/elasticsearch/test/IndexNameAndSettingsModule.java +++ b/core/src/test/java/org/elasticsearch/test/IndexSettingsModule.java @@ -18,25 +18,39 @@ */ package org.elasticsearch.test; +import org.elasticsearch.Version; +import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexSettings; +import java.util.Collection; import java.util.Collections; +import java.util.function.Consumer; -public class IndexNameAndSettingsModule extends AbstractModule { +public class IndexSettingsModule extends AbstractModule { private final Index index; private final Settings settings; - public IndexNameAndSettingsModule(Index index, Settings settings) { + public IndexSettingsModule(Index index, Settings settings) { this.settings = settings; this.index = index; } @Override protected void configure() { - bind(IndexSettings.class).toInstance(new IndexSettings(index, settings, Collections.EMPTY_LIST)); + bind(IndexSettings.class).toInstance(newIndexSettings(index, settings, Collections.EMPTY_LIST)); + } + + public static IndexSettings newIndexSettings(Index index, Settings settings, Collection> updateListeners) { + Settings build = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1) + .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) + .put(settings) + .build(); + IndexMetaData metaData = IndexMetaData.builder(index.getName()).settings(build).build(); + return new IndexSettings(metaData, Settings.EMPTY, Collections.EMPTY_LIST); } } diff --git a/core/src/test/java/org/elasticsearch/test/store/MockFSDirectoryService.java b/core/src/test/java/org/elasticsearch/test/store/MockFSDirectoryService.java index c3ba399def7..dc20feed099 100644 --- a/core/src/test/java/org/elasticsearch/test/store/MockFSDirectoryService.java +++ b/core/src/test/java/org/elasticsearch/test/store/MockFSDirectoryService.java @@ -27,6 +27,7 @@ import org.apache.lucene.index.IndexWriter; import org.apache.lucene.store.*; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.TestRuleMarkFailure; +import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.logging.ESLogger; @@ -41,6 +42,7 @@ 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; @@ -172,10 +174,10 @@ public class MockFSDirectoryService extends FsDirectoryService { } private FsDirectoryService randomDirectorService(IndexStore indexStore, ShardPath path) { - Settings.Builder builder = Settings.settingsBuilder(); - builder.put(indexSettings); - builder.put(IndexStoreModule.STORE_TYPE, RandomPicks.randomFrom(random, IndexStoreModule.Type.values()).getSettingsKey()); - return new FsDirectoryService(new IndexSettings(shardId.index(), builder.build(), Collections.EMPTY_LIST), indexStore, 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 IndexSettings newIndexSettings = new IndexSettings(build, indexSettings.getNodeSettings(), Collections.EMPTY_LIST); + return new FsDirectoryService(newIndexSettings, indexStore, path); } public static final class ElasticsearchMockDirectoryWrapper extends MockDirectoryWrapper { diff --git a/plugins/analysis-icu/src/test/java/org/elasticsearch/index/analysis/AnalysisTestUtils.java b/plugins/analysis-icu/src/test/java/org/elasticsearch/index/analysis/AnalysisTestUtils.java index 61122b74329..a25a8bfd016 100644 --- a/plugins/analysis-icu/src/test/java/org/elasticsearch/index/analysis/AnalysisTestUtils.java +++ b/plugins/analysis-icu/src/test/java/org/elasticsearch/index/analysis/AnalysisTestUtils.java @@ -29,7 +29,7 @@ import org.elasticsearch.env.Environment; import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.index.Index; import org.elasticsearch.indices.analysis.IndicesAnalysisService; -import org.elasticsearch.test.IndexNameAndSettingsModule; +import org.elasticsearch.test.IndexSettingsModule; import static org.elasticsearch.common.settings.Settings.settingsBuilder; @@ -42,7 +42,7 @@ public class AnalysisTestUtils { .build(); Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings))).createInjector(); Injector injector = new ModulesBuilder().add( - new IndexNameAndSettingsModule(index, indexSettings), + new IndexSettingsModule(index, indexSettings), new AnalysisModule(settings, parentInjector.getInstance(IndicesAnalysisService.class)).addProcessor(new IcuAnalysisBinderProcessor())) .createChildInjector(parentInjector); diff --git a/plugins/analysis-kuromoji/src/test/java/org/elasticsearch/index/analysis/KuromojiAnalysisTests.java b/plugins/analysis-kuromoji/src/test/java/org/elasticsearch/index/analysis/KuromojiAnalysisTests.java index f910328012c..c43488b4213 100644 --- a/plugins/analysis-kuromoji/src/test/java/org/elasticsearch/index/analysis/KuromojiAnalysisTests.java +++ b/plugins/analysis-kuromoji/src/test/java/org/elasticsearch/index/analysis/KuromojiAnalysisTests.java @@ -36,7 +36,7 @@ import org.elasticsearch.index.Index; import org.elasticsearch.indices.analysis.IndicesAnalysisService; import org.elasticsearch.plugin.analysis.kuromoji.AnalysisKuromojiPlugin; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.test.IndexNameAndSettingsModule; +import org.elasticsearch.test.IndexSettingsModule; import java.io.IOException; import java.io.InputStream; @@ -212,7 +212,7 @@ public class KuromojiAnalysisTests extends ESTestCase { new AnalysisKuromojiPlugin().onModule(analysisModule); Injector injector = new ModulesBuilder().add( - new IndexNameAndSettingsModule(index, settings), + new IndexSettingsModule(index, settings), analysisModule) .createChildInjector(parentInjector); diff --git a/plugins/analysis-phonetic/src/test/java/org/elasticsearch/index/analysis/SimplePhoneticAnalysisTests.java b/plugins/analysis-phonetic/src/test/java/org/elasticsearch/index/analysis/SimplePhoneticAnalysisTests.java index ea4983caf34..a276e96362d 100644 --- a/plugins/analysis-phonetic/src/test/java/org/elasticsearch/index/analysis/SimplePhoneticAnalysisTests.java +++ b/plugins/analysis-phonetic/src/test/java/org/elasticsearch/index/analysis/SimplePhoneticAnalysisTests.java @@ -30,7 +30,7 @@ import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.index.Index; import org.elasticsearch.indices.analysis.IndicesAnalysisService; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.test.IndexNameAndSettingsModule; +import org.elasticsearch.test.IndexSettingsModule; import org.hamcrest.MatcherAssert; import static org.elasticsearch.common.settings.Settings.settingsBuilder; @@ -56,7 +56,7 @@ public class SimplePhoneticAnalysisTests extends ESTestCase { Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings))).createInjector(); Injector injector = new ModulesBuilder().add( - new IndexNameAndSettingsModule(index, settings), + new IndexSettingsModule(index, settings), new AnalysisModule(settings, parentInjector.getInstance(IndicesAnalysisService.class)) .addProcessor(new PhoneticAnalysisBinderProcessor())).createChildInjector(parentInjector); diff --git a/plugins/analysis-smartcn/src/test/java/org/elasticsearch/index/analysis/SimpleSmartChineseAnalysisTests.java b/plugins/analysis-smartcn/src/test/java/org/elasticsearch/index/analysis/SimpleSmartChineseAnalysisTests.java index afdce6b607f..4456eeaba9c 100644 --- a/plugins/analysis-smartcn/src/test/java/org/elasticsearch/index/analysis/SimpleSmartChineseAnalysisTests.java +++ b/plugins/analysis-smartcn/src/test/java/org/elasticsearch/index/analysis/SimpleSmartChineseAnalysisTests.java @@ -30,7 +30,7 @@ import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.index.Index; import org.elasticsearch.indices.analysis.IndicesAnalysisService; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.test.IndexNameAndSettingsModule; +import org.elasticsearch.test.IndexSettingsModule; import org.hamcrest.MatcherAssert; import static org.elasticsearch.common.settings.Settings.settingsBuilder; @@ -48,7 +48,7 @@ public class SimpleSmartChineseAnalysisTests extends ESTestCase { .build(); Injector parentInjector = new ModulesBuilder().add(new SettingsModule(EMPTY_SETTINGS), new EnvironmentModule(new Environment(settings))).createInjector(); Injector injector = new ModulesBuilder().add( - new IndexNameAndSettingsModule(index, settings), + new IndexSettingsModule(index, settings), new AnalysisModule(EMPTY_SETTINGS, parentInjector.getInstance(IndicesAnalysisService.class)).addProcessor(new SmartChineseAnalysisBinderProcessor())) .createChildInjector(parentInjector); diff --git a/plugins/analysis-stempel/src/test/java/org/elasticsearch/index/analysis/PolishAnalysisTests.java b/plugins/analysis-stempel/src/test/java/org/elasticsearch/index/analysis/PolishAnalysisTests.java index c959dce775b..1a0376b721c 100644 --- a/plugins/analysis-stempel/src/test/java/org/elasticsearch/index/analysis/PolishAnalysisTests.java +++ b/plugins/analysis-stempel/src/test/java/org/elasticsearch/index/analysis/PolishAnalysisTests.java @@ -34,7 +34,7 @@ import org.elasticsearch.index.analysis.pl.PolishAnalysisBinderProcessor; import org.elasticsearch.index.analysis.pl.PolishStemTokenFilterFactory; import org.elasticsearch.indices.analysis.IndicesAnalysisService; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.test.IndexNameAndSettingsModule; +import org.elasticsearch.test.IndexSettingsModule; import org.hamcrest.MatcherAssert; import static org.elasticsearch.common.settings.Settings.settingsBuilder; @@ -53,7 +53,7 @@ public class PolishAnalysisTests extends ESTestCase { Injector parentInjector = new ModulesBuilder().add(new SettingsModule(EMPTY_SETTINGS), new EnvironmentModule(new Environment(settings))).createInjector(); Injector injector = new ModulesBuilder().add( - new IndexNameAndSettingsModule(index, settings), + new IndexSettingsModule(index, settings), new AnalysisModule(EMPTY_SETTINGS, parentInjector.getInstance(IndicesAnalysisService.class)).addProcessor(new PolishAnalysisBinderProcessor())) .createChildInjector(parentInjector); diff --git a/plugins/analysis-stempel/src/test/java/org/elasticsearch/index/analysis/SimplePolishTokenFilterTests.java b/plugins/analysis-stempel/src/test/java/org/elasticsearch/index/analysis/SimplePolishTokenFilterTests.java index b9c2d33fd5c..06be6f67925 100644 --- a/plugins/analysis-stempel/src/test/java/org/elasticsearch/index/analysis/SimplePolishTokenFilterTests.java +++ b/plugins/analysis-stempel/src/test/java/org/elasticsearch/index/analysis/SimplePolishTokenFilterTests.java @@ -36,7 +36,7 @@ import org.elasticsearch.index.Index; import org.elasticsearch.index.analysis.pl.PolishAnalysisBinderProcessor; import org.elasticsearch.indices.analysis.IndicesAnalysisService; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.test.IndexNameAndSettingsModule; +import org.elasticsearch.test.IndexSettingsModule; import java.io.IOException; import java.io.StringReader; @@ -99,7 +99,7 @@ public class SimplePolishTokenFilterTests extends ESTestCase { private AnalysisService createAnalysisService(Index index, Settings settings) { Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings))).createInjector(); Injector injector = new ModulesBuilder().add( - new IndexNameAndSettingsModule(index, settings), + new IndexSettingsModule(index, settings), new AnalysisModule(settings, parentInjector.getInstance(IndicesAnalysisService.class)).addProcessor(new PolishAnalysisBinderProcessor())) .createChildInjector(parentInjector); From c1b1f395a7cc1ef85a761c21001a0ed30c4cad5f Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Fri, 23 Oct 2015 11:05:37 +0200 Subject: [PATCH 05/11] pass the right settings to the listener --- .../src/main/java/org/elasticsearch/indices/IndicesService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/indices/IndicesService.java b/core/src/main/java/org/elasticsearch/indices/IndicesService.java index 845950025b6..b5022401366 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndicesService.java +++ b/core/src/main/java/org/elasticsearch/indices/IndicesService.java @@ -319,7 +319,7 @@ public class IndicesService extends AbstractLifecycleComponent i modules.add(indexModule); pluginsService.processModules(modules); final IndexEventListener listener = indexModule.freeze(); - listener.beforeIndexCreated(index, settings); + listener.beforeIndexCreated(index, idxSettings.getSettings()); Injector indexInjector; try { From 82050e8d30ae695c46b7e63b67faac8a037e837b Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Fri, 23 Oct 2015 12:04:54 +0200 Subject: [PATCH 06/11] add integration test for adding and listening to a dynamic index setting --- .../elasticsearch/index/IndexSettings.java | 34 +++-- .../index/SettingsListenerIT.java | 134 ++++++++++++++++++ 2 files changed, 150 insertions(+), 18 deletions(-) create mode 100644 core/src/test/java/org/elasticsearch/index/SettingsListenerIT.java diff --git a/core/src/main/java/org/elasticsearch/index/IndexSettings.java b/core/src/main/java/org/elasticsearch/index/IndexSettings.java index dc00ad06798..93e27edfd81 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexSettings.java +++ b/core/src/main/java/org/elasticsearch/index/IndexSettings.java @@ -48,16 +48,17 @@ public final class IndexSettings { private final Settings nodeSettings; private final int numberOfShards; private final boolean isShadowReplicaIndex; - - // updated via #updateIndexMetaData(IndexMetaData) + // volatile fields are updated via #updateIndexMetaData(IndexMetaData) under lock private volatile Settings settings; private volatile IndexMetaData indexMetaData; /** - * Creates a new {@link IndexSettings} instance - * @param indexMetaData the index this settings object is associated with - * @param nodeSettings the actual settings including the node level settings + * Creates a new {@link IndexSettings} instance. The given node settings will be merged with the settings in the metadata + * while index level settings will overwrite node settings. + * + * @param indexMetaData the index metadata this settings object is associated with + * @param nodeSettings the nodes settings this index is allocated on. * @param updateListeners a collection of listeners / consumers that should be notified if one or more settings are updated */ public IndexSettings(final IndexMetaData indexMetaData, final Settings nodeSettings, final Collection> updateListeners) { @@ -116,13 +117,6 @@ public final class IndexSettings { return nodeName; } - /** - * Returns all settings update consumers - */ - List> getUpdateListeners() { // for testing - return updateListeners; - } - /** * Returns the current IndexMetaData for this index */ @@ -138,9 +132,7 @@ public final class IndexSettings { /** * Returns the number of replicas this index has. */ - public int getNumberOfReplicas() { - return settings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, null); - } + public int getNumberOfReplicas() { return settings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, null); } /** * Returns true iff this index uses shadow replicas. @@ -159,7 +151,7 @@ public final class IndexSettings { } /** - * Notifies all registered settings consumers with the new settings iff at least one setting has changed. + * Updates the settings and index metadata and notifies all registered settings consumers with the new settings iff at least one setting has changed. * * @return true iff any setting has been updated otherwise false. */ @@ -178,8 +170,7 @@ public final class IndexSettings { // nothing to update, same settings return false; } - this.settings = Settings.builder().put(nodeSettings).put(newSettings).build(); - final Settings mergedSettings = this.settings; + final Settings mergedSettings = this.settings = Settings.builder().put(nodeSettings).put(newSettings).build(); for (final Consumer consumer : updateListeners) { try { consumer.accept(mergedSettings); @@ -189,4 +180,11 @@ public final class IndexSettings { } return true; } + + /** + * Returns all settings update consumers + */ + List> getUpdateListeners() { // for testing + return updateListeners; + } } diff --git a/core/src/test/java/org/elasticsearch/index/SettingsListenerIT.java b/core/src/test/java/org/elasticsearch/index/SettingsListenerIT.java new file mode 100644 index 00000000000..d4fad2cf3ae --- /dev/null +++ b/core/src/test/java/org/elasticsearch/index/SettingsListenerIT.java @@ -0,0 +1,134 @@ +/* + * 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; + +import org.elasticsearch.cluster.ClusterModule; +import org.elasticsearch.cluster.settings.Validator; +import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.common.inject.Binder; +import org.elasticsearch.common.inject.Module; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.plugins.Plugin; +import org.elasticsearch.test.ESIntegTestCase; +import org.elasticsearch.test.ESIntegTestCase.ClusterScope; + +import java.util.Collection; +import java.util.Collections; +import java.util.function.Consumer; + +import static org.elasticsearch.test.ESIntegTestCase.Scope.SUITE; +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; +import static org.hamcrest.Matchers.nullValue; + +@ClusterScope(scope = SUITE, numDataNodes = 1, transportClientRatio = 0.0) +public class SettingsListenerIT extends ESIntegTestCase { + + @Override + protected Collection> nodePlugins() { + return pluginList(SettingsListenerPlugin.class); + } + + public static class SettingsListenerPlugin extends Plugin { + private final SettingsTestingService service = new SettingsTestingService(); + + /** + * The name of the plugin. + */ + @Override + public String name() { + return "settings-listener"; + } + + /** + * The description of the plugin. + */ + @Override + public String description() { + return "Settings Listenern Plugin"; + } + + public void onModule(ClusterModule clusterModule) { + clusterModule.registerIndexDynamicSetting("index.test.new.setting", Validator.INTEGER); + } + + public void onModule(IndexModule module) { + if (module.getIndex().getName().equals("test")) { // only for the test index + module.addIndexSettingsListener(service); + service.accept(module.getSettings()); + } + } + + @Override + public Collection nodeModules() { + return Collections.singletonList(new SettingsListenerModule(service)); + } + } + + public static class SettingsListenerModule extends AbstractModule { + private final SettingsTestingService service; + + public SettingsListenerModule(SettingsTestingService service) { + this.service = service; + } + + @Override + protected void configure() { + bind(SettingsTestingService.class).toInstance(service); + } + } + + public static class SettingsTestingService implements Consumer { + public volatile int value; + @Override + public void accept(Settings settings) { + value = settings.getAsInt("index.test.new.setting", -1); + } + } + + public void testListener() { + assertAcked(client().admin().indices().prepareCreate("test").setSettings(Settings.builder() + .put("index.test.new.setting", 21) + .build()).get()); + + for (SettingsTestingService instance : internalCluster().getInstances(SettingsTestingService.class)) { + assertEquals(21, instance.value); + } + + client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder() + .put("index.test.new.setting", 42)).get(); + for (SettingsTestingService instance : internalCluster().getInstances(SettingsTestingService.class)) { + assertEquals(42, instance.value); + } + + assertAcked(client().admin().indices().prepareCreate("other").setSettings(Settings.builder() + .put("index.test.new.setting", 21) + .build()).get()); + + for (SettingsTestingService instance : internalCluster().getInstances(SettingsTestingService.class)) { + assertEquals(42, instance.value); + } + + client().admin().indices().prepareUpdateSettings("other").setSettings(Settings.builder() + .put("index.test.new.setting", 84)).get(); + + for (SettingsTestingService instance : internalCluster().getInstances(SettingsTestingService.class)) { + assertEquals(42, instance.value); + } + } +} From 42af6c6db939453043185e3bb19d010641830c05 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Fri, 23 Oct 2015 12:21:56 +0200 Subject: [PATCH 07/11] fix test to not use client nodes --- .../java/org/elasticsearch/index/SettingsListenerIT.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/index/SettingsListenerIT.java b/core/src/test/java/org/elasticsearch/index/SettingsListenerIT.java index d4fad2cf3ae..628479722ec 100644 --- a/core/src/test/java/org/elasticsearch/index/SettingsListenerIT.java +++ b/core/src/test/java/org/elasticsearch/index/SettingsListenerIT.java @@ -21,7 +21,6 @@ package org.elasticsearch.index; import org.elasticsearch.cluster.ClusterModule; import org.elasticsearch.cluster.settings.Validator; import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.inject.Binder; import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.plugins.Plugin; @@ -34,9 +33,8 @@ import java.util.function.Consumer; import static org.elasticsearch.test.ESIntegTestCase.Scope.SUITE; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; -import static org.hamcrest.Matchers.nullValue; -@ClusterScope(scope = SUITE, numDataNodes = 1, transportClientRatio = 0.0) +@ClusterScope(scope = SUITE, numDataNodes = 1, numClientNodes = 0) public class SettingsListenerIT extends ESIntegTestCase { @Override @@ -94,7 +92,8 @@ public class SettingsListenerIT extends ESIntegTestCase { } public static class SettingsTestingService implements Consumer { - public volatile int value; + public volatile int value; + @Override public void accept(Settings settings) { value = settings.getAsInt("index.test.new.setting", -1); From df9432fcee16c40cc8317877635349a6d49d0df9 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Sat, 24 Oct 2015 15:24:52 +0200 Subject: [PATCH 08/11] apply review comments --- .../main/java/org/elasticsearch/common/settings/Settings.java | 1 - .../org/elasticsearch/index/analysis/AnalysisService.java | 4 ++-- .../elasticsearch/index/analysis/CustomAnalyzerProvider.java | 2 +- .../org/elasticsearch/index/mapper/DocumentMapperParser.java | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/common/settings/Settings.java b/core/src/main/java/org/elasticsearch/common/settings/Settings.java index 2a45b6ffc6d..663abd746f0 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/Settings.java +++ b/core/src/main/java/org/elasticsearch/common/settings/Settings.java @@ -36,7 +36,6 @@ import org.elasticsearch.common.unit.SizeValue; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.index.IndexSettings; import java.io.IOException; import java.io.InputStream; diff --git a/core/src/main/java/org/elasticsearch/index/analysis/AnalysisService.java b/core/src/main/java/org/elasticsearch/index/analysis/AnalysisService.java index 8c8565124b8..562d70512d3 100644 --- a/core/src/main/java/org/elasticsearch/index/analysis/AnalysisService.java +++ b/core/src/main/java/org/elasticsearch/index/analysis/AnalysisService.java @@ -188,7 +188,7 @@ public class AnalysisService extends AbstractIndexComponent implements Closeable if (indicesAnalysisService != null) { for (Map.Entry entry : indicesAnalysisService.analyzerProviderFactories().entrySet()) { String name = entry.getKey(); - Version indexVersion = Version.indexCreated(this.indexSettings.getSettings()); + Version indexVersion = indexSettings.getIndexVersionCreated(); if (!analyzerProviders.containsKey(name)) { analyzerProviders.put(name, entry.getValue().create(name, Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, indexVersion).build())); } @@ -220,7 +220,7 @@ public class AnalysisService extends AbstractIndexComponent implements Closeable * and 100 afterwards so we override the positionIncrementGap if it * doesn't match here. */ - int overridePositionIncrementGap = StringFieldMapper.Defaults.positionIncrementGap(Version.indexCreated(this.indexSettings.getSettings())); + int overridePositionIncrementGap = StringFieldMapper.Defaults.positionIncrementGap(indexSettings.getIndexVersionCreated()); if (analyzerFactory instanceof CustomAnalyzerProvider) { ((CustomAnalyzerProvider) analyzerFactory).build(this); /* diff --git a/core/src/main/java/org/elasticsearch/index/analysis/CustomAnalyzerProvider.java b/core/src/main/java/org/elasticsearch/index/analysis/CustomAnalyzerProvider.java index 6036eba4b36..0904354f603 100644 --- a/core/src/main/java/org/elasticsearch/index/analysis/CustomAnalyzerProvider.java +++ b/core/src/main/java/org/elasticsearch/index/analysis/CustomAnalyzerProvider.java @@ -77,7 +77,7 @@ public class CustomAnalyzerProvider extends AbstractIndexAnalyzerProvider Date: Sat, 24 Oct 2015 17:18:51 +0200 Subject: [PATCH 09/11] Test: MinimumMasterNodesIT.testCanNotPublishWithoutMinMastNodes should wait for state to be recovered The test spawns up 3 nodes, waits for a master to be elected and starts network disruptions. If those kick in too early we may have a cluster with a state not recovered block which causes failure during clean ups. http://build-us-00.elastic.co/job/es_core_master_oracle_6/3034/ --- .../cluster/MinimumMasterNodesIT.java | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesIT.java b/core/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesIT.java index 1ae83985a61..648356be173 100644 --- a/core/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesIT.java +++ b/core/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesIT.java @@ -39,11 +39,7 @@ import org.elasticsearch.test.disruption.NetworkDelaysPartition; import org.elasticsearch.test.junit.annotations.TestLogging; import org.elasticsearch.test.transport.MockTransportService; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; +import java.util.*; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @@ -51,15 +47,8 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.Predicate; import static org.elasticsearch.common.settings.Settings.settingsBuilder; -import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; -import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; -import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoTimeout; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.isOneOf; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.nullValue; +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*; +import static org.hamcrest.Matchers.*; @ClusterScope(scope = Scope.TEST, numDataNodes = 0) @ESIntegTestCase.SuppressLocalMode @@ -366,6 +355,7 @@ public class MinimumMasterNodesIT extends ESIntegTestCase { .put(DiscoverySettings.COMMIT_TIMEOUT, "100ms") // speed things up .build(); internalCluster().startNodesAsync(3, settings).get(); + ensureGreen(); // ensure cluster state is recovered before we disrupt things final String master = internalCluster().getMasterName(); Set otherNodes = new HashSet<>(Arrays.asList(internalCluster().getNodeNames())); From b1cfa7b1d22ae143cd492f80991422abb918b096 Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Thu, 22 Oct 2015 19:58:10 +0200 Subject: [PATCH 10/11] Check rebalancing constraints when shards are moved from a node they can no longer remain on Closes #14259 Closes #14057 --- .../allocator/BalancedShardsAllocator.java | 4 +- .../allocation/FilterRoutingTests.java | 67 +++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java index bfa6b7d6577..96f62b44229 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java @@ -511,7 +511,9 @@ public class BalancedShardsAllocator extends AbstractComponent implements Shards continue; } RoutingNode target = routingNodes.node(currentNode.getNodeId()); - Decision decision = allocation.deciders().canAllocate(shard, target, allocation); + Decision allocationDecision = allocation.deciders().canAllocate(shard, target, allocation); + Decision rebalanceDecision = allocation.deciders().canRebalance(shard, allocation); + Decision decision = new Decision.Multi().add(allocationDecision).add(rebalanceDecision); if (decision.type() == Type.YES) { // TODO maybe we can respect throttling here too? sourceNode.removeShard(shard); ShardRouting targetRelocatingShard = routingNodes.relocate(shard, target.nodeId(), allocation.clusterInfo().getShardSize(shard, ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE)); diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FilterRoutingTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FilterRoutingTests.java index f7f694d5a40..43aee722c59 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FilterRoutingTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FilterRoutingTests.java @@ -23,6 +23,7 @@ import org.elasticsearch.Version; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; +import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.cluster.routing.ShardRouting; @@ -36,6 +37,7 @@ import java.util.List; import static java.util.Collections.singletonMap; import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING; +import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED; import static org.elasticsearch.common.settings.Settings.settingsBuilder; import static org.hamcrest.Matchers.equalTo; @@ -162,4 +164,69 @@ public class FilterRoutingTests extends ESAllocationTestCase { assertThat(startedShard.currentNodeId(), Matchers.anyOf(equalTo("node1"), equalTo("node4"))); } } + + public void testRebalanceAfterShardsCannotRemainOnNode() { + AllocationService strategy = createAllocationService(settingsBuilder().build()); + + logger.info("Building initial routing table"); + MetaData metaData = MetaData.builder() + .put(IndexMetaData.builder("test1").settings(settings(Version.CURRENT)).numberOfShards(2).numberOfReplicas(0)) + .put(IndexMetaData.builder("test2").settings(settings(Version.CURRENT)).numberOfShards(2).numberOfReplicas(0)) + .build(); + + RoutingTable routingTable = RoutingTable.builder() + .addAsNew(metaData.index("test1")) + .addAsNew(metaData.index("test2")) + .build(); + + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + + logger.info("--> adding two nodes and performing rerouting"); + DiscoveryNode node1 = newNode("node1", singletonMap("tag1", "value1")); + DiscoveryNode node2 = newNode("node2", singletonMap("tag1", "value2")); + clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(node1).put(node2)).build(); + routingTable = strategy.reroute(clusterState).routingTable(); + clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build(); + assertThat(clusterState.getRoutingNodes().node(node1.getId()).numberOfShardsWithState(INITIALIZING), equalTo(2)); + assertThat(clusterState.getRoutingNodes().node(node2.getId()).numberOfShardsWithState(INITIALIZING), equalTo(2)); + + logger.info("--> start the shards (only primaries)"); + routingTable = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING)).routingTable(); + clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build(); + + logger.info("--> make sure all shards are started"); + assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(4)); + + logger.info("--> disable allocation for node1 and reroute"); + strategy = createAllocationService(settingsBuilder() + .put("cluster.routing.allocation.cluster_concurrent_rebalance", "1") + .put("cluster.routing.allocation.exclude.tag1", "value1") + .build()); + + logger.info("--> move shards from node1 to node2"); + routingTable = strategy.reroute(clusterState).routingTable(); + clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build(); + logger.info("--> check that concurrent rebalance only allows 1 shard to move"); + assertThat(clusterState.getRoutingNodes().node(node1.getId()).numberOfShardsWithState(STARTED), equalTo(1)); + assertThat(clusterState.getRoutingNodes().node(node2.getId()).numberOfShardsWithState(INITIALIZING), equalTo(1)); + assertThat(clusterState.getRoutingNodes().node(node2.getId()).numberOfShardsWithState(STARTED), equalTo(2)); + + logger.info("--> start the shards (only primaries)"); + routingTable = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING)).routingTable(); + clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build(); + + logger.info("--> move second shard from node1 to node2"); + routingTable = strategy.reroute(clusterState).routingTable(); + clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build(); + assertThat(clusterState.getRoutingNodes().node(node2.getId()).numberOfShardsWithState(INITIALIZING), equalTo(1)); + assertThat(clusterState.getRoutingNodes().node(node2.getId()).numberOfShardsWithState(STARTED), equalTo(3)); + + logger.info("--> start the shards (only primaries)"); + routingTable = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING)).routingTable(); + clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build(); + + routingTable = strategy.reroute(clusterState).routingTable(); + clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build(); + assertThat(clusterState.getRoutingNodes().node(node2.getId()).numberOfShardsWithState(STARTED), equalTo(4)); + } } From c335b3a1762080f8cb5b2694985d93f17978474e Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Mon, 26 Oct 2015 10:46:20 +0100 Subject: [PATCH 11/11] Fix AckClusterUpdateSettingsIT.testClusterUpdateSettingsAcknowledgement() after changes in #14259 Closes #14278 --- .../elasticsearch/cluster/ack/AckClusterUpdateSettingsIT.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/src/test/java/org/elasticsearch/cluster/ack/AckClusterUpdateSettingsIT.java b/core/src/test/java/org/elasticsearch/cluster/ack/AckClusterUpdateSettingsIT.java index 12147ffb783..81de8b1a43c 100644 --- a/core/src/test/java/org/elasticsearch/cluster/ack/AckClusterUpdateSettingsIT.java +++ b/core/src/test/java/org/elasticsearch/cluster/ack/AckClusterUpdateSettingsIT.java @@ -29,6 +29,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.routing.IndexShardRoutingTable; import org.elasticsearch.cluster.routing.ShardRouting; +import org.elasticsearch.cluster.routing.allocation.decider.ConcurrentRebalanceAllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.discovery.DiscoverySettings; @@ -50,6 +51,7 @@ public class AckClusterUpdateSettingsIT extends ESIntegTestCase { //make sure that enough concurrent reroutes can happen at the same time //we have a minimum of 2 nodes, and a maximum of 10 shards, thus 5 should be enough .put(ThrottlingAllocationDecider.CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_RECOVERIES, 5) + .put(ConcurrentRebalanceAllocationDecider.CLUSTER_ROUTING_ALLOCATION_CLUSTER_CONCURRENT_REBALANCE, 10) .build(); }