From 832226d2cffd66599542dabdd092da345691336e Mon Sep 17 00:00:00 2001 From: William Brafford Date: Tue, 31 Oct 2023 12:25:50 -0400 Subject: [PATCH] Don't just obfuscate NodeMetadata version checks --- .../org/elasticsearch/env/NodeMetadata.java | 18 +----------------- .../elasticsearch/env/NodeMetadataTests.java | 18 ------------------ 2 files changed, 1 insertion(+), 35 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/env/NodeMetadata.java b/server/src/main/java/org/elasticsearch/env/NodeMetadata.java index a714ee4cf5ec0..77415bbaea949 100644 --- a/server/src/main/java/org/elasticsearch/env/NodeMetadata.java +++ b/server/src/main/java/org/elasticsearch/env/NodeMetadata.java @@ -114,7 +114,7 @@ public void verifyUpgradeToCurrentVersion() { assert (nodeVersion.equals(Version.V_EMPTY) == false) || (Version.CURRENT.major <= Version.V_7_0_0.major + 1) : "version is required in the node metadata from v9 onwards"; - if (NodeMetadata.isNodeVersionWireCompatible(nodeVersion.toString()) == false) { + if (nodeVersion.before(Version.CURRENT.minimumCompatibilityVersion())) { throw new IllegalStateException( "cannot upgrade a node from version [" + nodeVersion @@ -222,20 +222,4 @@ public NodeMetadata fromXContent(XContentParser parser) throws IOException { public static final MetadataStateFormat FORMAT = new NodeMetadataStateFormat(false); - /** - * Check whether a node version is compatible with the current minimum transport version. - * @param version A version identifier as a string - * @throws IllegalArgumentException if version is not a valid transport version identifier - * @return true if the version is compatible, false otherwise - */ - // visible for testing - static boolean isNodeVersionWireCompatible(String version) { - try { - Version esVersion = Version.fromString(version); - return esVersion.onOrAfter(Version.CURRENT.minimumCompatibilityVersion()); - } catch (IllegalArgumentException e) { - throw new IllegalArgumentException("Cannot parse [" + version + "] as a transport version identifier", e); - } - } - } diff --git a/server/src/test/java/org/elasticsearch/env/NodeMetadataTests.java b/server/src/test/java/org/elasticsearch/env/NodeMetadataTests.java index fc89e4d2176c1..b7001943073bc 100644 --- a/server/src/test/java/org/elasticsearch/env/NodeMetadataTests.java +++ b/server/src/test/java/org/elasticsearch/env/NodeMetadataTests.java @@ -15,7 +15,6 @@ import org.elasticsearch.index.IndexVersions; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.EqualsHashCodeTestUtils; -import org.elasticsearch.test.TransportVersionUtils; import org.elasticsearch.test.VersionUtils; import org.elasticsearch.test.index.IndexVersionUtils; @@ -160,23 +159,6 @@ public void testUpgradeMarksPreviousVersion() { assertThat(nodeMetadata.previousNodeVersion(), equalTo(version)); } - public void testIsNodeVersionWireCompatible() { - String nodeVersion = VersionUtils.randomCompatibleVersion(random(), Version.CURRENT).toString(); - assertTrue(NodeMetadata.isNodeVersionWireCompatible(nodeVersion)); - nodeVersion = VersionUtils.getPreviousVersion(Version.CURRENT.minimumCompatibilityVersion()).toString(); - assertFalse(NodeMetadata.isNodeVersionWireCompatible(nodeVersion)); - - String transportVersion = TransportVersionUtils.randomCompatibleVersion(random()).toString(); - IllegalArgumentException e1 = expectThrows( - IllegalArgumentException.class, - () -> NodeMetadata.isNodeVersionWireCompatible(transportVersion) - ); - assertThat(e1.getMessage(), equalTo("Cannot parse [" + transportVersion + "] as a transport version identifier")); - - IllegalArgumentException e2 = expectThrows(IllegalArgumentException.class, () -> NodeMetadata.isNodeVersionWireCompatible("x.y.z")); - assertThat(e2.getMessage(), equalTo("Cannot parse [x.y.z] as a transport version identifier")); - } - public static Version tooNewVersion() { return Version.fromId(between(Version.CURRENT.id + 1, 99999999)); }