瀏覽代碼

Bump to first non-release IndexVersion (#98478)

This bumps to an IndexVersion that is not associated with any specific release version. From this point, index metadata/data versioning will be handled in the same way as TransportVersion - a new constant for every change
Simon Cooper 2 年之前
父節點
當前提交
bebe2538b1

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

@@ -433,12 +433,12 @@ public class FullClusterRestartIT extends ParameterizedFullClusterRestartTestCas
             clusterState
         );
         assertEquals("0", numberOfReplicas);
-        Version version = Version.fromId(
+        IndexVersion version = IndexVersion.fromId(
             Integer.valueOf(
                 (String) XContentMapValues.extractValue("metadata.indices." + index + ".settings.index.version.created", clusterState)
             )
         );
-        assertEquals(getOldClusterVersion(), version);
+        assertEquals(getOldClusterIndexVersion(), version);
 
     }
 

+ 13 - 0
qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/AbstractRollingTestCase.java

@@ -9,8 +9,11 @@ package org.elasticsearch.upgrades;
 
 import org.elasticsearch.Version;
 import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.index.IndexVersion;
 import org.elasticsearch.test.rest.ESRestTestCase;
 
+import static org.hamcrest.Matchers.lessThan;
+
 public abstract class AbstractRollingTestCase extends ESRestTestCase {
     protected enum ClusterType {
         OLD,
@@ -31,6 +34,16 @@ public abstract class AbstractRollingTestCase extends ESRestTestCase {
     protected static final boolean FIRST_MIXED_ROUND = Boolean.parseBoolean(System.getProperty("tests.first_round", "false"));
     protected static final Version UPGRADE_FROM_VERSION = Version.fromString(System.getProperty("tests.upgrade_from_version"));
 
+    protected static IndexVersion getOldClusterIndexVersion() {
+        var version = UPGRADE_FROM_VERSION;
+        if (version.equals(org.elasticsearch.Version.CURRENT)) {
+            return IndexVersion.current();
+        } else {
+            assertThat("Index version needs to be added to rolling test parameters", version, lessThan(org.elasticsearch.Version.V_8_11_0));
+            return IndexVersion.fromId(version.id);
+        }
+    }
+
     @Override
     protected final boolean resetFeatureStates() {
         return false;

+ 1 - 1
qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/FeatureUpgradeIT.java

@@ -94,7 +94,7 @@ public class FeatureUpgradeIT extends AbstractRollingTestCase {
                     .orElse(Collections.emptyMap());
 
                 assertThat(feature, aMapWithSize(4));
-                assertThat(feature.get("minimum_index_version"), equalTo(Integer.toString(UPGRADE_FROM_VERSION.id)));
+                assertThat(feature.get("minimum_index_version"), equalTo(getOldClusterIndexVersion().toString()));
                 if (UPGRADE_FROM_VERSION.before(TransportGetFeatureUpgradeStatusAction.NO_UPGRADE_REQUIRED_VERSION)) {
                     assertThat(feature.get("migration_status"), equalTo("MIGRATION_NEEDED"));
                 } else {

+ 1 - 1
server/src/main/java/org/elasticsearch/TransportVersion.java

@@ -119,7 +119,7 @@ public record TransportVersion(int id) implements VersionId<TransportVersion> {
     public static final TransportVersion V_8_8_1 = registerTransportVersion(8_08_01_99, "291c71bb-5b0a-4b7e-a407-6e53bc128d0f");
 
     /*
-     * READ THE COMMENT BELOW THiS BLOCK OF DECLARATIONS BEFORE ADDING NEW TRANSPORT VERSIONS
+     * READ THE COMMENT BELOW THIS BLOCK OF DECLARATIONS BEFORE ADDING NEW TRANSPORT VERSIONS
      * Detached transport versions added below here.
      */
     public static final TransportVersion V_8_500_010 = registerTransportVersion(8_500_010, "9818C628-1EEC-439B-B943-468F61460675");

+ 28 - 5
server/src/main/java/org/elasticsearch/index/IndexVersion.java

@@ -18,8 +18,6 @@ import org.elasticsearch.internal.VersionExtension;
 import org.elasticsearch.xcontent.ToXContentFragment;
 import org.elasticsearch.xcontent.XContentBuilder;
 
-import java.io.IOException;
-
 import java.io.IOException;
 import java.lang.reflect.Field;
 import java.util.Collection;
@@ -67,8 +65,9 @@ public record IndexVersion(int id, Version luceneVersion) implements VersionId<I
     /*
      * NOTE: IntelliJ lies!
      * This map is used during class construction, referenced by the registerIndexVersion method.
-     * When all the transport version constants have been registered, the map is cleared & never touched again.
+     * When all the index version constants have been registered, the map is cleared & never touched again.
      */
+    @SuppressWarnings("UnusedAssignment")
     private static Map<String, Integer> IDS = new HashMap<>();
 
     private static IndexVersion registerIndexVersion(int id, Version luceneVersion, String uniqueId) {
@@ -117,12 +116,36 @@ public record IndexVersion(int id, Version luceneVersion) implements VersionId<I
     public static final IndexVersion V_8_9_1 = registerIndexVersion(8_09_01_99, Version.LUCENE_9_7_0, "955a80ac-f70c-40a5-9399-1d8a1e5d342d");
     public static final IndexVersion V_8_10_0 = registerIndexVersion(8_10_00_99, Version.LUCENE_9_7_0, "2e107286-12ad-4c51-9a6f-f8943663b6e7");
     public static final IndexVersion V_8_11_0 = registerIndexVersion(8_11_00_99, Version.LUCENE_9_7_0, "f08382c0-06ab-41f4-a56a-cf5397275627");
+
     /*
-     * READ THE JAVADOC ABOVE BEFORE ADDING NEW INDEX VERSIONS
+     * READ THE COMMENT BELOW THIS BLOCK OF DECLARATIONS BEFORE ADDING NEW INDEX VERSIONS
      * Detached index versions added below here.
      */
+    public static final IndexVersion V_8_500_000 = registerIndexVersion(8_500_000, Version.LUCENE_9_7_0, "bf656f5e-5808-4eee-bf8a-e2bf6736ff55");
+
+    /*
+     * STOP! READ THIS FIRST! No, really,
+     *        ____ _____ ___  ____  _        ____  _____    _    ____    _____ _   _ ___ ____    _____ ___ ____  ____ _____ _
+     *       / ___|_   _/ _ \|  _ \| |      |  _ \| ____|  / \  |  _ \  |_   _| | | |_ _/ ___|  |  ___|_ _|  _ \/ ___|_   _| |
+     *       \___ \ | || | | | |_) | |      | |_) |  _|   / _ \ | | | |   | | | |_| || |\___ \  | |_   | || |_) \___ \ | | | |
+     *        ___) || || |_| |  __/|_|      |  _ <| |___ / ___ \| |_| |   | | |  _  || | ___) | |  _|  | ||  _ < ___) || | |_|
+     *       |____/ |_| \___/|_|   (_)      |_| \_\_____/_/   \_\____/    |_| |_| |_|___|____/  |_|   |___|_| \_\____/ |_| (_)
+     *
+     * A new index version should be added EVERY TIME a change is made to index metadata or data storage.
+     * Each index version should only be used in a single merged commit (apart from the BwC versions copied from o.e.Version, ≤V_8_11_0).
+     *
+     * To add a new index version, add a new constant at the bottom of the list, above this comment, which is one greater than the
+     * current highest version, ensure it has a fresh UUID, and update CurrentHolder#CURRENT to point to the new version. Don't add other
+     * lines, comments, etc.
+     *
+     * REVERTING AN INDEX VERSION
+     *
+     * If you revert a commit with an index version change, you MUST ensure there is a NEW index version representing the reverted
+     * change. DO NOT let the index version go backwards, it must ALWAYS be incremented.
+     */
+
     private static class CurrentHolder {
-        private static final IndexVersion CURRENT = findCurrent(V_8_11_0);
+        private static final IndexVersion CURRENT = findCurrent(V_8_500_000);
 
         // finds the pluggable current version, or uses the given fallback
         private static IndexVersion findCurrent(IndexVersion fallback) {

+ 1 - 1
server/src/test/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteResponseTests.java

@@ -199,7 +199,7 @@ public class ClusterRerouteResponseTests extends ESTestCase {
                 Version.CURRENT,
                 IndexVersion.MINIMUM_COMPATIBLE,
                 IndexVersion.current(),
-                Version.CURRENT.id
+                IndexVersion.current()
             ),
             """
                 The [state] field in the response to the reroute API is deprecated and will be removed in a future version. \

+ 1 - 1
server/src/test/java/org/elasticsearch/cluster/ClusterStateTests.java

@@ -989,7 +989,7 @@ public class ClusterStateTests extends ESTestCase {
                 "unassigned" : [ ],
                 "nodes" : { }
               }
-            }""", Version.CURRENT.id), Strings.toString(builder));
+            }""", IndexVersion.current()), Strings.toString(builder));
     }
 
     private ClusterState buildClusterState() throws IOException {

+ 6 - 7
server/src/test/java/org/elasticsearch/cluster/metadata/ToAndFromJsonMetadataTests.java

@@ -9,7 +9,6 @@
 package org.elasticsearch.cluster.metadata;
 
 import org.elasticsearch.TransportVersion;
-import org.elasticsearch.Version;
 import org.elasticsearch.action.admin.indices.rollover.RolloverInfo;
 import org.elasticsearch.cluster.coordination.CoordinationMetadata;
 import org.elasticsearch.common.Strings;
@@ -275,7 +274,7 @@ public class ToAndFromJsonMetadataTests extends ESTestCase {
                 },
                 "reserved_state" : { }
               }
-            }""", Version.CURRENT.id, Version.CURRENT.id), Strings.toString(builder));
+            }""", IndexVersion.current(), IndexVersion.current()), Strings.toString(builder));
     }
 
     public void testToXContentAPI_SameTypeName() throws IOException {
@@ -371,7 +370,7 @@ public class ToAndFromJsonMetadataTests extends ESTestCase {
                 },
                 "reserved_state" : { }
               }
-            }""", Version.CURRENT.id), Strings.toString(builder));
+            }""", IndexVersion.current()), Strings.toString(builder));
     }
 
     public void testToXContentGateway_FlatSettingFalse_ReduceMappingTrue() throws IOException {
@@ -436,7 +435,7 @@ public class ToAndFromJsonMetadataTests extends ESTestCase {
                 },
                 "reserved_state" : { }
               }
-            }""", Version.CURRENT.id, Version.CURRENT.id), Strings.toString(builder));
+            }""", IndexVersion.current(), IndexVersion.current()), Strings.toString(builder));
     }
 
     public void testToXContentAPI_FlatSettingTrue_ReduceMappingFalse() throws IOException {
@@ -539,7 +538,7 @@ public class ToAndFromJsonMetadataTests extends ESTestCase {
                 },
                 "reserved_state" : { }
               }
-            }""", Version.CURRENT.id, Version.CURRENT.id), Strings.toString(builder));
+            }""", IndexVersion.current(), IndexVersion.current()), Strings.toString(builder));
     }
 
     public void testToXContentAPI_FlatSettingFalse_ReduceMappingTrue() throws IOException {
@@ -648,7 +647,7 @@ public class ToAndFromJsonMetadataTests extends ESTestCase {
                 },
                 "reserved_state" : { }
               }
-            }""", Version.CURRENT.id, Version.CURRENT.id), Strings.toString(builder));
+            }""", IndexVersion.current(), IndexVersion.current()), Strings.toString(builder));
     }
 
     public void testToXContentAPIReservedMetadata() throws IOException {
@@ -828,7 +827,7 @@ public class ToAndFromJsonMetadataTests extends ESTestCase {
                   }
                 }
               }
-            }""", Version.CURRENT.id, Version.CURRENT.id), Strings.toString(builder));
+            }""", IndexVersion.current(), IndexVersion.current()), Strings.toString(builder));
     }
 
     private Metadata buildMetadata() throws IOException {