Skip to content

Commit

Permalink
Add validation during cluster state restore, consider peristent setti…
Browse files Browse the repository at this point in the history
…ngs being restored for checking cluster minimum refresh interval

Signed-off-by: bansvaru <[email protected]>
  • Loading branch information
linuxpi committed Nov 28, 2023
1 parent 33fe975 commit 05045a2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1497,11 +1497,25 @@ public static void validateTranslogRetentionSettings(Settings indexSettings) {
* @param clusterSettings cluster setting
*/
public static void validateRefreshIntervalSettings(Settings requestSettings, ClusterSettings clusterSettings) {
validateRefreshIntervalSettings(requestSettings, clusterSettings, Settings.EMPTY);
}

/**
* Validates {@code index.refresh_interval} is equal or below the {@code cluster.minimum.index.refresh_interval}.
*
* @param requestSettings settings passed in during index create/update request
* @param clusterSettings cluster setting
* @param settings general settings to be checked for cluster minimum refresh interval. Useful while restoring ClusterState
*/
public static void validateRefreshIntervalSettings(Settings requestSettings, ClusterSettings clusterSettings, Settings settings) {
if (IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.exists(requestSettings) == false) {
return;
}
TimeValue requestRefreshInterval = IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.get(requestSettings);
TimeValue clusterMinimumRefreshInterval = clusterSettings.get(IndicesService.CLUSTER_MINIMUM_INDEX_REFRESH_INTERVAL_SETTING);
TimeValue clusterMinimumRefreshInterval = settings.getAsTime(
IndicesService.CLUSTER_MINIMUM_INDEX_REFRESH_INTERVAL_SETTING.getKey(),
clusterSettings.get(IndicesService.CLUSTER_MINIMUM_INDEX_REFRESH_INTERVAL_SETTING)
);
if (requestRefreshInterval.millis() < clusterMinimumRefreshInterval.millis()) {
throw new IllegalArgumentException(
"invalid index.refresh_interval ["
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ private void restoreGlobalMetadata(Metadata.Builder mdBuilder, Metadata remoteMe
}
if (remoteMetadata.templates() != null) {
for (final IndexTemplateMetadata cursor : remoteMetadata.templates().values()) {
MetadataCreateIndexService.validateRefreshIntervalSettings(
cursor.settings(),
clusterService.getClusterSettings(),
remoteMetadata.persistentSettings()
);
mdBuilder.put(cursor);
}
}
Expand Down

0 comments on commit 05045a2

Please sign in to comment.