Skip to content

Commit

Permalink
Add capability to restrict async durability mode for remote indexes
Browse files Browse the repository at this point in the history
Signed-off-by: Ashish Singh <ssashish@amazon.com>
  • Loading branch information
ashking94 committed Sep 22, 2023
1 parent 994e115 commit 9866498
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
import org.opensearch.index.mapper.MapperService.MergeReason;
import org.opensearch.index.query.QueryShardContext;
import org.opensearch.index.shard.IndexSettingProvider;
import org.opensearch.index.translog.Translog;
import org.opensearch.indices.IndexCreationException;
import org.opensearch.indices.IndicesService;
import org.opensearch.indices.InvalidIndexNameException;
Expand Down Expand Up @@ -922,6 +923,7 @@ static Settings aggregateIndexSettings(
validateTranslogRetentionSettings(indexSettings);
validateStoreTypeSettings(indexSettings);
validateRefreshIntervalSettings(request.settings(), clusterSettings);
validateTranslogDurabilitySettings(request.settings(), clusterSettings);

return indexSettings;
}
Expand Down Expand Up @@ -1491,7 +1493,7 @@ public static void validateTranslogRetentionSettings(Settings indexSettings) {
/**
* Validates {@code index.refresh_interval} is equal or below the {@code cluster.minimum.index.refresh_interval}.
*
* @param requestSettings settings passed in during index create request
* @param requestSettings settings passed in during index create/update request
* @param clusterSettings cluster setting
*/
static void validateRefreshIntervalSettings(Settings requestSettings, ClusterSettings clusterSettings) {
Expand All @@ -1510,4 +1512,26 @@ static void validateRefreshIntervalSettings(Settings requestSettings, ClusterSet
);
}
}

/**
* Validates {@code index.translog.durability} is not async if the {@code cluster.remote_store.index.restrict.async-durability} is set to true.
*
* @param requestSettings settings passed in during index create/update request
* @param clusterSettings cluster setting
*/
static void validateTranslogDurabilitySettings(Settings requestSettings, ClusterSettings clusterSettings) {
if (IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.exists(requestSettings) == false
|| clusterSettings.get(IndicesService.CLUSTER_REMOTE_INDEX_RESTRICT_ASYNC_DURABILITY_SETTING) == false) {
return;
}
Translog.Durability durability = IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.get(requestSettings);
if (durability.equals(Translog.Durability.ASYNC)) {
throw new IllegalArgumentException(
"Translog.Durability.ASYNC is not allowed as cluster setting ["
+ IndicesService.CLUSTER_REMOTE_INDEX_RESTRICT_ASYNC_DURABILITY_SETTING.getKey()
+ "] is true"
);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public void updateSettings(
.build();

MetadataCreateIndexService.validateRefreshIntervalSettings(normalizedSettings, clusterService.getClusterSettings());
MetadataCreateIndexService.validateTranslogDurabilitySettings(normalizedSettings, clusterService.getClusterSettings());

Settings.Builder settingsForClosedIndices = Settings.builder();
Settings.Builder settingsForOpenIndices = Settings.builder();
Expand Down
12 changes: 12 additions & 0 deletions server/src/main/java/org/opensearch/indices/IndicesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,18 @@ public class IndicesService extends AbstractLifecycleComponent
Property.Dynamic
);

/**
* This setting is used to restrict creation or updation of index where the `index.translog.durability` index setting
* is set as ASYNC if enabled. If disabled, any of the durability mode can be used and switched at any later time from
* one to another.
*/
public static final Setting<Boolean> CLUSTER_REMOTE_INDEX_RESTRICT_ASYNC_DURABILITY_SETTING = Setting.boolSetting(
"cluster.remote_store.index.restrict.async-durability",
false,
Property.NodeScope,
Property.Final
);

/**
* The node's settings.
*/
Expand Down

0 comments on commit 9866498

Please sign in to comment.