Skip to content

Commit 54ca49f

Browse files
committed
Deprecate setting shared cache on non-frozen nodes (#70341)
This commit deprecates the ability to set the shared cache to be positive on non-frozen nodes.
1 parent f37c93e commit 54ca49f

File tree

4 files changed

+85
-3
lines changed

4 files changed

+85
-3
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/DataTier.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,11 @@ public static boolean isColdNode(DiscoveryNode discoveryNode) {
208208
}
209209

210210
public static boolean isFrozenNode(DiscoveryNode discoveryNode) {
211-
return discoveryNode.getRoles().contains(DATA_FROZEN_NODE_ROLE) || discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_ROLE);
211+
return isFrozenNode(discoveryNode.getRoles());
212+
}
213+
214+
public static boolean isFrozenNode(final Set<DiscoveryNodeRole> roles) {
215+
return roles.contains(DATA_FROZEN_NODE_ROLE) || roles.contains(DiscoveryNodeRole.DATA_ROLE);
212216
}
213217

214218
/**

x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/FrozenCacheService.java

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@
1313
import org.elasticsearch.Assertions;
1414
import org.elasticsearch.action.ActionListener;
1515
import org.elasticsearch.action.StepListener;
16+
import org.elasticsearch.cluster.node.DiscoveryNodeRole;
1617
import org.elasticsearch.common.Nullable;
1718
import org.elasticsearch.common.lease.Releasable;
1819
import org.elasticsearch.common.lease.Releasables;
20+
import org.elasticsearch.common.logging.DeprecationCategory;
21+
import org.elasticsearch.common.logging.DeprecationLogger;
1922
import org.elasticsearch.common.settings.Setting;
2023
import org.elasticsearch.common.settings.Settings;
24+
import org.elasticsearch.common.settings.SettingsException;
2125
import org.elasticsearch.common.unit.ByteSizeUnit;
2226
import org.elasticsearch.common.unit.ByteSizeValue;
2327
import org.elasticsearch.common.unit.TimeValue;
@@ -30,12 +34,18 @@
3034
import org.elasticsearch.index.shard.ShardId;
3135
import org.elasticsearch.index.store.cache.CacheKey;
3236
import org.elasticsearch.index.store.cache.SparseFileTracker;
37+
import org.elasticsearch.node.NodeRoleSettings;
3338
import org.elasticsearch.threadpool.ThreadPool;
39+
import org.elasticsearch.xpack.core.DataTier;
3440

3541
import java.io.IOException;
3642
import java.io.UncheckedIOException;
3743
import java.util.ArrayList;
44+
import java.util.Collections;
45+
import java.util.HashSet;
46+
import java.util.Iterator;
3847
import java.util.List;
48+
import java.util.Map;
3949
import java.util.Objects;
4050
import java.util.concurrent.ConcurrentHashMap;
4151
import java.util.concurrent.ConcurrentLinkedQueue;
@@ -45,6 +55,7 @@
4555
import java.util.function.Consumer;
4656
import java.util.function.LongSupplier;
4757
import java.util.function.Predicate;
58+
import java.util.stream.Collectors;
4859

4960
import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshotsUtils.toIntBytes;
5061

@@ -67,9 +78,45 @@ public class FrozenCacheService implements Releasable {
6778
Setting.Property.NodeScope
6879
);
6980

70-
public static final Setting<ByteSizeValue> SNAPSHOT_CACHE_SIZE_SETTING = Setting.byteSizeSetting(
81+
public static final Setting<ByteSizeValue> SNAPSHOT_CACHE_SIZE_SETTING = new Setting<>(
7182
SHARED_CACHE_SETTINGS_PREFIX + "size",
72-
ByteSizeValue.ZERO,
83+
ByteSizeValue.ZERO.getStringRep(),
84+
s -> ByteSizeValue.parseBytesSizeValue(s, SHARED_CACHE_SETTINGS_PREFIX + "size"),
85+
new Setting.Validator<ByteSizeValue>() {
86+
87+
@Override
88+
public void validate(final ByteSizeValue value) {
89+
90+
}
91+
92+
@Override
93+
public void validate(final ByteSizeValue value, final Map<Setting<?>, Object> settings) {
94+
if (value.getBytes() == -1) {
95+
throw new SettingsException("setting [{}] must be non-negative", SHARED_CACHE_SETTINGS_PREFIX + "size");
96+
}
97+
if (value.getBytes() > 0) {
98+
@SuppressWarnings("unchecked")
99+
final List<DiscoveryNodeRole> roles = (List<DiscoveryNodeRole>) settings.get(NodeRoleSettings.NODE_ROLES_SETTING);
100+
if (DataTier.isFrozenNode(new HashSet<>(roles)) == false) {
101+
deprecationLogger.deprecate(
102+
DeprecationCategory.SETTINGS,
103+
"shared_cache",
104+
"setting [{}] to be positive [{}] on node without the data_frozen role is deprecated, roles are [{}]",
105+
SHARED_CACHE_SETTINGS_PREFIX + "size",
106+
value.getStringRep(),
107+
roles.stream().map(DiscoveryNodeRole::roleName).collect(Collectors.joining(","))
108+
);
109+
}
110+
}
111+
}
112+
113+
@Override
114+
public Iterator<Setting<?>> settings() {
115+
final List<Setting<?>> settings = Collections.singletonList(NodeRoleSettings.NODE_ROLES_SETTING);
116+
return settings.iterator();
117+
}
118+
119+
},
73120
Setting.Property.NodeScope
74121
);
75122

@@ -105,6 +152,7 @@ public class FrozenCacheService implements Releasable {
105152
);
106153

107154
private static final Logger logger = LogManager.getLogger(FrozenCacheService.class);
155+
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(FrozenCacheService.class);
108156

109157
private final ConcurrentHashMap<RegionKey, Entry<CacheFileRegion>> keyMapping;
110158

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
preallocate: org.elasticsearch.xpack.searchablesnapshots.preallocate.Preallocate

x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/FrozenCacheServiceTests.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,23 @@
88
package org.elasticsearch.xpack.searchablesnapshots.cache;
99

1010
import org.elasticsearch.cluster.coordination.DeterministicTaskQueue;
11+
import org.elasticsearch.cluster.node.DiscoveryNode;
1112
import org.elasticsearch.common.settings.Settings;
1213
import org.elasticsearch.env.Environment;
1314
import org.elasticsearch.env.TestEnvironment;
1415
import org.elasticsearch.index.shard.ShardId;
1516
import org.elasticsearch.index.store.cache.CacheKey;
17+
import org.elasticsearch.node.NodeRoleSettings;
1618
import org.elasticsearch.test.ESTestCase;
1719
import org.elasticsearch.threadpool.ThreadPool;
20+
import org.elasticsearch.xpack.core.DataTier;
1821
import org.elasticsearch.xpack.searchablesnapshots.cache.FrozenCacheService.CacheFileRegion;
1922

2023
import java.io.IOException;
2124
import java.nio.file.Files;
2225
import java.nio.file.Path;
26+
import java.util.Arrays;
27+
import java.util.HashSet;
2328

2429
import static org.elasticsearch.node.Node.NODE_NAME_SETTING;
2530

@@ -192,6 +197,30 @@ public void testDecay() throws IOException {
192197
}
193198
}
194199

200+
public void testCacheSizeDeprecatedOnNonFrozenNodes() {
201+
DiscoveryNode.setAdditionalRoles(
202+
new HashSet<>(
203+
Arrays.asList(
204+
DataTier.DATA_HOT_NODE_ROLE,
205+
DataTier.DATA_WARM_NODE_ROLE,
206+
DataTier.DATA_COLD_NODE_ROLE,
207+
DataTier.DATA_FROZEN_NODE_ROLE
208+
)
209+
)
210+
);
211+
final Settings settings = Settings.builder()
212+
.put(FrozenCacheService.SNAPSHOT_CACHE_SIZE_SETTING.getKey(), "500b")
213+
.put(FrozenCacheService.SNAPSHOT_CACHE_REGION_SIZE_SETTING.getKey(), "100b")
214+
.putList(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), DataTier.DATA_HOT_NODE_ROLE.roleName())
215+
.build();
216+
FrozenCacheService.SNAPSHOT_CACHE_SIZE_SETTING.get(settings);
217+
assertWarnings(
218+
"setting ["
219+
+ FrozenCacheService.SNAPSHOT_CACHE_SIZE_SETTING.getKey()
220+
+ "] to be positive [500b] on node without the data_frozen role is deprecated, roles are [data_hot]"
221+
);
222+
}
223+
195224
private static CacheKey generateCacheKey() {
196225
return new CacheKey(
197226
randomAlphaOfLength(10),

0 commit comments

Comments
 (0)