From 783afbc1bf75f16f9cc7f40968658a2ecd545586 Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Fri, 3 Sep 2021 12:18:12 -0500 Subject: [PATCH] Adding node deprecation info API check for frozen cache setting (#77085) In 8.0 the ability to have a positive "xpack.searchable.snapshot.shared_cache.size" on a non-frozen node has been removed. This commit adds a deprecation info API check if a non-frozen node has a positive "xpack.searchable.snapshot.shared_cache.size". Relates #42404 #71013 --- .../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 86fec7cc03c02..d9da43df6bd9d 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 @@ -98,6 +98,7 @@ private DeprecationChecks() { NodeDeprecationChecks::checkImplicitlyDisabledSecurityOnBasicAndTrial, NodeDeprecationChecks::checkSearchRemoteSettings, NodeDeprecationChecks::checkMonitoringExporterPassword, + NodeDeprecationChecks::checkFrozenCacheLeniency, NodeDeprecationChecks::checkSslServerEnabled, NodeDeprecationChecks::checkSslCertConfiguration, NodeDeprecationChecks::checkClusterRoutingAllocationIncludeRelocationsSetting, 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 7bfe1bc75a42f..569e6db14db20 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 @@ -20,6 +20,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.ssl.SslConfigurationKeys; import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.common.util.set.Sets; @@ -35,6 +36,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.transport.SniffConnectionStrategy; import org.elasticsearch.transport.TransportService; import org.elasticsearch.xpack.core.XPackSettings; @@ -669,6 +671,30 @@ static DeprecationIssue checkClusterRoutingAllocationIncludeRelocationsSetting(f ); } + 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; + } + static DeprecationIssue checkSslServerEnabled(final Settings settings, final PluginsAndModules pluginsAndModules, final ClusterState clusterState, 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 a928d24580ba2..1b2520309c826 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 @@ -963,6 +963,70 @@ public void testImplicitlyConfiguredSecurityOnGoldPlus() { 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) + ); + } + public void testCheckSslServerEnabled() { String httpSslEnabledKey = "xpack.security.http.ssl.enabled"; String transportSslEnabledKey = "xpack.security.transport.ssl.enabled";