Skip to content

Commit

Permalink
Add segment replication index setting, gated by feature flag
Browse files Browse the repository at this point in the history
Signed-off-by: Kartik Ganesh <[email protected]>
  • Loading branch information
kartg authored and nknize committed Apr 22, 2022
1 parent f006afa commit ae9fcfd
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,17 @@ 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.
*/
public static final Setting<Boolean> INDEX_SEGMENT_REPLICATION_SETTING = Setting.boolSetting(
SETTING_SEGMENT_REPLICATION,
false,
Property.IndexScope,
Property.Final
);

public static final String SETTING_AUTO_EXPAND_REPLICAS = "index.auto_expand_replicas";
public static final Setting<AutoExpandReplicas> INDEX_AUTO_EXPAND_REPLICAS_SETTING = AutoExpandReplicas.SETTING;

Expand Down
9 changes: 9 additions & 0 deletions server/src/main/java/org/opensearch/index/IndexSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ public final class IndexSettings {
private final String nodeName;
private final Settings nodeSettings;
private final int numberOfShards;
private final Boolean isSegRepEnabled;
// volatile fields are updated via #updateIndexMetadata(IndexMetadata) under lock
private volatile Settings settings;
private volatile IndexMetadata indexMetadata;
Expand Down Expand Up @@ -681,6 +682,7 @@ 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);

this.searchThrottled = INDEX_SEARCH_THROTTLED.get(settings);
this.queryStringLenient = QUERY_STRING_LENIENT_SETTING.get(settings);
Expand Down Expand Up @@ -915,6 +917,13 @@ public int getNumberOfReplicas() {
return settings.getAsInt(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, null);
}

/**
* Returns true if segment replication is enabled on the index.
*/
public boolean isSegrepEnabled() {
return Boolean.TRUE.equals(isSegRepEnabled);
}

/**
* Returns the node settings. The settings returned from {@link #getSettings()} are a merged version of the
* index settings and the node settings where node settings are overwritten by index settings.
Expand Down
25 changes: 25 additions & 0 deletions server/src/main/java/org/opensearch/node/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,27 @@ public class Node implements Closeable {
Property.NodeScope
);

/**
* Feature flag to gate the visibility of the index setting that enables segment replication.
* Once the feature is ready for production release, this feature flag can be removed.
*/
public static final boolean SEGREP_FEATURE_FLAG_ENABLED = "true".equals(
System.getProperty("opensearch.segment_replication_feature_flag_enabled")
);

/**
* Used to specify if the index should use segment replication. If false, document replication is used.
* Currently located here so that it can gated by the {@link #SEGREP_FEATURE_FLAG_ENABLED} feature flag.
* Once the feature is ready for production release, the setting can be moved to
* {@link org.opensearch.common.settings.IndexScopedSettings#BUILT_IN_INDEX_SETTINGS}.
*/
private static final Setting<Boolean> INDEX_SEGMENT_REPLICATION_SETTING = Setting.boolSetting(
"index.replication.segment_replication",
false,
Property.IndexScope,
Property.Final
);

/**
* controls whether the node is allowed to persist things like metadata to disk
* Note that this does not control whether the node stores actual indices (see
Expand Down Expand Up @@ -457,6 +478,10 @@ protected Node(
for (final ExecutorBuilder<?> builder : threadPool.builders()) {
additionalSettings.addAll(builder.getRegisteredSettings());
}
// Add segment replication setting gated by feature flag
if (SEGREP_FEATURE_FLAG_ENABLED) {
additionalSettings.add(INDEX_SEGMENT_REPLICATION_SETTING);
}
client = new NodeClient(settings, threadPool);

final ScriptModule scriptModule = new ScriptModule(settings, pluginsService.filterPlugins(ScriptPlugin.class));
Expand Down

0 comments on commit ae9fcfd

Please sign in to comment.