Skip to content

Commit

Permalink
Don't just obfuscate NodeMetadata version checks
Browse files Browse the repository at this point in the history
  • Loading branch information
williamrandolph committed Oct 31, 2023
1 parent 7c77f51 commit 832226d
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 35 deletions.
18 changes: 1 addition & 17 deletions server/src/main/java/org/elasticsearch/env/NodeMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -222,20 +222,4 @@ public NodeMetadata fromXContent(XContentParser parser) throws IOException {

public static final MetadataStateFormat<NodeMetadata> 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);
}
}

}
18 changes: 0 additions & 18 deletions server/src/test/java/org/elasticsearch/env/NodeMetadataTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
}
Expand Down

0 comments on commit 832226d

Please sign in to comment.