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 extends EngineFactory> engineFactoryImpl = InternalEngineFactory.class;
Class extends IndexSearcherWrapper> 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.
*/
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 extends EngineFactory> 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();
}