From e15707cc4cd51ac7eb979c965bdb965d0580a551 Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Wed, 24 Mar 2021 16:24:51 -0600 Subject: [PATCH] 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. It turns out there is not a simple way to do this with the existing Settings infrastructure. Given that setting this on non-frozen nodes is already deprecated (and already outputs a deprecated log message), After talking to Ryan, we agreed it was better to handle this upon reading the setting rather than adding anything to the `Settings` code for only this purpose. I also attempted to make the shared cache setting private (so it actually couldn't be retrieved outside of the static method), however, it's still needed in the `SearchableSnapshots` plugin interface, so without moving it there, it has to remain public (I can move it there if we decide that would be better). Tangentially related to #70341 --- .../searchable-snapshots/index.asciidoc | 6 +-- ...ableSnapshotsBlobStoreCacheIntegTests.java | 2 +- .../BaseSearchableSnapshotsIntegTestCase.java | 2 +- ...tiallyCachedShardAllocationIntegTests.java | 14 ++---- ...pshotsCanMatchOnCoordinatorIntegTests.java | 2 +- .../HasFrozenCacheAllocationDecider.java | 8 ++- .../cache/FrozenCacheInfoNodeAction.java | 5 +- .../cache/FrozenCacheService.java | 25 ++++++++-- .../store/cache/FrozenIndexInputTests.java | 2 +- .../AbstractSearchableSnapshotsTestCase.java | 4 +- .../cache/FrozenCacheServiceTests.java | 50 +++++++++++++++++-- 11 files changed, 84 insertions(+), 36 deletions(-) diff --git a/docs/reference/searchable-snapshots/index.asciidoc b/docs/reference/searchable-snapshots/index.asciidoc index ab9f5d36b5cfc..a61b9f04003ca 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 higher diff --git a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/blobstore/cache/SearchableSnapshotsBlobStoreCacheIntegTests.java b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/blobstore/cache/SearchableSnapshotsBlobStoreCacheIntegTests.java index bc3f3aae7f8cf..298967f96ccda 100644 --- a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/blobstore/cache/SearchableSnapshotsBlobStoreCacheIntegTests.java +++ b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/blobstore/cache/SearchableSnapshotsBlobStoreCacheIntegTests.java @@ -79,7 +79,7 @@ public static void setUpCacheSettings() { builder.put(CacheService.SNAPSHOT_CACHE_RECOVERY_RANGE_SIZE_SETTING.getKey(), blobCacheMaxLength); // Frozen (shared cache) cache should be large enough to not cause direct reads - builder.put(FrozenCacheService.SNAPSHOT_CACHE_SIZE_SETTING.getKey(), ByteSizeValue.ofMb(128)); + builder.put(FrozenCacheService.SNAPSHOT_CACHE_SIZE, ByteSizeValue.ofMb(128)); // Align ranges to match the blob cache max length builder.put(FrozenCacheService.SNAPSHOT_CACHE_REGION_SIZE_SETTING.getKey(), blobCacheMaxLength); builder.put(FrozenCacheService.SHARED_CACHE_RANGE_SIZE_SETTING.getKey(), blobCacheMaxLength); diff --git a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/BaseSearchableSnapshotsIntegTestCase.java b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/BaseSearchableSnapshotsIntegTestCase.java index 49bf9162e8871..06cab9b3dfa2d 100644 --- a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/BaseSearchableSnapshotsIntegTestCase.java +++ b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/BaseSearchableSnapshotsIntegTestCase.java @@ -76,7 +76,7 @@ protected Settings nodeSettings(int nodeOrdinal) { ); } builder.put( - FrozenCacheService.SNAPSHOT_CACHE_SIZE_SETTING.getKey(), + FrozenCacheService.SNAPSHOT_CACHE_SIZE, rarely() ? randomBoolean() ? new ByteSizeValue(randomIntBetween(0, 10), ByteSizeUnit.KB) diff --git a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/PartiallyCachedShardAllocationIntegTests.java b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/PartiallyCachedShardAllocationIntegTests.java index 63531b70c89b3..4d43e93b6e97d 100644 --- a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/PartiallyCachedShardAllocationIntegTests.java +++ b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/PartiallyCachedShardAllocationIntegTests.java @@ -49,7 +49,7 @@ import static org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider.CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING; import static org.elasticsearch.index.IndexSettings.INDEX_SOFT_DELETES_SETTING; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; -import static org.elasticsearch.xpack.searchablesnapshots.cache.FrozenCacheService.SNAPSHOT_CACHE_SIZE_SETTING; +import static org.elasticsearch.xpack.searchablesnapshots.cache.FrozenCacheService.SNAPSHOT_CACHE_SIZE; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasItem; @@ -60,7 +60,7 @@ protected Settings nodeSettings(int nodeOrdinal) { return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) // default to no cache: the tests create nodes with a cache configured as needed - .put(SNAPSHOT_CACHE_SIZE_SETTING.getKey(), ByteSizeValue.ZERO) + .put(SNAPSHOT_CACHE_SIZE, ByteSizeValue.ZERO) .build(); } @@ -119,7 +119,7 @@ public void testPartialSearchableSnapshotNotAllocatedToNodesWithoutCache() throw .getDecisions() .stream() .anyMatch( - d -> d.getExplanation().contains(SNAPSHOT_CACHE_SIZE_SETTING.getKey()) + d -> d.getExplanation().contains(SNAPSHOT_CACHE_SIZE) && d.getExplanation().contains("frozen searchable snapshot shards cannot be allocated to this node") ) ); @@ -131,9 +131,7 @@ public void testPartialSearchableSnapshotAllocatedToNodesWithCache() throws Exce final List newNodeNames = internalCluster().startDataOnlyNodes( between(1, 3), - Settings.builder() - .put(SNAPSHOT_CACHE_SIZE_SETTING.getKey(), new ByteSizeValue(randomLongBetween(1, ByteSizeValue.ofMb(10).getBytes()))) - .build() + Settings.builder().put(SNAPSHOT_CACHE_SIZE, new ByteSizeValue(randomLongBetween(1, ByteSizeValue.ofMb(10).getBytes()))).build() ); final RestoreSnapshotResponse restoreSnapshotResponse = client().execute(MountSearchableSnapshotAction.INSTANCE, req).get(); @@ -199,9 +197,7 @@ public void onFailure(Exception e) { final List newNodes = internalCluster().startDataOnlyNodes( 2, - Settings.builder() - .put(SNAPSHOT_CACHE_SIZE_SETTING.getKey(), new ByteSizeValue(randomLongBetween(1, ByteSizeValue.ofMb(10).getBytes()))) - .build() + Settings.builder().put(SNAPSHOT_CACHE_SIZE, new ByteSizeValue(randomLongBetween(1, ByteSizeValue.ofMb(10).getBytes()))).build() ); final ActionFuture responseFuture = client().execute(MountSearchableSnapshotAction.INSTANCE, req); diff --git a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsCanMatchOnCoordinatorIntegTests.java b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsCanMatchOnCoordinatorIntegTests.java index 1f60ccda0e52e..0ea13809f9550 100644 --- a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsCanMatchOnCoordinatorIntegTests.java +++ b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsCanMatchOnCoordinatorIntegTests.java @@ -70,7 +70,7 @@ protected Settings nodeSettings(int nodeOrdinal) { // Use an unbound cache so we can recover the searchable snapshot completely all the times .put(CacheService.SNAPSHOT_CACHE_SIZE_SETTING.getKey(), new ByteSizeValue(Long.MAX_VALUE, ByteSizeUnit.BYTES)) // Have a shared cache of reasonable size available on each node because tests randomize over frozen and cold allocation - .put(FrozenCacheService.SNAPSHOT_CACHE_SIZE_SETTING.getKey(), ByteSizeValue.ofMb(randomLongBetween(1, 10))) + .put(FrozenCacheService.SNAPSHOT_CACHE_SIZE, ByteSizeValue.ofMb(randomLongBetween(1, 10))) .build(); } diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/HasFrozenCacheAllocationDecider.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/HasFrozenCacheAllocationDecider.java index 50dae8203a8e1..ee769510c226a 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/HasFrozenCacheAllocationDecider.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/HasFrozenCacheAllocationDecider.java @@ -18,7 +18,7 @@ import org.elasticsearch.xpack.searchablesnapshots.cache.FrozenCacheInfoService; import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshotsConstants.SNAPSHOT_PARTIAL_SETTING; -import static org.elasticsearch.xpack.searchablesnapshots.cache.FrozenCacheService.SNAPSHOT_CACHE_SIZE_SETTING; +import static org.elasticsearch.xpack.searchablesnapshots.cache.FrozenCacheService.SNAPSHOT_CACHE_SIZE; public class HasFrozenCacheAllocationDecider extends AllocationDecider { @@ -27,7 +27,7 @@ public class HasFrozenCacheAllocationDecider extends AllocationDecider { private static final Decision STILL_FETCHING = Decision.single( Decision.Type.THROTTLE, NAME, - "value of [" + SNAPSHOT_CACHE_SIZE_SETTING.getKey() + "] on this node is not known yet" + "value of [" + SNAPSHOT_CACHE_SIZE + "] on this node is not known yet" ); private static final Decision HAS_FROZEN_CACHE = Decision.single( @@ -39,9 +39,7 @@ public class HasFrozenCacheAllocationDecider extends AllocationDecider { private static final Decision NO_FROZEN_CACHE = Decision.single( Decision.Type.NO, NAME, - "node setting [" - + SNAPSHOT_CACHE_SIZE_SETTING.getKey() - + "] is set to zero, so frozen searchable snapshot shards cannot be allocated to this node" + "node setting [" + SNAPSHOT_CACHE_SIZE + "] is set to zero, 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/action/cache/FrozenCacheInfoNodeAction.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/action/cache/FrozenCacheInfoNodeAction.java index e7437200a18ec..63a5a61ab1de1 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/action/cache/FrozenCacheInfoNodeAction.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/action/cache/FrozenCacheInfoNodeAction.java @@ -18,11 +18,10 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.tasks.Task; import org.elasticsearch.transport.TransportService; +import org.elasticsearch.xpack.searchablesnapshots.cache.FrozenCacheService; import java.io.IOException; -import static org.elasticsearch.xpack.searchablesnapshots.cache.FrozenCacheService.SNAPSHOT_CACHE_SIZE_SETTING; - public class FrozenCacheInfoNodeAction extends ActionType { public static final String NAME = FrozenCacheInfoAction.NAME + "[n]"; @@ -53,7 +52,7 @@ public static class TransportAction extends HandledTransportAction 0); + response = new FrozenCacheInfoResponse(FrozenCacheService.getSnapshotCacheSize(settings).getBytes() > 0); } @Override diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/FrozenCacheService.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/FrozenCacheService.java index 3342afe0ac370..9084a54e294d2 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/FrozenCacheService.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/FrozenCacheService.java @@ -76,10 +76,25 @@ public class FrozenCacheService implements Releasable { Setting.Property.NodeScope ); + /** + * Returns the snapshot cache size to be used for the given settings, however, all non-frozen + * nodes (nodes whose node.roles setting does not contain "data_frozen" or "data") will use a + * value of 0 for the setting. + */ + public static ByteSizeValue getSnapshotCacheSize(Settings settings) { + List nodeRoles = NodeRoleSettings.NODE_ROLES_SETTING.get(settings); + if (DataTier.isFrozenNode(Set.of(nodeRoles.toArray(DiscoveryNodeRole[]::new)))) { + return SNAPSHOT_CACHE_SIZE_SETTING.get(settings); + } else { + return ByteSizeValue.ZERO; + } + } + + public static final String SNAPSHOT_CACHE_SIZE = SHARED_CACHE_SETTINGS_PREFIX + "size"; public static final Setting SNAPSHOT_CACHE_SIZE_SETTING = new Setting<>( - SHARED_CACHE_SETTINGS_PREFIX + "size", + SNAPSHOT_CACHE_SIZE, ByteSizeValue.ZERO.getStringRep(), - s -> ByteSizeValue.parseBytesSizeValue(s, SHARED_CACHE_SETTINGS_PREFIX + "size"), + s -> ByteSizeValue.parseBytesSizeValue(s, SNAPSHOT_CACHE_SIZE), new Setting.Validator() { @Override @@ -90,7 +105,7 @@ public void validate(final ByteSizeValue value) { @Override public void validate(final ByteSizeValue value, final Map, Object> settings) { if (value.getBytes() == -1) { - throw new SettingsException("setting [{}] must be non-negative", SHARED_CACHE_SETTINGS_PREFIX + "size"); + throw new SettingsException("setting [{}] must be non-negative", SNAPSHOT_CACHE_SIZE); } if (value.getBytes() > 0) { @SuppressWarnings("unchecked") @@ -100,7 +115,7 @@ public void validate(final ByteSizeValue value, final Map, Object> se DeprecationCategory.SETTINGS, "shared_cache", "setting [{}] to be positive [{}] on node without the data_frozen role is deprecated, roles are [{}]", - SHARED_CACHE_SETTINGS_PREFIX + "size", + SNAPSHOT_CACHE_SIZE, value.getStringRep(), roles.stream().map(DiscoveryNodeRole::roleName).collect(Collectors.joining(",")) ); @@ -175,7 +190,7 @@ public Iterator> settings() { @SuppressWarnings({ "unchecked", "rawtypes" }) public FrozenCacheService(NodeEnvironment environment, Settings settings, ThreadPool threadPool) { this.currentTimeSupplier = threadPool::relativeTimeInMillis; - final long cacheSize = SNAPSHOT_CACHE_SIZE_SETTING.get(settings).getBytes(); + final long cacheSize = getSnapshotCacheSize(settings).getBytes(); final long regionSize = SNAPSHOT_CACHE_REGION_SIZE_SETTING.get(settings).getBytes(); final int numRegions = Math.toIntExact(cacheSize / regionSize); keyMapping = new ConcurrentHashMap<>(); diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/index/store/cache/FrozenIndexInputTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/index/store/cache/FrozenIndexInputTests.java index 7b71c62a2abda..feffd701b6460 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/index/store/cache/FrozenIndexInputTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/index/store/cache/FrozenIndexInputTests.java @@ -83,7 +83,7 @@ public void testRandomReads() throws IOException { final Settings settings = Settings.builder() .put(FrozenCacheService.SNAPSHOT_CACHE_REGION_SIZE_SETTING.getKey(), regionSize) .put(FrozenCacheService.SHARED_CACHE_RANGE_SIZE_SETTING.getKey(), rangeSize) - .put(FrozenCacheService.SNAPSHOT_CACHE_SIZE_SETTING.getKey(), cacheSize) + .put(FrozenCacheService.SNAPSHOT_CACHE_SIZE, cacheSize) .put("path.home", createTempDir()) .build(); final Environment environment = TestEnvironment.newEnvironment(settings); diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/AbstractSearchableSnapshotsTestCase.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/AbstractSearchableSnapshotsTestCase.java index 948ace58ddaea..3aa2bf73b5291 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/AbstractSearchableSnapshotsTestCase.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/AbstractSearchableSnapshotsTestCase.java @@ -151,7 +151,7 @@ protected FrozenCacheService defaultFrozenCacheService() { protected FrozenCacheService randomFrozenCacheService() { final Settings.Builder cacheSettings = Settings.builder(); if (randomBoolean()) { - cacheSettings.put(FrozenCacheService.SNAPSHOT_CACHE_SIZE_SETTING.getKey(), randomFrozenCacheSize()); + cacheSettings.put(FrozenCacheService.SNAPSHOT_CACHE_SIZE, randomFrozenCacheSize()); } if (randomBoolean()) { cacheSettings.put(FrozenCacheService.SNAPSHOT_CACHE_REGION_SIZE_SETTING.getKey(), randomFrozenCacheSize()); @@ -184,7 +184,7 @@ protected FrozenCacheService createFrozenCacheService(final ByteSizeValue cacheS return new FrozenCacheService( nodeEnvironment, Settings.builder() - .put(FrozenCacheService.SNAPSHOT_CACHE_SIZE_SETTING.getKey(), cacheSize) + .put(FrozenCacheService.SNAPSHOT_CACHE_SIZE, cacheSize) .put(FrozenCacheService.SHARED_CACHE_RANGE_SIZE_SETTING.getKey(), cacheRangeSize) .build(), threadPool diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/FrozenCacheServiceTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/FrozenCacheServiceTests.java index d44a089386efd..3901826163cd6 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/FrozenCacheServiceTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/FrozenCacheServiceTests.java @@ -10,6 +10,7 @@ import org.elasticsearch.cluster.coordination.DeterministicTaskQueue; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.env.TestEnvironment; import org.elasticsearch.index.shard.ShardId; @@ -24,15 +25,20 @@ import java.util.Set; import static org.elasticsearch.node.Node.NODE_NAME_SETTING; +import static org.hamcrest.Matchers.equalTo; public class FrozenCacheServiceTests extends ESTestCase { public void testBasicEviction() throws IOException { + DiscoveryNode.setAdditionalRoles( + Set.of(DataTier.DATA_HOT_NODE_ROLE, DataTier.DATA_WARM_NODE_ROLE, DataTier.DATA_COLD_NODE_ROLE, DataTier.DATA_FROZEN_NODE_ROLE) + ); Settings settings = Settings.builder() .put(NODE_NAME_SETTING.getKey(), "node") - .put(FrozenCacheService.SNAPSHOT_CACHE_SIZE_SETTING.getKey(), "500b") + .put(FrozenCacheService.SNAPSHOT_CACHE_SIZE, "500b") .put(FrozenCacheService.SNAPSHOT_CACHE_REGION_SIZE_SETTING.getKey(), "100b") .put("path.home", createTempDir()) + .putList(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), DataTier.DATA_FROZEN_NODE_ROLE.roleName()) .build(); final DeterministicTaskQueue taskQueue = new DeterministicTaskQueue(settings, random()); try ( @@ -73,11 +79,15 @@ public void testBasicEviction() throws IOException { } public void testAutoEviction() throws IOException { + DiscoveryNode.setAdditionalRoles( + Set.of(DataTier.DATA_HOT_NODE_ROLE, DataTier.DATA_WARM_NODE_ROLE, DataTier.DATA_COLD_NODE_ROLE, DataTier.DATA_FROZEN_NODE_ROLE) + ); Settings settings = Settings.builder() .put(NODE_NAME_SETTING.getKey(), "node") - .put(FrozenCacheService.SNAPSHOT_CACHE_SIZE_SETTING.getKey(), "200b") + .put(FrozenCacheService.SNAPSHOT_CACHE_SIZE, "200b") .put(FrozenCacheService.SNAPSHOT_CACHE_REGION_SIZE_SETTING.getKey(), "100b") .put("path.home", createTempDir()) + .putList(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), DataTier.DATA_FROZEN_NODE_ROLE.roleName()) .build(); final DeterministicTaskQueue taskQueue = new DeterministicTaskQueue(settings, random()); try ( @@ -109,11 +119,15 @@ public void testAutoEviction() throws IOException { } public void testForceEviction() throws IOException { + DiscoveryNode.setAdditionalRoles( + Set.of(DataTier.DATA_HOT_NODE_ROLE, DataTier.DATA_WARM_NODE_ROLE, DataTier.DATA_COLD_NODE_ROLE, DataTier.DATA_FROZEN_NODE_ROLE) + ); Settings settings = Settings.builder() .put(NODE_NAME_SETTING.getKey(), "node") - .put(FrozenCacheService.SNAPSHOT_CACHE_SIZE_SETTING.getKey(), "500b") + .put(FrozenCacheService.SNAPSHOT_CACHE_SIZE, "500b") .put(FrozenCacheService.SNAPSHOT_CACHE_REGION_SIZE_SETTING.getKey(), "100b") .put("path.home", createTempDir()) + .putList(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), DataTier.DATA_FROZEN_NODE_ROLE.roleName()) .build(); final DeterministicTaskQueue taskQueue = new DeterministicTaskQueue(settings, random()); try ( @@ -137,11 +151,15 @@ public void testForceEviction() throws IOException { } public void testDecay() throws IOException { + DiscoveryNode.setAdditionalRoles( + Set.of(DataTier.DATA_HOT_NODE_ROLE, DataTier.DATA_WARM_NODE_ROLE, DataTier.DATA_COLD_NODE_ROLE, DataTier.DATA_FROZEN_NODE_ROLE) + ); Settings settings = Settings.builder() .put(NODE_NAME_SETTING.getKey(), "node") - .put(FrozenCacheService.SNAPSHOT_CACHE_SIZE_SETTING.getKey(), "500b") + .put(FrozenCacheService.SNAPSHOT_CACHE_SIZE, "500b") .put(FrozenCacheService.SNAPSHOT_CACHE_REGION_SIZE_SETTING.getKey(), "100b") .put("path.home", createTempDir()) + .putList(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), DataTier.DATA_FROZEN_NODE_ROLE.roleName()) .build(); final DeterministicTaskQueue taskQueue = new DeterministicTaskQueue(settings, random()); try ( @@ -195,7 +213,7 @@ public void testCacheSizeDeprecatedOnNonFrozenNodes() { Set.of(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(), "500b") + .put(FrozenCacheService.SNAPSHOT_CACHE_SIZE, "500b") .put(FrozenCacheService.SNAPSHOT_CACHE_REGION_SIZE_SETTING.getKey(), "100b") .putList(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), DataTier.DATA_HOT_NODE_ROLE.roleName()) .build(); @@ -207,6 +225,28 @@ public void testCacheSizeDeprecatedOnNonFrozenNodes() { ); } + public void testCacheSizeZeroOnNonFrozenNodes() { + DiscoveryNode.setAdditionalRoles( + Set.of(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, "500b") + .put(FrozenCacheService.SNAPSHOT_CACHE_REGION_SIZE_SETTING.getKey(), "100b") + .putList(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), DataTier.DATA_HOT_NODE_ROLE.roleName()) + .build(); + assertThat(FrozenCacheService.getSnapshotCacheSize(settings), equalTo(ByteSizeValue.ZERO)); + } + { + final Settings settings = Settings.builder() + .put(FrozenCacheService.SNAPSHOT_CACHE_SIZE, "500b") + .put(FrozenCacheService.SNAPSHOT_CACHE_REGION_SIZE_SETTING.getKey(), "100b") + .putList(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), DataTier.DATA_FROZEN_NODE_ROLE.roleName()) + .build(); + assertThat(FrozenCacheService.getSnapshotCacheSize(settings), equalTo(ByteSizeValue.ofBytes(500))); + } + } + private static CacheKey generateCacheKey() { return new CacheKey( randomAlphaOfLength(10),