Skip to content

Commit

Permalink
Fix up testIndexCompatibilityChecks a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
williamrandolph committed Feb 8, 2024
1 parent de15050 commit 70e62e9
Showing 1 changed file with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.lucene.util.SetOnce;
import org.elasticsearch.Build;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.Metadata;
Expand Down Expand Up @@ -585,7 +584,7 @@ public void testIndexCompatibilityChecks() throws IOException {
);
}

Version oldVersion = Version.fromId(between(1, Version.CURRENT.minimumCompatibilityVersion().id - 1));
IndexVersion oldVersionCheckpoint = IndexVersion.fromId(between(1, IndexVersions.V_7_17_0.id() - 1));
IndexVersion oldIndexVersion = IndexVersion.fromId(between(1, IndexVersions.MINIMUM_COMPATIBLE.id() - 1));
IndexVersion previousNodeVersion = IndexVersion.fromId(between(IndexVersions.V_7_17_0.id(), IndexVersion.current().id() - 1));
overrideOldestIndexVersion(oldIndexVersion, previousNodeVersion, env.nodeDataPaths());
Expand Down Expand Up @@ -614,21 +613,18 @@ public void testIndexCompatibilityChecks() throws IOException {
checkForIndexCompatibility(logger, env.dataPaths());

// Simulate empty old index version, attempting to upgrade before 7.17
removeOldestIndexVersion(oldVersion, env.nodeDataPaths());
removeOldestIndexVersion(oldVersionCheckpoint, env.nodeDataPaths());

ex = expectThrows(
IllegalStateException.class,
"Must fail the check on index that's too old",
() -> checkForIndexCompatibility(logger, env.dataPaths())
);

// TODO[wrb] replace range with "pre-7.x" or something
assertThat(
ex.getMessage(),
allOf(
startsWith(
"cannot upgrade a node from version [" + IndexVersion.fromId(oldVersion.id()).toReleaseVersion() + "] directly"
),
startsWith("cannot upgrade a node from version [" + oldVersionCheckpoint.toReleaseVersion() + "] directly"),
containsString("upgrade to version [" + Build.current().minWireCompatVersion())
)
);
Expand Down Expand Up @@ -763,7 +759,7 @@ private static void overrideOldestIndexVersion(IndexVersion oldestIndexVersion,
}
}

private static void removeOldestIndexVersion(Version oldVersion, Path... dataPaths) throws IOException {
private static void removeOldestIndexVersion(IndexVersion oldVersionCheckpoint, Path... dataPaths) throws IOException {
for (final Path dataPath : dataPaths) {
final Path indexPath = dataPath.resolve(METADATA_DIRECTORY_NAME);
if (Files.exists(indexPath)) {
Expand All @@ -778,7 +774,7 @@ private static void removeOldestIndexVersion(Version oldVersion, Path... dataPat
)
) {
final Map<String, String> commitData = new HashMap<>(userData);
commitData.put(NODE_VERSION_KEY, Integer.toString(oldVersion.id));
commitData.put(NODE_VERSION_KEY, Integer.toString(oldVersionCheckpoint.id()));
commitData.remove(OLDEST_INDEX_VERSION_KEY);
indexWriter.setLiveCommitData(commitData.entrySet());
indexWriter.commit();
Expand Down

0 comments on commit 70e62e9

Please sign in to comment.