Skip to content

Commit

Permalink
rename time_index to time_series_index
Browse files Browse the repository at this point in the history
Signed-off-by: Rishabh Maurya <[email protected]>
  • Loading branch information
rishabhmaurya committed Sep 28, 2023
1 parent 8686dbe commit 589332c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 9 additions & 10 deletions server/src/main/java/org/opensearch/index/IndexSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -613,8 +612,8 @@ public static IndexMergePolicy fromString(String text) {
Property.IndexScope
);

public static final Setting<String> TIME_INDEX_MERGE_POLICY = Setting.simpleString(
"indices.time_index.default_index_merge_policy",
public static final Setting<String> TIME_SERIES_INDEX_MERGE_POLICY = Setting.simpleString(
"indices.time_series_index.default_index_merge_policy",
DEFAULT_POLICY,
IndexMergePolicy::fromString,
Property.NodeScope
Expand Down Expand Up @@ -1516,24 +1515,24 @@ 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;
case LOG_BYTE_SIZE:
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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())
Expand All @@ -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(
Expand Down Expand Up @@ -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: "));

Expand Down

0 comments on commit 589332c

Please sign in to comment.