Emit settings deprecation logging on empty update

When executing a cluster settings update that leaves the cluster state
unchanged, we skip validation and this avoids deprecation logging for
deprecated settings in the cluster state. This commit addresses this by
running validation even if the settings are unchanged.

Relates #27017
This commit is contained in:
Jason Tedor 2017-10-25 22:15:38 -04:00 committed by GitHub
parent 9aae2f593a
commit 17d6820a4b
2 changed files with 62 additions and 26 deletions

View File

@ -58,10 +58,8 @@ final class SettingsUpdater {
persistentSettings.put(currentState.metaData().persistentSettings()); persistentSettings.put(currentState.metaData().persistentSettings());
changed |= clusterSettings.updateDynamicSettings(persistentToApply, persistentSettings, persistentUpdates, "persistent"); changed |= clusterSettings.updateDynamicSettings(persistentToApply, persistentSettings, persistentUpdates, "persistent");
if (!changed) { final ClusterState clusterState;
return currentState; if (changed) {
}
MetaData.Builder metaData = MetaData.builder(currentState.metaData()) MetaData.Builder metaData = MetaData.builder(currentState.metaData())
.persistentSettings(persistentSettings.build()) .persistentSettings(persistentSettings.build())
.transientSettings(transientSettings.build()); .transientSettings(transientSettings.build());
@ -81,12 +79,19 @@ final class SettingsUpdater {
} else { } else {
blocks.removeGlobalBlock(MetaData.CLUSTER_READ_ONLY_ALLOW_DELETE_BLOCK); blocks.removeGlobalBlock(MetaData.CLUSTER_READ_ONLY_ALLOW_DELETE_BLOCK);
} }
ClusterState build = builder(currentState).metaData(metaData).blocks(blocks).build(); clusterState = builder(currentState).metaData(metaData).blocks(blocks).build();
Settings settings = build.metaData().settings(); } else {
// now we try to apply things and if they are invalid we fail clusterState = currentState;
// this dryRun will validate & parse settings but won't actually apply them. }
/*
* Now we try to apply things and if they are invalid we fail. This dry run will validate, parse settings, and trigger deprecation
* logging, but will not actually apply them.
*/
final Settings settings = clusterState.metaData().settings();
clusterSettings.validateUpdate(settings); clusterSettings.validateUpdate(settings);
return build;
return clusterState;
} }

View File

@ -23,10 +23,15 @@ import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator; import org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator;
import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Setting.Property;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class SettingsUpdaterTests extends ESTestCase { public class SettingsUpdaterTests extends ESTestCase {
@ -132,4 +137,30 @@ public class SettingsUpdaterTests extends ESTestCase {
assertEquals(clusterState.blocks().global().size(), 0); assertEquals(clusterState.blocks().global().size(), 0);
} }
public void testDeprecationLogging() {
Setting<String> deprecatedSetting =
Setting.simpleString("deprecated.setting", Property.Dynamic, Property.NodeScope, Property.Deprecated);
final Settings settings = Settings.builder().put("deprecated.setting", "foo").build();
final Set<Setting<?>> settingsSet =
Stream.concat(ClusterSettings.BUILT_IN_CLUSTER_SETTINGS.stream(), Stream.of(deprecatedSetting)).collect(Collectors.toSet());
final ClusterSettings clusterSettings = new ClusterSettings(settings, settingsSet);
clusterSettings.addSettingsUpdateConsumer(deprecatedSetting, s -> {});
final SettingsUpdater settingsUpdater = new SettingsUpdater(clusterSettings);
final ClusterState clusterState =
ClusterState.builder(new ClusterName("foo")).metaData(MetaData.builder().persistentSettings(settings).build()).build();
final Settings toApplyDebug = Settings.builder().put("logger.org.elasticsearch", "debug").build();
final ClusterState afterDebug = settingsUpdater.updateSettings(clusterState, toApplyDebug, Settings.EMPTY);
assertSettingDeprecationsAndWarnings(new Setting<?>[] { deprecatedSetting });
final Settings toApplyUnset = Settings.builder().putNull("logger.org.elasticsearch").build();
final ClusterState afterUnset = settingsUpdater.updateSettings(afterDebug, toApplyUnset, Settings.EMPTY);
assertSettingDeprecationsAndWarnings(new Setting<?>[] { deprecatedSetting });
// we also check that if no settings are changed, deprecation logging still occurs
settingsUpdater.updateSettings(afterUnset, toApplyUnset, Settings.EMPTY);
assertSettingDeprecationsAndWarnings(new Setting<?>[] { deprecatedSetting });
}
} }