From 908d34d83a6afbcd69d8811f418ad6e8be11d8d1 Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Thu, 7 Nov 2024 12:03:52 +0000 Subject: [PATCH] Remove 8.11 node version inference code (#116019) --- .../elasticsearch/cluster/ClusterState.java | 94 +++---------------- .../cluster/coordination/JoinRequest.java | 28 +----- .../xpack/core/ml/MlConfigVersion.java | 6 +- .../transform/TransformConfigVersion.java | 6 +- .../xpack/core/ml/MlConfigVersionTests.java | 9 -- .../TransformConfigVersionTests.java | 9 -- .../ml/action/TrainedModelValidatorTests.java | 31 ------ .../xpack/ml/job/JobNodeSelectorTests.java | 13 --- 8 files changed, 23 insertions(+), 173 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/cluster/ClusterState.java b/server/src/main/java/org/elasticsearch/cluster/ClusterState.java index f7cad013554c6..1364f0c78f3be 100644 --- a/server/src/main/java/org/elasticsearch/cluster/ClusterState.java +++ b/server/src/main/java/org/elasticsearch/cluster/ClusterState.java @@ -47,6 +47,7 @@ import org.elasticsearch.common.xcontent.ChunkedToXContentHelper; import org.elasticsearch.core.Nullable; import org.elasticsearch.core.SuppressForbidden; +import org.elasticsearch.core.UpdateForV9; import org.elasticsearch.index.shard.IndexLongFieldRange; import org.elasticsearch.indices.SystemIndexDescriptor; import org.elasticsearch.xcontent.ToXContent; @@ -1025,29 +1026,14 @@ public static ClusterState readFrom(StreamInput in, DiscoveryNode localNode) thr builder.metadata = Metadata.readFrom(in); builder.routingTable = RoutingTable.readFrom(in); builder.nodes = DiscoveryNodes.readFrom(in, localNode); - if (in.getTransportVersion().onOrAfter(TransportVersions.V_8_8_0)) { - builder.nodeIdsToCompatibilityVersions(in.readMap(CompatibilityVersions::readVersion)); - } else { - // this clusterstate is from a pre-8.8.0 node - // infer the versions from discoverynodes for now - // leave mappings versions empty - builder.nodes() - .getNodes() - .values() - .forEach(n -> builder.putCompatibilityVersions(n.getId(), inferTransportVersion(n), Map.of())); - } - if (in.getTransportVersion().onOrAfter(TransportVersions.V_8_12_0)) { - builder.nodeFeatures(ClusterFeatures.readFrom(in)); - } + builder.nodeIdsToCompatibilityVersions(in.readMap(CompatibilityVersions::readVersion)); + builder.nodeFeatures(ClusterFeatures.readFrom(in)); builder.blocks = ClusterBlocks.readFrom(in); int customSize = in.readVInt(); for (int i = 0; i < customSize; i++) { Custom customIndexMetadata = in.readNamedWriteable(Custom.class); builder.putCustom(customIndexMetadata.getWriteableName(), customIndexMetadata); } - if (in.getTransportVersion().before(TransportVersions.V_8_0_0)) { - in.readVInt(); // used to be minimumMasterNodesOnPublishingMaster, which was used in 7.x for BWC with 6.x - } return builder.build(); } @@ -1055,22 +1041,10 @@ public static ClusterState readFrom(StreamInput in, DiscoveryNode localNode) thr * If the cluster state does not contain transport version information, this is the version * that is inferred for all nodes on version 8.8.0 or above. */ + @UpdateForV9(owner = UpdateForV9.Owner.CORE_INFRA) public static final TransportVersion INFERRED_TRANSPORT_VERSION = TransportVersions.V_8_8_0; - public static final Version VERSION_INTRODUCING_TRANSPORT_VERSIONS = Version.V_8_8_0; - private static TransportVersion inferTransportVersion(DiscoveryNode node) { - TransportVersion tv; - if (node.getVersion().before(VERSION_INTRODUCING_TRANSPORT_VERSIONS)) { - // 1-to-1 mapping between Version and TransportVersion - tv = TransportVersion.fromId(node.getPre811VersionId().getAsInt()); - } else { - // use the lowest value it could be for now - tv = INFERRED_TRANSPORT_VERSION; - } - return tv; - } - @Override public void writeTo(StreamOutput out) throws IOException { clusterName.writeTo(out); @@ -1079,17 +1053,10 @@ public void writeTo(StreamOutput out) throws IOException { metadata.writeTo(out); routingTable.writeTo(out); nodes.writeTo(out); - if (out.getTransportVersion().onOrAfter(TransportVersions.V_8_8_0)) { - out.writeMap(compatibilityVersions, StreamOutput::writeWriteable); - } - if (out.getTransportVersion().onOrAfter(TransportVersions.V_8_12_0)) { - clusterFeatures.writeTo(out); - } + out.writeMap(compatibilityVersions, StreamOutput::writeWriteable); + clusterFeatures.writeTo(out); blocks.writeTo(out); VersionedNamedWriteable.writeVersionedWritables(out, customs); - if (out.getTransportVersion().before(TransportVersions.V_8_0_0)) { - out.writeVInt(-1); // used to be minimumMasterNodesOnPublishingMaster, which was used in 7.x for BWC with 6.x - } } private static class ClusterStateDiff implements Diff { @@ -1106,7 +1073,6 @@ private static class ClusterStateDiff implements Diff { private final Diff nodes; - @Nullable private final Diff> versions; private final Diff features; @@ -1142,26 +1108,13 @@ private static class ClusterStateDiff implements Diff { toVersion = in.readLong(); routingTable = RoutingTable.readDiffFrom(in); nodes = DiscoveryNodes.readDiffFrom(in, localNode); - if (in.getTransportVersion().onOrAfter(TransportVersions.V_8_8_0) && in.readBoolean()) { - versions = DiffableUtils.readJdkMapDiff( - in, - DiffableUtils.getStringKeySerializer(), - COMPATIBILITY_VERSIONS_VALUE_SERIALIZER - ); - } else { - versions = null; // infer at application time - } - if (in.getTransportVersion().onOrAfter(TransportVersions.V_8_12_0)) { - features = ClusterFeatures.readDiffFrom(in); - } else { - features = null; // fill in when nodes re-register with a master that understands features - } + boolean versionPresent = in.readBoolean(); + if (versionPresent == false) throw new IOException("ClusterStateDiff stream must have versions"); + versions = DiffableUtils.readJdkMapDiff(in, DiffableUtils.getStringKeySerializer(), COMPATIBILITY_VERSIONS_VALUE_SERIALIZER); + features = ClusterFeatures.readDiffFrom(in); metadata = Metadata.readDiffFrom(in); blocks = ClusterBlocks.readDiffFrom(in); customs = DiffableUtils.readJdkMapDiff(in, DiffableUtils.getStringKeySerializer(), CUSTOM_VALUE_SERIALIZER); - if (in.getTransportVersion().before(TransportVersions.V_8_0_0)) { - in.readVInt(); // used to be minimumMasterNodesOnPublishingMaster, which was used in 7.x for BWC with 6.x - } } @Override @@ -1172,18 +1125,12 @@ public void writeTo(StreamOutput out) throws IOException { out.writeLong(toVersion); routingTable.writeTo(out); nodes.writeTo(out); - if (out.getTransportVersion().onOrAfter(TransportVersions.V_8_8_0)) { - out.writeOptionalWriteable(versions); - } - if (out.getTransportVersion().onOrAfter(TransportVersions.V_8_12_0)) { - features.writeTo(out); - } + out.writeBoolean(true); + versions.writeTo(out); + features.writeTo(out); metadata.writeTo(out); blocks.writeTo(out); customs.writeTo(out); - if (out.getTransportVersion().before(TransportVersions.V_8_0_0)) { - out.writeVInt(-1); // used to be minimumMasterNodesOnPublishingMaster, which was used in 7.x for BWC with 6.x - } } @Override @@ -1200,19 +1147,8 @@ public ClusterState apply(ClusterState state) { builder.version(toVersion); builder.routingTable(routingTable.apply(state.routingTable)); builder.nodes(nodes.apply(state.nodes)); - if (versions != null) { - builder.nodeIdsToCompatibilityVersions(this.versions.apply(state.compatibilityVersions)); - } else { - // infer the versions from discoverynodes for now - // leave mappings versions empty - builder.nodes() - .getNodes() - .values() - .forEach(n -> builder.putCompatibilityVersions(n.getId(), inferTransportVersion(n), Map.of())); - } - if (features != null) { - builder.nodeFeatures(this.features.apply(state.clusterFeatures)); - } + builder.nodeIdsToCompatibilityVersions(this.versions.apply(state.compatibilityVersions)); + builder.nodeFeatures(this.features.apply(state.clusterFeatures)); builder.metadata(metadata.apply(state.metadata)); builder.blocks(blocks.apply(state.blocks)); builder.customs(customs.apply(state.customs)); diff --git a/server/src/main/java/org/elasticsearch/cluster/coordination/JoinRequest.java b/server/src/main/java/org/elasticsearch/cluster/coordination/JoinRequest.java index 2247d7a92cf41..5f499634fdbaa 100644 --- a/server/src/main/java/org/elasticsearch/cluster/coordination/JoinRequest.java +++ b/server/src/main/java/org/elasticsearch/cluster/coordination/JoinRequest.java @@ -8,8 +8,6 @@ */ package org.elasticsearch.cluster.coordination; -import org.elasticsearch.TransportVersion; -import org.elasticsearch.TransportVersions; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.version.CompatibilityVersions; import org.elasticsearch.common.io.stream.StreamInput; @@ -17,7 +15,6 @@ import org.elasticsearch.transport.TransportRequest; import java.io.IOException; -import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Set; @@ -72,21 +69,8 @@ public JoinRequest( public JoinRequest(StreamInput in) throws IOException { super(in); sourceNode = new DiscoveryNode(in); - if (in.getTransportVersion().onOrAfter(TransportVersions.V_8_8_0)) { - compatibilityVersions = CompatibilityVersions.readVersion(in); - } else { - // there's a 1-1 mapping from Version to TransportVersion before 8.8.0 - // no known mapping versions here - compatibilityVersions = new CompatibilityVersions( - TransportVersion.fromId(sourceNode.getPre811VersionId().getAsInt()), - Map.of() - ); - } - if (in.getTransportVersion().onOrAfter(TransportVersions.V_8_12_0)) { - features = in.readCollectionAsSet(StreamInput::readString); - } else { - features = Set.of(); - } + compatibilityVersions = CompatibilityVersions.readVersion(in); + features = in.readCollectionAsSet(StreamInput::readString); minimumTerm = in.readLong(); optionalJoin = Optional.ofNullable(in.readOptionalWriteable(Join::new)); } @@ -95,12 +79,8 @@ public JoinRequest(StreamInput in) throws IOException { public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); sourceNode.writeTo(out); - if (out.getTransportVersion().onOrAfter(TransportVersions.V_8_8_0)) { - compatibilityVersions.writeTo(out); - } - if (out.getTransportVersion().onOrAfter(TransportVersions.V_8_12_0)) { - out.writeCollection(features, StreamOutput::writeString); - } + compatibilityVersions.writeTo(out); + out.writeCollection(features, StreamOutput::writeString); out.writeLong(minimumTerm); out.writeOptionalWriteable(optionalJoin.orElse(null)); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/MlConfigVersion.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/MlConfigVersion.java index 1b365bd96d834..409dde2d06d92 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/MlConfigVersion.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/MlConfigVersion.java @@ -298,10 +298,8 @@ public static Tuple getMinMaxMlConfigVersion(D public static MlConfigVersion getMlConfigVersionForNode(DiscoveryNode node) { String mlConfigVerStr = node.getAttributes().get(ML_CONFIG_VERSION_NODE_ATTR); - if (mlConfigVerStr != null) { - return fromString(mlConfigVerStr); - } - return fromId(node.getPre811VersionId().orElseThrow(() -> new IllegalStateException("getting legacy version id not possible"))); + if (mlConfigVerStr == null) throw new IllegalStateException(ML_CONFIG_VERSION_NODE_ATTR + " not present on node"); + return fromString(mlConfigVerStr); } // Parse an MlConfigVersion from a string. diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/TransformConfigVersion.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/TransformConfigVersion.java index ef65f4bca1c35..a1cc978af20e6 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/TransformConfigVersion.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/TransformConfigVersion.java @@ -331,10 +331,8 @@ public static Tuple getMinMaxTra public static TransformConfigVersion getTransformConfigVersionForNode(DiscoveryNode node) { String transformConfigVerStr = node.getAttributes().get(TRANSFORM_CONFIG_VERSION_NODE_ATTR); - if (transformConfigVerStr != null) { - return fromString(transformConfigVerStr); - } - return fromId(node.getPre811VersionId().orElseThrow(() -> new IllegalStateException("getting legacy version id not possible"))); + if (transformConfigVerStr == null) throw new IllegalStateException(TRANSFORM_CONFIG_VERSION_NODE_ATTR + " not present on node"); + return fromString(transformConfigVerStr); } // Parse an TransformConfigVersion from a string. diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/MlConfigVersionTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/MlConfigVersionTests.java index 34428c303a076..4a3fd101b507d 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/MlConfigVersionTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/MlConfigVersionTests.java @@ -196,15 +196,6 @@ public void testGetMinMaxMlConfigVersionWhenMlConfigVersionAttrIsMissing() { } public void testGetMlConfigVersionForNode() { - DiscoveryNode node = DiscoveryNodeUtils.builder("_node_id4") - .name("_node_name4") - .address(new TransportAddress(InetAddress.getLoopbackAddress(), 9303)) - .roles(ROLES_WITH_ML) - .version(VersionInformation.inferVersions(Version.fromString("8.7.0"))) - .build(); - MlConfigVersion mlConfigVersion = MlConfigVersion.getMlConfigVersionForNode(node); - assertEquals(MlConfigVersion.V_8_7_0, mlConfigVersion); - DiscoveryNode node1 = DiscoveryNodeUtils.builder("_node_id5") .name("_node_name5") .address(new TransportAddress(InetAddress.getLoopbackAddress(), 9304)) diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/transform/TransformConfigVersionTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/transform/TransformConfigVersionTests.java index b42056372b1ab..acb89298ed568 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/transform/TransformConfigVersionTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/transform/TransformConfigVersionTests.java @@ -155,15 +155,6 @@ public void testGetMinMaxTransformConfigVersion() { } public void testGetTransformConfigVersionForNode() { - DiscoveryNode node = DiscoveryNodeUtils.builder("_node_id4") - .name("_node_name4") - .address(new TransportAddress(InetAddress.getLoopbackAddress(), 9303)) - .roles(ROLES_WITH_TRANSFORM) - .version(VersionInformation.inferVersions(Version.fromString("8.7.0"))) - .build(); - TransformConfigVersion transformConfigVersion = TransformConfigVersion.getTransformConfigVersionForNode(node); - assertEquals(TransformConfigVersion.V_8_7_0, transformConfigVersion); - DiscoveryNode node1 = DiscoveryNodeUtils.builder("_node_id5") .name("_node_name5") .address(new TransportAddress(InetAddress.getLoopbackAddress(), 9304)) diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TrainedModelValidatorTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TrainedModelValidatorTests.java index f8755b282c6a1..239f392e9f905 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TrainedModelValidatorTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TrainedModelValidatorTests.java @@ -64,37 +64,6 @@ public void testValidateMinimumVersion() { { ClusterState state = mock(ClusterState.class); - final ModelPackageConfig packageConfigCurrent = new ModelPackageConfig.Builder( - ModelPackageConfigTests.randomModulePackageConfig() - ).setMinimumVersion(MlConfigVersion.CURRENT.toString()).build(); - - DiscoveryNode node = DiscoveryNodeUtils.create( - "node1", - new TransportAddress(InetAddress.getLoopbackAddress(), 9300), - Version.V_8_7_0 - ); - - DiscoveryNodes nodes = DiscoveryNodes.builder().add(node).build(); - - when(state.nodes()).thenReturn(nodes); - - Exception e = expectThrows( - ActionRequestValidationException.class, - () -> TrainedModelValidator.validateMinimumVersion(packageConfigCurrent, state) - ); - - assertEquals( - "Validation Failed: 1: The model [" - + packageConfigCurrent.getPackagedModelId() - + "] requires that all nodes have ML config version [" - + MlConfigVersion.CURRENT - + "] or higher;", - e.getMessage() - ); - } - { - ClusterState state = mock(ClusterState.class); - final ModelPackageConfig packageConfigBroken = new ModelPackageConfig.Builder( ModelPackageConfigTests.randomModulePackageConfig() ).setMinimumVersion("_broken_version_").build(); diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/JobNodeSelectorTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/JobNodeSelectorTests.java index 112a8c80b0483..f7fb82f5d233c 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/JobNodeSelectorTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/JobNodeSelectorTests.java @@ -88,19 +88,6 @@ public void testNodeNameAndVersionForRecentNode() { assertEquals("{_node_name1}{ML config version=10.0.0}", JobNodeSelector.nodeNameAndVersion(node)); } - public void testNodeNameAndVersionForOldNode() { - TransportAddress ta = new TransportAddress(InetAddress.getLoopbackAddress(), 9300); - Map attributes = Map.of("unrelated", "attribute"); - DiscoveryNode node = DiscoveryNodeUtils.builder("_node_id2") - .name("_node_name2") - .address(ta) - .attributes(attributes) - .roles(ROLES_WITH_ML) - .version(VersionInformation.inferVersions(Version.V_8_7_0)) - .build(); - assertEquals("{_node_name2}{ML config version=8.7.0}", JobNodeSelector.nodeNameAndVersion(node)); - } - public void testNodeNameAndMlAttributes() { TransportAddress ta = new TransportAddress(InetAddress.getLoopbackAddress(), 9300); SortedMap attributes = new TreeMap<>();