Skip to content

Commit

Permalink
Remove desired node historical features (elastic#116951)
Browse files Browse the repository at this point in the history
  • Loading branch information
thecoop authored Nov 20, 2024
1 parent e5209f9 commit c2c0901
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.elasticsearch.Build;
import org.elasticsearch.action.admin.cluster.desirednodes.UpdateDesiredNodesRequest;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.ResponseException;
import org.elasticsearch.cluster.metadata.DesiredNode;
import org.elasticsearch.cluster.metadata.DesiredNodeWithStatus;
import org.elasticsearch.common.Strings;
Expand Down Expand Up @@ -42,22 +41,7 @@ public DesiredNodesUpgradeIT(@Name("upgradedNodes") int upgradedNodes) {
desiredNodesVersion = upgradedNodes + 1;
}

private enum ProcessorsPrecision {
DOUBLE,
FLOAT
}

public void testUpgradeDesiredNodes() throws Exception {
if (oldClusterHasFeature(DesiredNode.DOUBLE_PROCESSORS_SUPPORTED)) {
assertUpgradedNodesCanReadDesiredNodes();
} else if (oldClusterHasFeature(DesiredNode.RANGE_FLOAT_PROCESSORS_SUPPORTED)) {
assertDesiredNodesUpdatedWithRoundedUpFloatsAreIdempotent();
} else {
assertDesiredNodesWithFloatProcessorsAreRejectedInOlderVersions();
}
}

private void assertUpgradedNodesCanReadDesiredNodes() throws Exception {
if (isMixedCluster() || isUpgradedCluster()) {
final Map<String, Object> desiredNodes = getLatestDesiredNodes();
final String historyId = extractValue(desiredNodes, "history_id");
Expand All @@ -66,60 +50,10 @@ private void assertUpgradedNodesCanReadDesiredNodes() throws Exception {
assertThat(version, is(equalTo(desiredNodesVersion - 1)));
}

addClusterNodesToDesiredNodesWithProcessorsOrProcessorRanges(desiredNodesVersion, ProcessorsPrecision.DOUBLE);
addClusterNodesToDesiredNodesWithProcessorsOrProcessorRanges(desiredNodesVersion);
assertAllDesiredNodesAreActualized();
}

private void assertDesiredNodesUpdatedWithRoundedUpFloatsAreIdempotent() throws Exception {
// We define the same set of desired nodes to ensure that they are equal across all
// the test runs, otherwise we cannot guarantee an idempotent update in this test
final var desiredNodes = getNodeNames().stream()
.map(
nodeName -> new DesiredNode(
Settings.builder().put(NODE_NAME_SETTING.getKey(), nodeName).build(),
1238.49922909,
ByteSizeValue.ofGb(32),
ByteSizeValue.ofGb(128),
clusterHasFeature(DesiredNode.DESIRED_NODE_VERSION_DEPRECATED) ? null : Build.current().version()
)
)
.toList();

if (isMixedCluster()) {
updateDesiredNodes(desiredNodes, desiredNodesVersion - 1);
}
for (int i = 0; i < 2; i++) {
updateDesiredNodes(desiredNodes, desiredNodesVersion);
}

final Map<String, Object> latestDesiredNodes = getLatestDesiredNodes();
final int latestDesiredNodesVersion = extractValue(latestDesiredNodes, "version");
assertThat(latestDesiredNodesVersion, is(equalTo(desiredNodesVersion)));

if (isUpgradedCluster()) {
assertAllDesiredNodesAreActualized();
}
}

private void assertDesiredNodesWithFloatProcessorsAreRejectedInOlderVersions() throws Exception {
if (isOldCluster()) {
addClusterNodesToDesiredNodesWithIntegerProcessors(1);
} else if (isMixedCluster()) {
// Processor ranges or float processors are forbidden during upgrades: 8.2 -> 8.3 clusters
final var responseException = expectThrows(
ResponseException.class,
() -> addClusterNodesToDesiredNodesWithProcessorsOrProcessorRanges(desiredNodesVersion, ProcessorsPrecision.FLOAT)
);
final var statusCode = responseException.getResponse().getStatusLine().getStatusCode();
assertThat(statusCode, is(equalTo(400)));
} else {
assertAllDesiredNodesAreActualized();
addClusterNodesToDesiredNodesWithProcessorsOrProcessorRanges(4, ProcessorsPrecision.FLOAT);
}

getLatestDesiredNodes();
}

private Map<String, Object> getLatestDesiredNodes() throws IOException {
final var getDesiredNodesRequest = new Request("GET", "/_internal/desired_nodes/_latest");
final var response = client().performRequest(getDesiredNodesRequest);
Expand All @@ -140,15 +74,14 @@ private void assertAllDesiredNodesAreActualized() throws Exception {
}
}

private void addClusterNodesToDesiredNodesWithProcessorsOrProcessorRanges(int version, ProcessorsPrecision processorsPrecision)
throws Exception {
private void addClusterNodesToDesiredNodesWithProcessorsOrProcessorRanges(int version) throws Exception {
final List<DesiredNode> nodes;
if (randomBoolean()) {
nodes = getNodeNames().stream()
.map(
nodeName -> new DesiredNode(
Settings.builder().put(NODE_NAME_SETTING.getKey(), nodeName).build(),
processorsPrecision == ProcessorsPrecision.DOUBLE ? randomDoubleProcessorCount() : 0.5f,
randomDoubleProcessorCount(),
ByteSizeValue.ofGb(randomIntBetween(10, 24)),
ByteSizeValue.ofGb(randomIntBetween(128, 256)),
clusterHasFeature(DesiredNode.DESIRED_NODE_VERSION_DEPRECATED) ? null : Build.current().version()
Expand All @@ -157,9 +90,7 @@ private void addClusterNodesToDesiredNodesWithProcessorsOrProcessorRanges(int ve
.toList();
} else {
nodes = getNodeNames().stream().map(nodeName -> {
double minProcessors = processorsPrecision == ProcessorsPrecision.DOUBLE
? randomDoubleProcessorCount()
: randomFloatProcessorCount();
double minProcessors = randomDoubleProcessorCount();
return new DesiredNode(
Settings.builder().put(NODE_NAME_SETTING.getKey(), nodeName).build(),
new DesiredNode.ProcessorsRange(minProcessors, minProcessors + randomIntBetween(10, 20)),
Expand All @@ -172,21 +103,6 @@ private void addClusterNodesToDesiredNodesWithProcessorsOrProcessorRanges(int ve
updateDesiredNodes(nodes, version);
}

private void addClusterNodesToDesiredNodesWithIntegerProcessors(int version) throws Exception {
final var nodes = getNodeNames().stream()
.map(
nodeName -> new DesiredNode(
Settings.builder().put(NODE_NAME_SETTING.getKey(), nodeName).build(),
randomIntBetween(1, 24),
ByteSizeValue.ofGb(randomIntBetween(10, 24)),
ByteSizeValue.ofGb(randomIntBetween(128, 256)),
clusterHasFeature(DesiredNode.DESIRED_NODE_VERSION_DEPRECATED) ? null : Build.current().version()
)
)
.toList();
updateDesiredNodes(nodes, version);
}

private void updateDesiredNodes(List<DesiredNode> nodes, int version) throws IOException {
final var request = new Request("PUT", "/_internal/desired_nodes/upgrade_test/" + version);
try (var builder = JsonXContent.contentBuilder()) {
Expand Down Expand Up @@ -223,10 +139,6 @@ private double randomDoubleProcessorCount() {
return randomDoubleBetween(0.5, 512.1234, true);
}

private float randomFloatProcessorCount() {
return randomIntBetween(1, 512) + randomFloat();
}

@SuppressWarnings("unchecked")
private static <T> T extractValue(Map<String, Object> map, String path) {
return (T) XContentMapValues.extractValue(path, map);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.elasticsearch.cluster.block.ClusterBlockException;
import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.cluster.desirednodes.VersionConflictException;
import org.elasticsearch.cluster.metadata.DesiredNode;
import org.elasticsearch.cluster.metadata.DesiredNodes;
import org.elasticsearch.cluster.metadata.DesiredNodesMetadata;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
Expand Down Expand Up @@ -99,22 +98,6 @@ protected void masterOperation(
);
}

@Override
protected void doExecute(Task task, UpdateDesiredNodesRequest request, ActionListener<UpdateDesiredNodesResponse> listener) {
if (request.clusterHasRequiredFeatures(nf -> featureService.clusterHasFeature(clusterService.state(), nf)) == false) {
listener.onFailure(
new IllegalArgumentException(
"Unable to use processor ranges, floating-point (with greater precision) processors "
+ "in mixed-clusters with nodes that do not support feature "
+ DesiredNode.RANGE_FLOAT_PROCESSORS_SUPPORTED.id()
)
);
return;
}

super.doExecute(task, request, listener);
}

static ClusterState replaceDesiredNodes(ClusterState clusterState, DesiredNodes newDesiredNodes) {
return clusterState.copyAndUpdateMetadata(
metadata -> metadata.putCustom(DesiredNodesMetadata.TYPE, new DesiredNodesMetadata(newDesiredNodes))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.features.NodeFeature;
import org.elasticsearch.xcontent.ConstructingObjectParser;
import org.elasticsearch.xcontent.ParseField;
import org.elasticsearch.xcontent.XContentParser;

import java.io.IOException;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;

public class UpdateDesiredNodesRequest extends AcknowledgedRequest<UpdateDesiredNodesRequest> {
private static final TransportVersion DRY_RUN_VERSION = TransportVersions.V_8_4_0;
Expand Down Expand Up @@ -117,11 +115,6 @@ public boolean isDryRun() {
return dryRun;
}

public boolean clusterHasRequiredFeatures(Predicate<NodeFeature> clusterHasFeature) {
return clusterHasFeature.test(DesiredNode.RANGE_FLOAT_PROCESSORS_SUPPORTED)
|| nodes.stream().allMatch(n -> n.clusterHasRequiredFeatures(clusterHasFeature));
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;
import java.util.function.Predicate;
import java.util.regex.Pattern;

import static java.lang.String.format;
Expand All @@ -48,7 +47,6 @@
public final class DesiredNode implements Writeable, ToXContentObject, Comparable<DesiredNode> {

public static final NodeFeature RANGE_FLOAT_PROCESSORS_SUPPORTED = new NodeFeature("desired_node.range_float_processors");
public static final NodeFeature DOUBLE_PROCESSORS_SUPPORTED = new NodeFeature("desired_node.double_processors");
public static final NodeFeature DESIRED_NODE_VERSION_DEPRECATED = new NodeFeature("desired_node.version_deprecated");

public static final TransportVersion RANGE_FLOAT_PROCESSORS_SUPPORT_TRANSPORT_VERSION = TransportVersions.V_8_3_0;
Expand Down Expand Up @@ -348,10 +346,6 @@ public Set<DiscoveryNodeRole> getRoles() {
return roles;
}

public boolean clusterHasRequiredFeatures(Predicate<NodeFeature> clusterHasFeature) {
return (processorsRange == null && processors.hasDecimals() == false) || clusterHasFeature.test(RANGE_FLOAT_PROCESSORS_SUPPORTED);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,12 @@

package org.elasticsearch.cluster.metadata;

import org.elasticsearch.Version;
import org.elasticsearch.features.FeatureSpecification;
import org.elasticsearch.features.NodeFeature;

import java.util.Map;
import java.util.Set;

public class MetadataFeatures implements FeatureSpecification {
@Override
public Map<NodeFeature, Version> getHistoricalFeatures() {
return Map.of(
DesiredNode.RANGE_FLOAT_PROCESSORS_SUPPORTED,
Version.V_8_3_0,
DesiredNode.DOUBLE_PROCESSORS_SUPPORTED,
Version.V_8_5_0
);
}

@Override
public Set<NodeFeature> getFeatures() {
return Set.of(DesiredNode.DESIRED_NODE_VERSION_DEPRECATED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,38 +185,6 @@ public void testNodeCPUsRoundUp() {
}
}

public void testDesiredNodeHasRangeFloatProcessors() {
final var settings = Settings.builder().put(NODE_NAME_SETTING.getKey(), randomAlphaOfLength(10)).build();

{
final var desiredNode = new DesiredNode(
settings,
new DesiredNode.ProcessorsRange(0.4, 1.2),
ByteSizeValue.ofGb(1),
ByteSizeValue.ofGb(1)
);
assertThat(desiredNode.clusterHasRequiredFeatures(DesiredNode.RANGE_FLOAT_PROCESSORS_SUPPORTED::equals), is(true));
assertThat(desiredNode.clusterHasRequiredFeatures(nf -> false), is(false));
}

{
final var desiredNode = new DesiredNode(
settings,
randomIntBetween(0, 10) + randomDoubleBetween(0.00001, 0.99999, true),
ByteSizeValue.ofGb(1),
ByteSizeValue.ofGb(1)
);
assertThat(desiredNode.clusterHasRequiredFeatures(DesiredNode.RANGE_FLOAT_PROCESSORS_SUPPORTED::equals), is(true));
assertThat(desiredNode.clusterHasRequiredFeatures(nf -> false), is(false));
}

{
final var desiredNode = new DesiredNode(settings, 2.0f, ByteSizeValue.ofGb(1), ByteSizeValue.ofGb(1));
assertThat(desiredNode.clusterHasRequiredFeatures(DesiredNode.RANGE_FLOAT_PROCESSORS_SUPPORTED::equals), is(true));
assertThat(desiredNode.clusterHasRequiredFeatures(nf -> false), is(true));
}
}

public void testEqualsOrProcessorsCloseTo() {
final Settings settings = Settings.builder().put(NODE_NAME_SETTING.getKey(), randomAlphaOfLength(10)).build();
final double maxDelta = 1E-3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.Set;

import static org.elasticsearch.xcontent.XContentParserConfiguration.EMPTY;
import static org.hamcrest.Matchers.anEmptyMap;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.hasEntry;
Expand All @@ -48,7 +47,7 @@ public void testExtractHistoricalMetadata() throws IOException {
nodeFeatureVersionMap.putAll(historical);
featureNamesSet.addAll(names);
});
assertThat(nodeFeatureVersionMap, not(anEmptyMap()));
// assertThat(nodeFeatureVersionMap, not(anEmptyMap()));
assertThat(featureNamesSet, not(empty()));
assertThat(featureNamesSet, hasItem("test_features_enabled"));

Expand Down

0 comments on commit c2c0901

Please sign in to comment.