From ae9fcfdc7738cf07fe374776b48f9d2456329638 Mon Sep 17 00:00:00 2001 From: Kartik Ganesh Date: Thu, 21 Apr 2022 16:51:18 -0700 Subject: [PATCH] Add segment replication index setting, gated by feature flag Signed-off-by: Kartik Ganesh --- .../cluster/metadata/IndexMetadata.java | 11 ++++++++ .../org/opensearch/index/IndexSettings.java | 9 +++++++ .../main/java/org/opensearch/node/Node.java | 25 +++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java b/server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java index 6510c57060fe0..52ba67bcde583 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java @@ -260,6 +260,17 @@ public Iterator> 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 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 INDEX_AUTO_EXPAND_REPLICAS_SETTING = AutoExpandReplicas.SETTING; diff --git a/server/src/main/java/org/opensearch/index/IndexSettings.java b/server/src/main/java/org/opensearch/index/IndexSettings.java index aa69417af1897..2834620ab85ff 100644 --- a/server/src/main/java/org/opensearch/index/IndexSettings.java +++ b/server/src/main/java/org/opensearch/index/IndexSettings.java @@ -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; @@ -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); @@ -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. diff --git a/server/src/main/java/org/opensearch/node/Node.java b/server/src/main/java/org/opensearch/node/Node.java index c929c7c013b13..02649e1bd6673 100644 --- a/server/src/main/java/org/opensearch/node/Node.java +++ b/server/src/main/java/org/opensearch/node/Node.java @@ -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 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 @@ -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));