From f61c824c8f1cf044e1349ce322867d9648db47ff Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Tue, 31 Aug 2021 12:39:33 -0500 Subject: [PATCH] Adding node deprecation info API check for frozen cache setting --- .../xpack/deprecation/DeprecationChecks.java | 1 + .../deprecation/NodeDeprecationChecks.java | 26 ++++++++ .../NodeDeprecationChecksTests.java | 64 +++++++++++++++++++ 3 files changed, 91 insertions(+) diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java index dddccceb358ac..af37fb1e1fd51 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java @@ -95,6 +95,7 @@ private DeprecationChecks() { NodeDeprecationChecks::checkSingleDataNodeWatermarkSetting, NodeDeprecationChecks::checkImplicitlyDisabledSecurityOnBasicAndTrial, NodeDeprecationChecks::checkMonitoringExporterPassword, + NodeDeprecationChecks::checkFrozenCacheLeniency, NodeDeprecationChecks::checkClusterRoutingAllocationIncludeRelocationsSetting ) ).collect(Collectors.toList()); diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java index 4968eea4ed60f..e88c99b831f62 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java @@ -19,6 +19,7 @@ import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.env.Environment; @@ -30,6 +31,7 @@ import org.elasticsearch.script.ScriptService; import org.elasticsearch.threadpool.FixedExecutorBuilder; import org.elasticsearch.transport.RemoteClusterService; +import org.elasticsearch.xpack.core.DataTier; import org.elasticsearch.xpack.core.XPackSettings; import org.elasticsearch.xpack.core.security.authc.RealmConfig; import org.elasticsearch.xpack.core.security.authc.RealmSettings; @@ -595,4 +597,28 @@ static DeprecationIssue checkClusterRoutingAllocationIncludeRelocationsSetting(f DeprecationIssue.Level.CRITICAL ); } + + static DeprecationIssue checkFrozenCacheLeniency(final Settings settings, + final PluginsAndModules pluginsAndModules, + final ClusterState clusterState, + final XPackLicenseState licenseState) { + final String cacheSizeSettingKey = "xpack.searchable.snapshot.shared_cache.size"; + Setting cacheSizeSetting = Setting.byteSizeSetting(cacheSizeSettingKey, ByteSizeValue.ZERO); + if (cacheSizeSetting.exists(settings)) { + ByteSizeValue cacheSize = cacheSizeSetting.get(settings); + if (cacheSize.getBytes() > 0) { + final List roles = NodeRoleSettings.NODE_ROLES_SETTING.get(settings); + if (DataTier.isFrozenNode(new HashSet<>(roles)) == false) { + String message = String.format(Locale.ROOT, "setting [%s] cannot be greater than zero on non-frozen nodes", + cacheSizeSettingKey); + String url = + "https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html#breaking_80_settings_changes"; + String details = String.format(Locale.ROOT, "setting [%s] cannot be greater than zero on non-frozen nodes, and is " + + "currently set to [%s]", cacheSizeSettingKey, settings.get(cacheSizeSettingKey)); + return new DeprecationIssue(DeprecationIssue.Level.CRITICAL, message, url, details, false, null); + } + } + } + return null; + } } diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java index 0886f0dfe28fd..fb6ddc28395a4 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java @@ -863,4 +863,68 @@ public void testImplicitlyConfiguredSecurityOnGoldPlus() { final List issues = getDeprecationIssues(settings, pluginsAndModules, licenseState); assertThat(issues, empty()); } + + public void testCheckFrozenCacheLeniency() { + String cacheSizeSettingValue = "10gb"; + String cacheSizeSettingKey = "xpack.searchable.snapshot.shared_cache.size"; + Settings nodeSettings = Settings.builder() + .put(cacheSizeSettingKey, cacheSizeSettingValue) + .put("node.roles", "data_warm") + .build(); + final XPackLicenseState licenseState = new XPackLicenseState(Settings.EMPTY, () -> 0); + final ClusterState clusterState = ClusterState.EMPTY_STATE; + DeprecationIssue expectedIssue = new DeprecationIssue(DeprecationIssue.Level.CRITICAL, + String.format(Locale.ROOT, + "setting [%s] cannot be greater than zero on non-frozen nodes", + cacheSizeSettingKey), + "https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html#breaking_80_settings_changes", + String.format(Locale.ROOT, + "setting [%s] cannot be greater than zero on non-frozen nodes, and is currently set to [%s]", + cacheSizeSettingKey, + cacheSizeSettingValue), + false,null + ); + assertThat( + NodeDeprecationChecks.checkFrozenCacheLeniency(nodeSettings, null, clusterState, licenseState), + equalTo(expectedIssue) + ); + + // If no 'node.roles' is specified, a node gets all roles: + nodeSettings = Settings.builder() + .put(cacheSizeSettingKey, cacheSizeSettingValue) + .build(); + assertThat( + NodeDeprecationChecks.checkFrozenCacheLeniency(nodeSettings, null, clusterState, licenseState), + equalTo(null) + ); + + // No deprecation warning on a frozen node: + nodeSettings = Settings.builder() + .put(cacheSizeSettingKey, cacheSizeSettingValue) + .put("node.roles", "data_frozen") + .build(); + assertThat( + NodeDeprecationChecks.checkFrozenCacheLeniency(nodeSettings, null, clusterState, licenseState), + equalTo(null) + ); + + // No cache size specified, so no deprecation warning: + nodeSettings = Settings.builder() + .put("node.roles", "data_warm") + .build(); + assertThat( + NodeDeprecationChecks.checkFrozenCacheLeniency(nodeSettings, null, clusterState, licenseState), + equalTo(null) + ); + + // Cache size is not positive, so no deprecation wawrning: + nodeSettings = Settings.builder() + .put(cacheSizeSettingKey, "0b") + .put("node.roles", "data_warm") + .build(); + assertThat( + NodeDeprecationChecks.checkFrozenCacheLeniency(nodeSettings, null, clusterState, licenseState), + equalTo(null) + ); + } }