From 589332c819648702632f1b993494e0b1ea92ded5 Mon Sep 17 00:00:00 2001 From: Rishabh Maurya Date: Thu, 28 Sep 2023 11:01:21 -0700 Subject: [PATCH] rename time_index to time_series_index Signed-off-by: Rishabh Maurya --- .../common/settings/ClusterSettings.java | 2 +- .../org/opensearch/index/IndexSettings.java | 19 ++++++----- .../opensearch/index/MergePolicyProvider.java | 5 +++ .../index/MergePolicySettingsTests.java | 32 +++++++++---------- 4 files changed, 31 insertions(+), 27 deletions(-) diff --git a/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java b/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java index 0861657005acc..5261d40387dc6 100644 --- a/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java +++ b/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java @@ -457,7 +457,7 @@ public void apply(Settings value, Settings current, Settings previous) { NetworkService.TCP_CONNECT_TIMEOUT, IndexSettings.QUERY_STRING_ANALYZE_WILDCARD, IndexSettings.QUERY_STRING_ALLOW_LEADING_WILDCARD, - IndexSettings.TIME_INDEX_MERGE_POLICY, + IndexSettings.TIME_SERIES_INDEX_MERGE_POLICY, ScriptService.SCRIPT_GENERAL_CACHE_SIZE_SETTING, ScriptService.SCRIPT_GENERAL_CACHE_EXPIRE_SETTING, ScriptService.SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING, diff --git a/server/src/main/java/org/opensearch/index/IndexSettings.java b/server/src/main/java/org/opensearch/index/IndexSettings.java index ac6ba8d688c45..ce6c1a5ad6284 100644 --- a/server/src/main/java/org/opensearch/index/IndexSettings.java +++ b/server/src/main/java/org/opensearch/index/IndexSettings.java @@ -58,7 +58,6 @@ import java.util.Collections; import java.util.List; import java.util.Locale; -import java.util.Objects; import java.util.Optional; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; @@ -613,8 +612,8 @@ public static IndexMergePolicy fromString(String text) { Property.IndexScope ); - public static final Setting TIME_INDEX_MERGE_POLICY = Setting.simpleString( - "indices.time_index.default_index_merge_policy", + public static final Setting TIME_SERIES_INDEX_MERGE_POLICY = Setting.simpleString( + "indices.time_series_index.default_index_merge_policy", DEFAULT_POLICY, IndexMergePolicy::fromString, Property.NodeScope @@ -1516,13 +1515,13 @@ public long getGcDeletesInMillis() { /** * Returns the merge policy that should be used for this index. - * @param isTimeIndex true if index contains @timestamp field + * @param isTimeSeriesIndex true if index contains @timestamp field */ - public MergePolicy getMergePolicy(boolean isTimeIndex) { + public MergePolicy getMergePolicy(boolean isTimeSeriesIndex) { String indexScopedPolicy = scopedSettings.get(INDEX_MERGE_POLICY); MergePolicyProvider mergePolicyProvider = null; IndexMergePolicy indexMergePolicy = IndexMergePolicy.fromString(indexScopedPolicy); - switch (Objects.requireNonNull(indexMergePolicy)) { + switch (indexMergePolicy) { case TIERED: mergePolicyProvider = tieredMergePolicyProvider; break; @@ -1530,10 +1529,10 @@ public MergePolicy getMergePolicy(boolean isTimeIndex) { mergePolicyProvider = logByteSizeMergePolicyProvider; break; case DEFAULT_POLICY: - if (isTimeIndex) { - String nodeScopedTimeIndexPolicy = TIME_INDEX_MERGE_POLICY.get(nodeSettings); - IndexMergePolicy nodeMergePolicy = IndexMergePolicy.fromString(nodeScopedTimeIndexPolicy); - switch (Objects.requireNonNull(nodeMergePolicy)) { + if (isTimeSeriesIndex) { + String nodeScopedTimeSeriesIndexPolicy = TIME_SERIES_INDEX_MERGE_POLICY.get(nodeSettings); + IndexMergePolicy nodeMergePolicy = IndexMergePolicy.fromString(nodeScopedTimeSeriesIndexPolicy); + switch (nodeMergePolicy) { case TIERED: case DEFAULT_POLICY: mergePolicyProvider = tieredMergePolicyProvider; diff --git a/server/src/main/java/org/opensearch/index/MergePolicyProvider.java b/server/src/main/java/org/opensearch/index/MergePolicyProvider.java index 1c2388fedd633..6f734314f758f 100644 --- a/server/src/main/java/org/opensearch/index/MergePolicyProvider.java +++ b/server/src/main/java/org/opensearch/index/MergePolicyProvider.java @@ -9,10 +9,15 @@ package org.opensearch.index; import org.apache.lucene.index.MergePolicy; +import org.opensearch.common.annotation.InternalApi; /** * A provider for obtaining merge policies used by OpenSearch indexes. + * + * @opensearch.internal */ + +@InternalApi public interface MergePolicyProvider { // don't convert to Setting<> and register... we only set this in tests and register via a plugin String INDEX_MERGE_ENABLED = "index.merge.enabled"; diff --git a/server/src/test/java/org/opensearch/index/MergePolicySettingsTests.java b/server/src/test/java/org/opensearch/index/MergePolicySettingsTests.java index a98c00879fbc1..32c4c048d77ba 100644 --- a/server/src/test/java/org/opensearch/index/MergePolicySettingsTests.java +++ b/server/src/test/java/org/opensearch/index/MergePolicySettingsTests.java @@ -111,36 +111,36 @@ public void testMergePolicyPrecedence() throws IOException { assertTrue(indexSettings.getMergePolicy(false) instanceof OpenSearchTieredMergePolicy); assertTrue(indexSettings.getMergePolicy(true) instanceof OpenSearchTieredMergePolicy); - // 1.1 node setting TIME_INDEX_MERGE_POLICY is set as log_byte_size - // assert index policy is tiered whereas time index policy is log_byte_size + // 1.1 node setting TIME_SERIES_INDEX_MERGE_POLICY is set as log_byte_size + // assert index policy is tiered whereas time series index policy is log_byte_size Settings nodeSettings = Settings.builder() - .put(IndexSettings.TIME_INDEX_MERGE_POLICY.getKey(), IndexSettings.IndexMergePolicy.LOG_BYTE_SIZE.getValue()) + .put(IndexSettings.TIME_SERIES_INDEX_MERGE_POLICY.getKey(), IndexSettings.IndexMergePolicy.LOG_BYTE_SIZE.getValue()) .build(); indexSettings = new IndexSettings(newIndexMeta("test", Settings.EMPTY), nodeSettings); assertTrue(indexSettings.getMergePolicy(false) instanceof OpenSearchTieredMergePolicy); assertTrue(indexSettings.getMergePolicy(true) instanceof LogByteSizeMergePolicy); - // 1.2 node setting TIME_INDEX_MERGE_POLICY is set as tiered - // assert both index and time index policy is tiered + // 1.2 node setting TIME_SERIES_INDEX_MERGE_POLICY is set as tiered + // assert both index and time series index policy is tiered nodeSettings = Settings.builder() - .put(IndexSettings.TIME_INDEX_MERGE_POLICY.getKey(), IndexSettings.IndexMergePolicy.TIERED.getValue()) + .put(IndexSettings.TIME_SERIES_INDEX_MERGE_POLICY.getKey(), IndexSettings.IndexMergePolicy.TIERED.getValue()) .build(); indexSettings = new IndexSettings(newIndexMeta("test", Settings.EMPTY), nodeSettings); assertTrue(indexSettings.getMergePolicy(false) instanceof OpenSearchTieredMergePolicy); assertTrue(indexSettings.getMergePolicy(true) instanceof OpenSearchTieredMergePolicy); // 2. INDEX_MERGE_POLICY set as tiered - // assert both index and time-index merge policy is set as tiered + // assert both index and time-series-index merge policy is set as tiered indexSettings = indexSettings( Settings.builder().put(IndexSettings.INDEX_MERGE_POLICY.getKey(), IndexSettings.IndexMergePolicy.TIERED.getValue()).build() ); assertTrue(indexSettings.getMergePolicy(false) instanceof OpenSearchTieredMergePolicy); assertTrue(indexSettings.getMergePolicy(true) instanceof OpenSearchTieredMergePolicy); - // 2.1 node setting TIME_INDEX_MERGE_POLICY is set as log_byte_size - // assert both index and time-index merge policy is set as tiered + // 2.1 node setting TIME_SERIES_INDEX_MERGE_POLICY is set as log_byte_size + // assert both index and time-series-index merge policy is set as tiered nodeSettings = Settings.builder() - .put(IndexSettings.TIME_INDEX_MERGE_POLICY.getKey(), IndexSettings.IndexMergePolicy.LOG_BYTE_SIZE.getValue()) + .put(IndexSettings.TIME_SERIES_INDEX_MERGE_POLICY.getKey(), IndexSettings.IndexMergePolicy.LOG_BYTE_SIZE.getValue()) .build(); indexSettings = new IndexSettings( newIndexMeta( @@ -153,7 +153,7 @@ public void testMergePolicyPrecedence() throws IOException { assertTrue(indexSettings.getMergePolicy(true) instanceof OpenSearchTieredMergePolicy); // 3. INDEX_MERGE_POLICY set as log_byte_size - // assert both index and time-index merge policy is set as log_byte_size + // assert both index and time-series-index merge policy is set as log_byte_size indexSettings = indexSettings( Settings.builder() .put(IndexSettings.INDEX_MERGE_POLICY.getKey(), IndexSettings.IndexMergePolicy.LOG_BYTE_SIZE.getValue()) @@ -162,10 +162,10 @@ public void testMergePolicyPrecedence() throws IOException { assertTrue(indexSettings.getMergePolicy(false) instanceof LogByteSizeMergePolicy); assertTrue(indexSettings.getMergePolicy(true) instanceof LogByteSizeMergePolicy); - // 3.1 node setting TIME_INDEX_MERGE_POLICY is set as tiered - // assert both index and time-index merge policy is set as log_byte_size + // 3.1 node setting TIME_SERIES_INDEX_MERGE_POLICY is set as tiered + // assert both index and time-series-index merge policy is set as log_byte_size nodeSettings = Settings.builder() - .put(IndexSettings.TIME_INDEX_MERGE_POLICY.getKey(), IndexSettings.IndexMergePolicy.TIERED.getValue()) + .put(IndexSettings.TIME_SERIES_INDEX_MERGE_POLICY.getKey(), IndexSettings.IndexMergePolicy.TIERED.getValue()) .build(); indexSettings = new IndexSettings( newIndexMeta( @@ -195,10 +195,10 @@ public void testInvalidMergePolicy() throws IOException { ); assertThat(exc2.getMessage(), containsString(" has unsupported policy specified: ")); - final Settings invalidSettings2 = Settings.builder().put(IndexSettings.TIME_INDEX_MERGE_POLICY.getKey(), "invalid").build(); + final Settings invalidSettings2 = Settings.builder().put(IndexSettings.TIME_SERIES_INDEX_MERGE_POLICY.getKey(), "invalid").build(); IllegalArgumentException exc3 = expectThrows( IllegalArgumentException.class, - () -> IndexSettings.TIME_INDEX_MERGE_POLICY.get(invalidSettings2) + () -> IndexSettings.TIME_SERIES_INDEX_MERGE_POLICY.get(invalidSettings2) ); assertThat(exc3.getMessage(), containsString(" has unsupported policy specified: "));