Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,11 @@ public static boolean isColdNode(DiscoveryNode discoveryNode) {
}

public static boolean isFrozenNode(DiscoveryNode discoveryNode) {
return discoveryNode.getRoles().contains(DATA_FROZEN_NODE_ROLE) || discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_ROLE);
return isFrozenNode(discoveryNode.getRoles());
}

public static boolean isFrozenNode(final Set<DiscoveryNodeRole> roles) {
return roles.contains(DATA_FROZEN_NODE_ROLE) || roles.contains(DiscoveryNodeRole.DATA_ROLE);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@
import org.elasticsearch.Assertions;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.StepListener;
import org.elasticsearch.cluster.node.DiscoveryNodeRole;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.lease.Releasable;
import org.elasticsearch.common.lease.Releasables;
import org.elasticsearch.common.logging.DeprecationCategory;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsException;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
Expand All @@ -30,13 +34,18 @@
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.index.store.cache.CacheKey;
import org.elasticsearch.index.store.cache.SparseFileTracker;
import org.elasticsearch.node.NodeRoleSettings;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.DataTier;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.ArrayList;
import java.util.Iterator;
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;
Expand All @@ -45,6 +54,7 @@
import java.util.function.Consumer;
import java.util.function.LongSupplier;
import java.util.function.Predicate;
import java.util.stream.Collectors;

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

Expand All @@ -67,9 +77,45 @@ public class FrozenCacheService implements Releasable {
Setting.Property.NodeScope
);

public static final Setting<ByteSizeValue> SNAPSHOT_CACHE_SIZE_SETTING = Setting.byteSizeSetting(
public static final Setting<ByteSizeValue> SNAPSHOT_CACHE_SIZE_SETTING = new Setting<>(
SHARED_CACHE_SETTINGS_PREFIX + "size",
ByteSizeValue.ZERO,
ByteSizeValue.ZERO.getStringRep(),
s -> ByteSizeValue.parseBytesSizeValue(s, SHARED_CACHE_SETTINGS_PREFIX + "size"),
new Setting.Validator<ByteSizeValue>() {

@Override
public void validate(final ByteSizeValue value) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we disallow a ByteSizeValue of -1b since that is a valid ByteSizeValue object here?

It feels like the setting should be either 0b or > 0b, but not -1.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed 3f02383.

}

@Override
public void validate(final ByteSizeValue value, final Map<Setting<?>, Object> settings) {
if (value.getBytes() == -1) {
throw new SettingsException("setting [{}] must be non-negative", SHARED_CACHE_SETTINGS_PREFIX + "size");
}
if (value.getBytes() > 0) {
@SuppressWarnings("unchecked")
final List<DiscoveryNodeRole> roles = (List<DiscoveryNodeRole>) settings.get(NodeRoleSettings.NODE_ROLES_SETTING);
if (DataTier.isFrozenNode(Set.of(roles.toArray(DiscoveryNodeRole[]::new))) == false) {
deprecationLogger.deprecate(
DeprecationCategory.SETTINGS,
"shared_cache",
"setting [{}] to be positive [{}] on node without the data_frozen role is deprecated, roles are [{}]",
SHARED_CACHE_SETTINGS_PREFIX + "size",
value.getStringRep(),
roles.stream().map(DiscoveryNodeRole::roleName).collect(Collectors.joining(","))
);
}
}
}

@Override
public Iterator<Setting<?>> settings() {
final List<Setting<?>> settings = List.of(NodeRoleSettings.NODE_ROLES_SETTING);
return settings.iterator();
}

},
Setting.Property.NodeScope
);

Expand Down Expand Up @@ -105,6 +151,7 @@ public class FrozenCacheService implements Releasable {
);

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
preallocate: org.elasticsearch.xpack.searchablesnapshots.preallocate.Preallocate
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unrelated to this change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's needed to be able to run the relevant unit tests inside of IntelliJ.

Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@
package org.elasticsearch.xpack.searchablesnapshots.cache;

import org.elasticsearch.cluster.coordination.DeterministicTaskQueue;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.env.TestEnvironment;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.index.store.cache.CacheKey;
import org.elasticsearch.node.NodeRoleSettings;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.DataTier;
import org.elasticsearch.xpack.searchablesnapshots.cache.FrozenCacheService.CacheFileRegion;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Set;

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

Expand Down Expand Up @@ -192,6 +196,23 @@ public void testDecay() throws IOException {
}
}

public void testCacheSizeDeprecatedOnNonFrozenNodes() {
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_SETTING.getKey(), "500b")
.put(FrozenCacheService.SNAPSHOT_CACHE_REGION_SIZE_SETTING.getKey(), "100b")
.putList(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), DataTier.DATA_HOT_NODE_ROLE.roleName())
.build();
FrozenCacheService.SNAPSHOT_CACHE_SIZE_SETTING.get(settings);
assertWarnings(
"setting ["
+ FrozenCacheService.SNAPSHOT_CACHE_SIZE_SETTING.getKey()
+ "] to be positive [500b] on node without the data_frozen role is deprecated, roles are [data_hot]"
);
}

private static CacheKey generateCacheKey() {
return new CacheKey(
randomAlphaOfLength(10),
Expand Down