Browse Source

Migrate some full-cluster restart tests to use IndexVersion (#97368)

This infers the index version from the specified node version. Note that this will break when 8.10 is released, and BwC tests try to use 8.10 nodes. #97200 should be implemented before 8.10 is released to properly specify IndexVersion, without requiring inference.
Simon Cooper 2 years ago
parent
commit
52a6820813

+ 16 - 12
qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/upgrades/FullClusterRestartIT.java

@@ -961,9 +961,10 @@ public class FullClusterRestartIT extends ParameterizedFullClusterRestartTestCas
             assertTrue("expected to find a primary but didn't\n" + recoveryResponse, foundPrimary);
             assertEquals("mismatch while checking for translog recovery\n" + recoveryResponse, shouldHaveTranslog, restoredFromTranslog);
 
-            String currentLuceneVersion = IndexVersion.current().luceneVersion().toString();
-            String bwcLuceneVersion = getOldClusterVersion().luceneVersion().toString();
-            String minCompatibleBWCVersion = Version.CURRENT.minimumCompatibilityVersion().luceneVersion().toString();
+            var luceneVersion = IndexVersion.current().luceneVersion();
+            String currentLuceneVersion = luceneVersion.toString();
+            int currentLuceneVersionMajor = luceneVersion.major;
+            String bwcLuceneVersion = getOldClusterIndexVersion().luceneVersion().toString();
             if (shouldHaveTranslog && false == currentLuceneVersion.equals(bwcLuceneVersion)) {
                 int numCurrentVersion = 0;
                 int numBwcVersion = 0;
@@ -975,19 +976,22 @@ public class FullClusterRestartIT extends ParameterizedFullClusterRestartTestCas
                     if (false == line.startsWith("p")) {
                         continue;
                     }
-                    Matcher m = Pattern.compile("(\\d+\\.\\d+\\.\\d+)$").matcher(line);
+                    Matcher m = Pattern.compile("((\\d+)\\.\\d+\\.\\d+)$").matcher(line);
                     assertTrue(line, m.find());
                     String version = m.group(1);
+                    int major = Integer.parseInt(m.group(2));
                     if (currentLuceneVersion.equals(version)) {
                         numCurrentVersion++;
                     } else if (bwcLuceneVersion.equals(version)) {
                         numBwcVersion++;
-                    } else if (minCompatibleBWCVersion.equals(version) && minCompatibleBWCVersion.equals(bwcLuceneVersion) == false) {
-                        // Our upgrade path from 7.non-last always goes through 7.last, which depending on timing can create 7.last
-                        // index segment. We ignore those.
+                    } else if (major == currentLuceneVersionMajor - 1) {
+                        // we can read one lucene version back. The upgrade path might have created old segment versions.
+                        // that's ok, we just ignore them
                         continue;
                     } else {
-                        fail("expected version to be one of [" + currentLuceneVersion + "," + bwcLuceneVersion + "] but was " + line);
+                        fail(
+                            "expected lucene version to be one of [" + currentLuceneVersion + "," + bwcLuceneVersion + "] but was " + line
+                        );
                     }
                 }
                 assertNotEquals(
@@ -1106,9 +1110,9 @@ public class FullClusterRestartIT extends ParameterizedFullClusterRestartTestCas
         createSnapshot.setJsonEntity("{\"indices\": \"" + index + "\"}");
         client().performRequest(createSnapshot);
 
-        checkSnapshot("old_snap", count, getOldClusterVersion());
+        checkSnapshot("old_snap", count, getOldClusterVersion(), getOldClusterIndexVersion());
         if (false == isRunningAgainstOldCluster()) {
-            checkSnapshot("new_snap", count, Version.CURRENT);
+            checkSnapshot("new_snap", count, Version.CURRENT, IndexVersion.current());
         }
     }
 
@@ -1298,7 +1302,7 @@ public class FullClusterRestartIT extends ParameterizedFullClusterRestartTestCas
     }
 
     @SuppressWarnings("unchecked")
-    private void checkSnapshot(final String snapshotName, final int count, final Version tookOnVersion) throws IOException {
+    private void checkSnapshot(String snapshotName, int count, Version tookOnVersion, IndexVersion tookOnIndexVersion) throws IOException {
         // Check the snapshot metadata, especially the version
         Request listSnapshotRequest = new Request("GET", "/_snapshot/repo/" + snapshotName);
         Map<String, Object> snapResponse = entityAsMap(client().performRequest(listSnapshotRequest));
@@ -1308,7 +1312,7 @@ public class FullClusterRestartIT extends ParameterizedFullClusterRestartTestCas
         // the format can change depending on the ES node version running & this test code running
         assertThat(
             XContentMapValues.extractValue("snapshots.version", snapResponse),
-            either(Matchers.<Object>equalTo(List.of(tookOnVersion.toString()))).or(equalTo(List.of(tookOnVersion.indexVersion.toString())))
+            either(Matchers.<Object>equalTo(List.of(tookOnVersion.toString()))).or(equalTo(List.of(tookOnIndexVersion.toString())))
         );
 
         // Remove the routing setting and template so we can test restoring them.

+ 12 - 0
qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/upgrades/ParameterizedFullClusterRestartTestCase.java

@@ -12,6 +12,7 @@ import com.carrotsearch.randomizedtesting.annotations.Name;
 import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
 import com.carrotsearch.randomizedtesting.annotations.TestCaseOrdering;
 
+import org.elasticsearch.index.IndexVersion;
 import org.elasticsearch.test.cluster.ElasticsearchCluster;
 import org.elasticsearch.test.cluster.util.Version;
 import org.elasticsearch.test.rest.ESRestTestCase;
@@ -23,6 +24,7 @@ import java.util.Locale;
 
 import static org.elasticsearch.upgrades.FullClusterRestartUpgradeStatus.OLD;
 import static org.elasticsearch.upgrades.FullClusterRestartUpgradeStatus.UPGRADED;
+import static org.hamcrest.Matchers.lessThan;
 
 @TestCaseOrdering(FullClusterRestartTestOrdering.class)
 public abstract class ParameterizedFullClusterRestartTestCase extends ESRestTestCase {
@@ -78,6 +80,16 @@ public abstract class ParameterizedFullClusterRestartTestCase extends ESRestTest
         return org.elasticsearch.Version.fromString(OLD_CLUSTER_VERSION.toString());
     }
 
+    public static IndexVersion getOldClusterIndexVersion() {
+        var version = getOldClusterVersion();
+        if (version.equals(org.elasticsearch.Version.CURRENT)) {
+            return IndexVersion.current();
+        } else {
+            assertThat("Index version needs to be added to restart test parameters", version, lessThan(org.elasticsearch.Version.V_8_10_0));
+            return IndexVersion.fromId(version.id);
+        }
+    }
+
     public static Version getOldClusterTestVersion() {
         return Version.fromString(OLD_CLUSTER_VERSION.toString());
     }

+ 20 - 3
x-pack/qa/repository-old-versions/src/test/java/org/elasticsearch/oldrepos/OldRepositoryAccessIT.java

@@ -28,6 +28,7 @@ import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.common.util.concurrent.ThreadContext;
 import org.elasticsearch.core.Booleans;
 import org.elasticsearch.core.PathUtils;
+import org.elasticsearch.index.IndexVersion;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.elasticsearch.search.SearchHit;
 import org.elasticsearch.search.builder.SearchSourceBuilder;
@@ -57,6 +58,7 @@ import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.greaterThan;
 import static org.hamcrest.Matchers.hasKey;
 import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.lessThan;
 import static org.hamcrest.Matchers.not;
 import static org.hamcrest.Matchers.startsWith;
 
@@ -98,6 +100,9 @@ public class OldRepositoryAccessIT extends ESRestTestCase {
             sourceOnlyRepository == false || oldVersion.onOrAfter(Version.fromString("6.5.0"))
         );
 
+        assertThat("Index version should be added to archive tests", oldVersion, lessThan(Version.V_8_10_0));
+        IndexVersion indexVersion = IndexVersion.fromId(oldVersion.id);
+
         int oldEsPort = Integer.parseInt(System.getProperty("tests.es.port"));
         String indexName;
         if (sourceOnlyRepository) {
@@ -113,7 +118,18 @@ public class OldRepositoryAccessIT extends ESRestTestCase {
             RestClient oldEs = RestClient.builder(new HttpHost("127.0.0.1", oldEsPort)).build()
         ) {
             if (afterRestart == false) {
-                beforeRestart(sourceOnlyRepository, repoLocation, oldVersion, numDocs, extraDocs, expectedIds, client, oldEs, indexName);
+                beforeRestart(
+                    sourceOnlyRepository,
+                    repoLocation,
+                    oldVersion,
+                    indexVersion,
+                    numDocs,
+                    extraDocs,
+                    expectedIds,
+                    client,
+                    oldEs,
+                    indexName
+                );
             } else {
                 afterRestart(indexName);
             }
@@ -131,6 +147,7 @@ public class OldRepositoryAccessIT extends ESRestTestCase {
         boolean sourceOnlyRepository,
         String repoLocation,
         Version oldVersion,
+        IndexVersion indexVersion,
         int numDocs,
         int extraDocs,
         Set<String> expectedIds,
@@ -213,7 +230,7 @@ public class OldRepositoryAccessIT extends ESRestTestCase {
         assertEquals(numberOfShards, (int) getResp.evaluate("snapshots.0.shards.successful"));
         assertEquals(numberOfShards, (int) getResp.evaluate("snapshots.0.shards.total"));
         assertEquals(0, (int) getResp.evaluate("snapshots.0.shards.failed"));
-        assertEquals(oldVersion.indexVersion.toString(), getResp.evaluate("snapshots.0.version"));
+        assertEquals(indexVersion.toString(), getResp.evaluate("snapshots.0.version"));
 
         // list specific snapshot on new ES
         getSnaps = new Request("GET", "/_snapshot/" + repoName + "/" + snapshotName);
@@ -227,7 +244,7 @@ public class OldRepositoryAccessIT extends ESRestTestCase {
         assertEquals(numberOfShards, (int) getResp.evaluate("snapshots.0.shards.successful"));
         assertEquals(numberOfShards, (int) getResp.evaluate("snapshots.0.shards.total"));
         assertEquals(0, (int) getResp.evaluate("snapshots.0.shards.failed"));
-        assertEquals(oldVersion.indexVersion.toString(), getResp.evaluate("snapshots.0.version"));
+        assertEquals(indexVersion.toString(), getResp.evaluate("snapshots.0.version"));
 
         // list advanced snapshot info on new ES
         getSnaps = new Request("GET", "/_snapshot/" + repoName + "/" + snapshotName + "/_status");