Skip to content

Commit

Permalink
Add validation to index.search.idle.after when segment replication is…
Browse files Browse the repository at this point in the history
… enabled.

This change updates search idle setting to not be configurable on segrep indices with replicas.

Signed-off-by: Marc Handalian <[email protected]>
  • Loading branch information
mch2 committed Jun 19, 2023
1 parent 6ac635e commit 50b03b3
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.opensearch.index.query.RangeQueryBuilder;
import org.opensearch.index.shard.IndexShard;
import org.opensearch.indices.IndicesService;
import org.opensearch.indices.replication.common.ReplicationType;
import org.opensearch.plugins.Plugin;
import org.opensearch.plugins.SearchPlugin;
import org.opensearch.rest.RestStatus;
Expand Down Expand Up @@ -370,6 +371,34 @@ public void testSearchIdle() throws Exception {
});
}

public void testSearchIdle_SegmentReplication() {
// fail with replica count > 0
int numOfReplicas = 1;
internalCluster().ensureAtLeastNumDataNodes(numOfReplicas + 1);
final Settings.Builder settings = Settings.builder()
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, randomIntBetween(1, 5))
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, numOfReplicas)
.put(IndexMetadata.SETTING_REPLICATION_TYPE, ReplicationType.SEGMENT)
.put(IndexSettings.INDEX_SEARCH_IDLE_AFTER.getKey(), TimeValue.timeValueMillis(randomIntBetween(50, 500)));

expectThrows(IllegalArgumentException.class, () -> {
assertAcked(prepareCreate("test").setSettings(settings).setMapping("created_date", "type=date,format=yyyy-MM-dd"));
});

// setting allowed with 0 replicas.
settings.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0);
assertAcked(prepareCreate("test").setSettings(settings).setMapping("created_date", "type=date,format=yyyy-MM-dd"));

// add a replica
assertAcked(
client().admin()
.indices()
.prepareUpdateSettings("test")
.setSettings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1))
);

}

public void testCircuitBreakerReduceFail() throws Exception {
int numShards = randomIntBetween(1, 10);
indexSomeDocs("test", numShards, numShards * 3);
Expand Down
33 changes: 33 additions & 0 deletions server/src/main/java/org/opensearch/index/IndexSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@
import org.opensearch.search.pipeline.SearchPipelineService;

import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
Expand All @@ -70,6 +72,7 @@
import static org.opensearch.index.mapper.MapperService.INDEX_MAPPING_NESTED_FIELDS_LIMIT_SETTING;
import static org.opensearch.index.mapper.MapperService.INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING;
import static org.opensearch.index.store.remote.directory.RemoteSnapshotDirectory.SEARCHABLE_SNAPSHOT_EXTENDED_COMPATIBILITY_MINIMUM_VERSION;
import static org.opensearch.indices.IndicesService.CLUSTER_REPLICATION_TYPE_SETTING;

/**
* This class encapsulates all index level settings and handles settings updates.
Expand Down Expand Up @@ -122,6 +125,36 @@ public final class IndexSettings {
"index.search.idle.after",
TimeValue.timeValueSeconds(30),
TimeValue.timeValueMinutes(0),
new Setting.Validator<>() {

@Override
public void validate(TimeValue value) {

}

@Override
public void validate(TimeValue value, Map<Setting<?>, Object> settings, boolean isPresent) {
if (isPresent) {
final Object clusterSettingReplicationType = settings.get(CLUSTER_REPLICATION_TYPE_SETTING);
final Object replicationType = settings.get(IndexMetadata.INDEX_REPLICATION_TYPE_SETTING);
int numReplicas = (int) settings.get(IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING);
if ((ReplicationType.SEGMENT.equals(clusterSettingReplicationType) || ReplicationType.SEGMENT.equals(replicationType))
&& numReplicas > 0) {
throw new IllegalArgumentException("Shard idle is disabled for indices with replicas using Segment Replication");
}
}
}

@Override
public Iterator<Setting<?>> settings() {
final List<Setting<?>> settings = List.of(
CLUSTER_REPLICATION_TYPE_SETTING,
IndexMetadata.INDEX_REPLICATION_TYPE_SETTING,
IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING
);
return settings.iterator();
}
},
Property.IndexScope,
Property.Dynamic
);
Expand Down

0 comments on commit 50b03b3

Please sign in to comment.