From ba73330bec52c7f514b47266d73ba27681a1e5c9 Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Wed, 31 Mar 2021 11:33:35 -0600 Subject: [PATCH 1/2] Make searchable snapshot cache size effectively zero on non-frozen nodes This commits makes the shared_cache searchable snapshot cache size setting resolve to 0 for nodes that to do have the data_frozen node role. Tangentially related to #70341 Supercedes #70846 --- .../searchable-snapshots/index.asciidoc | 6 ++-- .../cache/shared/FrozenCacheService.java | 21 +++++++++++--- .../cache/shared/FrozenCacheServiceTests.java | 28 +++++++++++++++++++ 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/docs/reference/searchable-snapshots/index.asciidoc b/docs/reference/searchable-snapshots/index.asciidoc index 3debbb52369ff..6d4d1b4228bc1 100644 --- a/docs/reference/searchable-snapshots/index.asciidoc +++ b/docs/reference/searchable-snapshots/index.asciidoc @@ -172,9 +172,9 @@ xpack.searchable.snapshot.shared_cache.size: 4TB ---- IMPORTANT: Currently, you can configure -`xpack.searchable.snapshot.shared_cache.size` on any node. In a future release, -you will only be able to configure this setting on nodes with the -<> role. +`xpack.searchable.snapshot.shared_cache.size` on any node. However, if the cache size is set on any +node that does not have the <> role, it will be treated as though it +is set to `0b`. You can set `xpack.searchable.snapshot.shared_cache.size` to any size between a couple of gigabytes up to 90% of available disk space. We only recommend larger diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/shared/FrozenCacheService.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/shared/FrozenCacheService.java index ffe54abd0094d..6925fd1dc4ccf 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/shared/FrozenCacheService.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/shared/FrozenCacheService.java @@ -30,12 +30,12 @@ import org.elasticsearch.common.util.concurrent.KeyedLock; import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.index.shard.ShardId; -import org.elasticsearch.xpack.searchablesnapshots.cache.common.CacheKey; -import org.elasticsearch.xpack.searchablesnapshots.cache.common.SparseFileTracker; import org.elasticsearch.node.NodeRoleSettings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.xpack.core.DataTier; import org.elasticsearch.xpack.searchablesnapshots.cache.common.ByteRange; +import org.elasticsearch.xpack.searchablesnapshots.cache.common.CacheKey; +import org.elasticsearch.xpack.searchablesnapshots.cache.common.SparseFileTracker; import java.io.IOException; import java.io.UncheckedIOException; @@ -46,6 +46,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.Executor; @@ -92,7 +93,7 @@ private static Setting.Validator getPageSizeAlignedByteSizeValueV }; } - public static final Setting SNAPSHOT_CACHE_SIZE_SETTING = new Setting<>( + public static final Setting SNAPSHOT_CACHE_SIZE_SETTING = new Setting( SHARED_CACHE_SETTINGS_PREFIX + "size", ByteSizeValue.ZERO.getStringRep(), s -> ByteSizeValue.parseBytesSizeValue(s, SHARED_CACHE_SETTINGS_PREFIX + "size"), @@ -132,7 +133,19 @@ public Iterator> settings() { }, Setting.Property.NodeScope - ); + ) { + @Override + public ByteSizeValue get(final Settings settings) { + final ByteSizeValue value = super.get(settings); + final List roles = NodeRoleSettings.NODE_ROLES_SETTING.get(settings); + final Set roleSet = new HashSet<>(roles); + if (DataTier.isFrozenNode(roleSet)) { + return value; + } else { + return ByteSizeValue.ZERO; + } + } + }; public static final Setting FROZEN_CACHE_RECOVERY_RANGE_SIZE_SETTING = Setting.byteSizeSetting( SHARED_CACHE_SETTINGS_PREFIX + "recovery_range_size", diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/shared/FrozenCacheServiceTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/shared/FrozenCacheServiceTests.java index 144080528d992..3de5084ff5069 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/shared/FrozenCacheServiceTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/shared/FrozenCacheServiceTests.java @@ -27,6 +27,7 @@ import java.util.HashSet; import static org.elasticsearch.node.Node.NODE_NAME_SETTING; +import static org.hamcrest.Matchers.equalTo; public class FrozenCacheServiceTests extends ESTestCase { @@ -223,6 +224,33 @@ public void testCacheSizeDeprecatedOnNonFrozenNodes() { ); } + public void testCacheSizeReturnsZeroOnNonFrozenNodes() { + DiscoveryNode.setAdditionalRoles( + new HashSet<>( + Arrays.asList( + DataTier.DATA_HOT_NODE_ROLE, + DataTier.DATA_WARM_NODE_ROLE, + DataTier.DATA_COLD_NODE_ROLE, + DataTier.DATA_FROZEN_NODE_ROLE + ) + ) + ); + final Settings settings = Settings.builder() + .put(FrozenCacheService.SNAPSHOT_CACHE_SIZE_SETTING.getKey(), new ByteSizeValue(size(500)).getStringRep()) + .put(FrozenCacheService.SNAPSHOT_CACHE_REGION_SIZE_SETTING.getKey(), new ByteSizeValue(size(100)).getStringRep()) + .putList(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), DataTier.DATA_HOT_NODE_ROLE.roleName()) + .build(); + final ByteSizeValue value = FrozenCacheService.SNAPSHOT_CACHE_SIZE_SETTING.get(settings); + assertThat(value, equalTo(ByteSizeValue.ZERO)); + assertWarnings( + "setting [" + + FrozenCacheService.SNAPSHOT_CACHE_SIZE_SETTING.getKey() + + "] to be positive [" + + new ByteSizeValue(size(500)).getStringRep() + + "] on node without the data_frozen role is deprecated, roles are [data_hot]" + ); + } + private static CacheKey generateCacheKey() { return new CacheKey( randomAlphaOfLength(10), From facc960ef30a6a840644d2c995a5e509089ab6a5 Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Thu, 1 Apr 2021 11:28:00 -0600 Subject: [PATCH 2/2] Update message in HasFrozenCacheAllocationDecider --- .../decider/HasFrozenCacheAllocationDecider.java | 5 ++++- .../cache/shared/FrozenCacheServiceTests.java | 12 +----------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/HasFrozenCacheAllocationDecider.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/HasFrozenCacheAllocationDecider.java index 76492e9cc2a5e..f03fb912dc58b 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/HasFrozenCacheAllocationDecider.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/HasFrozenCacheAllocationDecider.java @@ -9,6 +9,7 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.routing.RoutingNode; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; @@ -42,7 +43,9 @@ public class HasFrozenCacheAllocationDecider extends AllocationDecider { NAME, "node setting [" + SNAPSHOT_CACHE_SIZE_SETTING.getKey() - + "] is set to zero, so frozen searchable snapshot shards cannot be allocated to this node" + + "] is set to zero, or the node is not a [" + + DiscoveryNodeRole.DATA_FROZEN_NODE_ROLE.roleName() + + "] node, so frozen searchable snapshot shards cannot be allocated to this node" ); private static final Decision UNKNOWN_FROZEN_CACHE = Decision.single( diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/shared/FrozenCacheServiceTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/shared/FrozenCacheServiceTests.java index 0bafebdc4fc62..362abe2b532e1 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/shared/FrozenCacheServiceTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/shared/FrozenCacheServiceTests.java @@ -212,20 +212,10 @@ public void testCacheSizeDeprecatedOnNonFrozenNodes() { } public void testCacheSizeReturnsZeroOnNonFrozenNodes() { - DiscoveryNode.setAdditionalRoles( - new HashSet<>( - Arrays.asList( - DataTier.DATA_HOT_NODE_ROLE, - DataTier.DATA_WARM_NODE_ROLE, - DataTier.DATA_COLD_NODE_ROLE, - DataTier.DATA_FROZEN_NODE_ROLE - ) - ) - ); final Settings settings = Settings.builder() .put(FrozenCacheService.SNAPSHOT_CACHE_SIZE_SETTING.getKey(), new ByteSizeValue(size(500)).getStringRep()) .put(FrozenCacheService.SNAPSHOT_CACHE_REGION_SIZE_SETTING.getKey(), new ByteSizeValue(size(100)).getStringRep()) - .putList(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), DataTier.DATA_HOT_NODE_ROLE.roleName()) + .putList(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), DiscoveryNodeRole.DATA_HOT_NODE_ROLE.roleName()) .build(); final ByteSizeValue value = FrozenCacheService.SNAPSHOT_CACHE_SIZE_SETTING.get(settings); assertThat(value, equalTo(ByteSizeValue.ZERO));