Skip to content

Fix tests involving getBestDowngradeVersion #127646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 5, 2025
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
6 changes: 0 additions & 6 deletions muted-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,6 @@ tests:
issue: https://github.com/elastic/elasticsearch/issues/121165
- class: org.elasticsearch.xpack.security.authc.ldap.ActiveDirectorySessionFactoryTests
issue: https://github.com/elastic/elasticsearch/issues/121285
- class: org.elasticsearch.env.NodeEnvironmentTests
method: testGetBestDowngradeVersion
issue: https://github.com/elastic/elasticsearch/issues/121316
- class: org.elasticsearch.test.rest.yaml.CcsCommonYamlTestSuiteIT
issue: https://github.com/elastic/elasticsearch/issues/121407
- class: org.elasticsearch.analysis.common.CommonAnalysisClientYamlTestSuiteIT
Expand Down Expand Up @@ -234,9 +231,6 @@ tests:
- class: org.elasticsearch.smoketest.MlWithSecurityIT
method: test {yaml=ml/3rd_party_deployment/Test start and stop multiple deployments}
issue: https://github.com/elastic/elasticsearch/issues/124315
- class: org.elasticsearch.env.NodeEnvironmentTests
method: testIndexCompatibilityChecks
issue: https://github.com/elastic/elasticsearch/issues/124388
- class: org.elasticsearch.multiproject.test.CoreWithMultipleProjectsClientYamlTestSuiteIT
method: test {yaml=data_stream/190_failure_store_redirection/Redirect ingest failure in data stream to failure store}
issue: https://github.com/elastic/elasticsearch/issues/124518
Expand Down
11 changes: 8 additions & 3 deletions server/src/main/java/org/elasticsearch/env/NodeEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -1501,10 +1501,15 @@ private static void tryWriteTempFile(Path path) throws IOException {

/**
* Get a useful version string to direct a user's downgrade operation
* <p>
* Assuming that the index was compatible with {@code previousNodeVersion},
* the user should downgrade to that {@code previousNodeVersion},
* unless it's prior to the minimum compatible version,
* in which case the user should downgrade to that instead.
* (If the index version is so old that the minimum compatible version is incompatible with the index,
* then the cluster was already borked before the node upgrade began,
* and we can't probably help them without more info than we have here.)
*
* <p>If a user is trying to install current major N but has incompatible indices, the user should
* downgrade to last minor of the previous major (N-1).last. We return (N-1).last, unless the user is trying to upgrade from
* a (N-1).last.x release, in which case we return the last installed version.
* @return Version to downgrade to
*/
// visible for testing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.elasticsearch.test.MockLog;
import org.elasticsearch.test.NodeRoles;
import org.elasticsearch.test.junit.annotations.TestLogging;
import org.hamcrest.Matchers;
import org.junit.AssumptionViolatedException;

import java.io.IOException;
Expand Down Expand Up @@ -582,9 +581,9 @@ public void testIndexCompatibilityChecks() throws IOException {
containsString("it holds metadata for indices with version [" + oldIndexVersion.toReleaseVersion() + "]"),
containsString(
"Revert this node to version ["
+ (previousNodeVersion.major == Version.CURRENT.major
? Version.CURRENT.minimumCompatibilityVersion()
: previousNodeVersion)
+ (previousNodeVersion.onOrAfter(Version.CURRENT.minimumCompatibilityVersion())
? previousNodeVersion
: Version.CURRENT.minimumCompatibilityVersion())
+ "]"
)
)
Expand Down Expand Up @@ -639,29 +638,37 @@ public void testSymlinkDataDirectory() throws Exception {
}

public void testGetBestDowngradeVersion() {
assertThat(
NodeEnvironment.getBestDowngradeVersion(BuildVersion.fromString("8.18.0")),
Matchers.equalTo(BuildVersion.fromString("8.18.0"))
);
assertThat(
NodeEnvironment.getBestDowngradeVersion(BuildVersion.fromString("8.18.5")),
Matchers.equalTo(BuildVersion.fromString("8.18.5"))
);
assertThat(
NodeEnvironment.getBestDowngradeVersion(BuildVersion.fromString("8.18.12")),
Matchers.equalTo(BuildVersion.fromString("8.18.12"))
);
assertThat(
NodeEnvironment.getBestDowngradeVersion(BuildVersion.fromString("8.19.0")),
Matchers.equalTo(BuildVersion.fromString("8.19.0"))
int prev = Version.CURRENT.minimumCompatibilityVersion().major;
int last = Version.CURRENT.minimumCompatibilityVersion().minor;
int old = prev - 1;

assumeTrue("The current compatibility rules are active only from 8.x onward", prev >= 7);
assertEquals(Version.CURRENT.major - 1, prev);

assertEquals(
"From an old major, recommend prev.last",
NodeEnvironment.getBestDowngradeVersion(BuildVersion.fromString(old + ".0.0")),
BuildVersion.fromString(prev + "." + last + ".0")
);
assertThat(
NodeEnvironment.getBestDowngradeVersion(BuildVersion.fromString("8.17.0")),
Matchers.equalTo(BuildVersion.fromString("8.18.0"))

if (last >= 1) {
assertEquals(
"From an old minor of the previous major, recommend prev.last",
NodeEnvironment.getBestDowngradeVersion(BuildVersion.fromString(prev + "." + (last - 1) + ".0")),
BuildVersion.fromString(prev + "." + last + ".0")
);
}

assertEquals(
"From an old patch of prev.last, return that version itself",
NodeEnvironment.getBestDowngradeVersion(BuildVersion.fromString(prev + "." + last + ".1")),
BuildVersion.fromString(prev + "." + last + ".1")
);
assertThat(
NodeEnvironment.getBestDowngradeVersion(BuildVersion.fromString("7.17.0")),
Matchers.equalTo(BuildVersion.fromString("8.18.0"))

assertEquals(
"From the first version of this major, return that version itself",
NodeEnvironment.getBestDowngradeVersion(BuildVersion.fromString(Version.CURRENT.major + ".0.0")),
BuildVersion.fromString(Version.CURRENT.major + ".0.0")
);
}

Expand Down