Skip to content

Commit

Permalink
Change replication index setting from boolean to Enum
Browse files Browse the repository at this point in the history
Also incorporates PR feedback about the feature flag scope and naming

Signed-off-by: Kartik Ganesh <[email protected]>
  • Loading branch information
kartg committed Apr 22, 2022
1 parent f9153c4 commit 8bda19d
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import org.opensearch.index.mapper.MapperService;
import org.opensearch.index.seqno.SequenceNumbers;
import org.opensearch.index.shard.ShardId;
import org.opensearch.indices.replication.common.ReplicationType;
import org.opensearch.rest.RestStatus;

import java.io.IOException;
Expand Down Expand Up @@ -260,13 +261,14 @@ public Iterator<Setting<?>> settings() {
Property.IndexScope
);

public static final String SETTING_SEGMENT_REPLICATION = "index.replication.segment_replication";
/**
* Used to specify if the index should use segment replication. If false, document replication is used.
* Used to specify the replication type for the index. By default, document replication is used.
*/
public static final Setting<Boolean> INDEX_SEGMENT_REPLICATION_SETTING = Setting.boolSetting(
SETTING_SEGMENT_REPLICATION,
false,
public static final String SETTING_REPLICATION_TYPE = "index.replication.type";
public static final Setting<ReplicationType> INDEX_REPLICATION_TYPE_SETTING = new Setting<>(
SETTING_REPLICATION_TYPE,
ReplicationType.DOCUMENT.toString(),
ReplicationType::parseString,
Property.IndexScope,
Property.Final
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ public final class IndexScopedSettings extends AbstractScopedSettings {
* setting should be moved to {@link #BUILT_IN_INDEX_SETTINGS}.
*/
public static final Map<String, Setting> FEATURE_FLAGGED_INDEX_SETTINGS = Map.of(
FeatureFlags.SEGREP_FEATURE_FLAG,
IndexMetadata.INDEX_SEGMENT_REPLICATION_SETTING
FeatureFlags.REPLICATION_TYPE,
IndexMetadata.INDEX_REPLICATION_TYPE_SETTING
);

public static final IndexScopedSettings DEFAULT_SCOPED_SETTINGS = new IndexScopedSettings(Settings.EMPTY, BUILT_IN_INDEX_SETTINGS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
public class FeatureFlags {

/**
* Gates the visibility of the index setting that enables segment replication.
* Gates the visibility of the index setting that allows changing of replication type.
* Once the feature is ready for production release, this feature flag can be removed.
*/
public static final String SEGREP_FEATURE_FLAG = "opensearch.segment_replication_feature_flag_enabled";
public static final String REPLICATION_TYPE = "opensearch.experimental.feature.replication_type.enabled";

/**
* Used to test feature flags whose values are expected to be booleans.
Expand Down
5 changes: 4 additions & 1 deletion server/src/main/java/org/opensearch/index/IndexSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.opensearch.common.unit.ByteSizeValue;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.index.translog.Translog;
import org.opensearch.indices.replication.common.ReplicationType;
import org.opensearch.ingest.IngestService;
import org.opensearch.node.Node;

Expand Down Expand Up @@ -682,7 +683,9 @@ public IndexSettings(final IndexMetadata indexMetadata, final Settings nodeSetti
nodeName = Node.NODE_NAME_SETTING.get(settings);
this.indexMetadata = indexMetadata;
numberOfShards = settings.getAsInt(IndexMetadata.SETTING_NUMBER_OF_SHARDS, null);
isSegRepEnabled = settings.getAsBoolean(IndexMetadata.SETTING_SEGMENT_REPLICATION, false);

ReplicationType replicationType = ReplicationType.parseString(settings.get(IndexMetadata.SETTING_REPLICATION_TYPE));
isSegRepEnabled = ReplicationType.SEGMENT.equals(replicationType);

this.searchThrottled = INDEX_SEARCH_THROTTLED.get(settings);
this.queryStringLenient = QUERY_STRING_LENIENT_SETTING.get(settings);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.indices.replication.common;

public enum ReplicationType {

DOCUMENT("document"),

SEGMENT("segment");

private final String value;

ReplicationType(String replicationType) {
this.value = replicationType;
}

public static ReplicationType parseString(String replicationType) {
try {
return ReplicationType.valueOf(replicationType);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Could not parse ReplicationStrategy for [" + replicationType + "]");
} catch (NullPointerException npe) {
// return a default value for null input
return DOCUMENT;
}
}

@Override
public String toString() {
return value;
}
}

0 comments on commit 8bda19d

Please sign in to comment.