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/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/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 658b36286fa3e..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 @@ -24,6 +24,7 @@ import java.io.IOException; import static org.elasticsearch.node.Node.NODE_NAME_SETTING; +import static org.hamcrest.Matchers.equalTo; public class FrozenCacheServiceTests extends ESTestCase { @@ -210,6 +211,23 @@ public void testCacheSizeDeprecatedOnNonFrozenNodes() { ); } + public void testCacheSizeReturnsZeroOnNonFrozenNodes() { + 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(), DiscoveryNodeRole.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),