From f77d1e70089f5af03e7f47c54d6ba2b75959dc51 Mon Sep 17 00:00:00 2001 From: Christophe Bismuth Date: Thu, 4 Oct 2018 16:01:41 +0200 Subject: [PATCH] Add setting to apply to validation collection (#28309) --- .../settings/AbstractScopedSettings.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/common/settings/AbstractScopedSettings.java b/server/src/main/java/org/elasticsearch/common/settings/AbstractScopedSettings.java index 5c65a9f5c4ee6..cc5dcc6aed8e1 100644 --- a/server/src/main/java/org/elasticsearch/common/settings/AbstractScopedSettings.java +++ b/server/src/main/java/org/elasticsearch/common/settings/AbstractScopedSettings.java @@ -735,22 +735,21 @@ private boolean updateSettings(Settings toApply, Settings.Builder target, Settin private void validate(String key, Settings toApply, Settings target) { Settings.Builder toValidate = Settings.builder(); - // Reuse target settings to have a bigger picture, - // this helps to validate runtime dependencies - // (e.g. "low", "high" and "flood_stage" disk watermarks). - // Only valid target settings are kept. - target.keySet().forEach(targetKey -> { + validateAndCopy(target, toValidate); + validateAndCopy(toApply, toValidate); + toValidate.copy(key, toApply); + validate(toValidate.build(), false); + } + + private void validateAndCopy(Settings toCopy, Settings.Builder toValidate) { + toCopy.keySet().forEach(key -> { try { - validate(targetKey, target, false); - toValidate.copy(targetKey, target); + validate(key, toCopy, false); + toValidate.copy(key, toCopy); } catch (Exception ignored) { // Don't add invalid settings for validation } }); - // Put last to override existing target setting - toValidate.copy(key, toApply); - // We might not have a full picture here do to a dependency validation - validate(toValidate.build(), false); } private static boolean applyDeletes(Set deletes, Settings.Builder builder, Predicate canRemove) {