Skip to content

Commit cd73065

Browse files
committed
Fix tests involving getBestDowngradeVersion
1 parent d546fc8 commit cd73065

File tree

3 files changed

+41
-33
lines changed

3 files changed

+41
-33
lines changed

muted-tests.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,6 @@ tests:
185185
issue: https://github.com/elastic/elasticsearch/issues/121165
186186
- class: org.elasticsearch.xpack.security.authc.ldap.ActiveDirectorySessionFactoryTests
187187
issue: https://github.com/elastic/elasticsearch/issues/121285
188-
- class: org.elasticsearch.env.NodeEnvironmentTests
189-
method: testGetBestDowngradeVersion
190-
issue: https://github.com/elastic/elasticsearch/issues/121316
191188
- class: org.elasticsearch.test.rest.yaml.CcsCommonYamlTestSuiteIT
192189
issue: https://github.com/elastic/elasticsearch/issues/121407
193190
- class: org.elasticsearch.analysis.common.CommonAnalysisClientYamlTestSuiteIT
@@ -234,9 +231,6 @@ tests:
234231
- class: org.elasticsearch.smoketest.MlWithSecurityIT
235232
method: test {yaml=ml/3rd_party_deployment/Test start and stop multiple deployments}
236233
issue: https://github.com/elastic/elasticsearch/issues/124315
237-
- class: org.elasticsearch.env.NodeEnvironmentTests
238-
method: testIndexCompatibilityChecks
239-
issue: https://github.com/elastic/elasticsearch/issues/124388
240234
- class: org.elasticsearch.multiproject.test.CoreWithMultipleProjectsClientYamlTestSuiteIT
241235
method: test {yaml=data_stream/190_failure_store_redirection/Redirect ingest failure in data stream to failure store}
242236
issue: https://github.com/elastic/elasticsearch/issues/124518

server/src/main/java/org/elasticsearch/env/NodeEnvironment.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.lucene.store.NativeFSLockFactory;
2424
import org.elasticsearch.Build;
2525
import org.elasticsearch.ElasticsearchException;
26+
import org.elasticsearch.Version;
2627
import org.elasticsearch.cluster.metadata.IndexMetadata;
2728
import org.elasticsearch.cluster.node.DiscoveryNode;
2829
import org.elasticsearch.cluster.node.DiscoveryNodeRole;
@@ -1501,10 +1502,15 @@ private static void tryWriteTempFile(Path path) throws IOException {
15011502

15021503
/**
15031504
* Get a useful version string to direct a user's downgrade operation
1505+
* <p>
1506+
* Assuming that the index was compatible with {@code previousNodeVersion},
1507+
* the user should downgrade to that {@code previousNodeVersion},
1508+
* unless it's prior to the minimum compatible version,
1509+
* in which case the user should downgrade to that instead.
1510+
* (If the index version is so old that the minimum compatible version is incompatible with the index,
1511+
* then the cluster was already borked before the node upgrade began,
1512+
* and we can't probably help them without more info than we have here.)
15041513
*
1505-
* <p>If a user is trying to install current major N but has incompatible indices, the user should
1506-
* downgrade to last minor of the previous major (N-1).last. We return (N-1).last, unless the user is trying to upgrade from
1507-
* a (N-1).last.x release, in which case we return the last installed version.
15081514
* @return Version to downgrade to
15091515
*/
15101516
// visible for testing

server/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -582,9 +582,9 @@ public void testIndexCompatibilityChecks() throws IOException {
582582
containsString("it holds metadata for indices with version [" + oldIndexVersion.toReleaseVersion() + "]"),
583583
containsString(
584584
"Revert this node to version ["
585-
+ (previousNodeVersion.major == Version.CURRENT.major
586-
? Version.CURRENT.minimumCompatibilityVersion()
587-
: previousNodeVersion)
585+
+ (previousNodeVersion.onOrAfter(Version.CURRENT.minimumCompatibilityVersion())
586+
? previousNodeVersion
587+
: Version.CURRENT.minimumCompatibilityVersion())
588588
+ "]"
589589
)
590590
)
@@ -639,29 +639,37 @@ public void testSymlinkDataDirectory() throws Exception {
639639
}
640640

641641
public void testGetBestDowngradeVersion() {
642-
assertThat(
643-
NodeEnvironment.getBestDowngradeVersion(BuildVersion.fromString("8.18.0")),
644-
Matchers.equalTo(BuildVersion.fromString("8.18.0"))
645-
);
646-
assertThat(
647-
NodeEnvironment.getBestDowngradeVersion(BuildVersion.fromString("8.18.5")),
648-
Matchers.equalTo(BuildVersion.fromString("8.18.5"))
649-
);
650-
assertThat(
651-
NodeEnvironment.getBestDowngradeVersion(BuildVersion.fromString("8.18.12")),
652-
Matchers.equalTo(BuildVersion.fromString("8.18.12"))
653-
);
654-
assertThat(
655-
NodeEnvironment.getBestDowngradeVersion(BuildVersion.fromString("8.19.0")),
656-
Matchers.equalTo(BuildVersion.fromString("8.19.0"))
642+
int prev = Version.CURRENT.minimumCompatibilityVersion().major;
643+
int last = Version.CURRENT.minimumCompatibilityVersion().minor;
644+
int old = prev-1;
645+
646+
assumeTrue("The current compatibility rules are active only from 9.x onward", prev >= 7);
647+
assertEquals(Version.CURRENT.major-1, prev);
648+
649+
assertEquals(
650+
"From an old major, recommend prev.last",
651+
NodeEnvironment.getBestDowngradeVersion(BuildVersion.fromString(old + ".0.0")),
652+
BuildVersion.fromString(prev + "." + last + ".0")
657653
);
658-
assertThat(
659-
NodeEnvironment.getBestDowngradeVersion(BuildVersion.fromString("8.17.0")),
660-
Matchers.equalTo(BuildVersion.fromString("8.18.0"))
654+
655+
if (last >= 1) {
656+
assertEquals(
657+
"From an old minor of the previous major, recommend prev.last",
658+
NodeEnvironment.getBestDowngradeVersion(BuildVersion.fromString(prev + "." + (last - 1) + ".0")),
659+
BuildVersion.fromString(prev + "." + last + ".0")
660+
);
661+
}
662+
663+
assertEquals(
664+
"From an old patch of prev.last, return that version itself",
665+
NodeEnvironment.getBestDowngradeVersion(BuildVersion.fromString(prev + "." + last + ".1")),
666+
BuildVersion.fromString(prev + "." + last + ".1")
661667
);
662-
assertThat(
663-
NodeEnvironment.getBestDowngradeVersion(BuildVersion.fromString("7.17.0")),
664-
Matchers.equalTo(BuildVersion.fromString("8.18.0"))
668+
669+
assertEquals(
670+
"From the first version of this major, return that version itself",
671+
NodeEnvironment.getBestDowngradeVersion(BuildVersion.fromString(Version.CURRENT.major + ".0.0")),
672+
BuildVersion.fromString(Version.CURRENT.major + ".0.0")
665673
);
666674
}
667675

0 commit comments

Comments
 (0)