From 0f1af2562733186a8d957f141716d124de11e91a Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Tue, 28 Mar 2023 13:51:17 +0100 Subject: [PATCH 01/20] Introduce IndexFormatVersion class --- .../admin/indices/create/SplitIndexIT.java | 3 +- .../org/elasticsearch/TransportVersion.java | 2 +- .../cluster/metadata/IndexMetadata.java | 44 +++--- .../metadata/MetadataCreateIndexService.java | 13 +- .../common/settings/IndexScopedSettings.java | 8 +- .../index/IndexFormatVersion.java | 139 ++++++++++++++++++ .../elasticsearch/index/IndexSettings.java | 12 +- .../MetadataCreateIndexServiceTests.java | 17 ++- 8 files changed, 192 insertions(+), 46 deletions(-) create mode 100644 server/src/main/java/org/elasticsearch/index/IndexFormatVersion.java diff --git a/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/create/SplitIndexIT.java b/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/create/SplitIndexIT.java index 722f05661b2f7..f468b065fe6af 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/create/SplitIndexIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/create/SplitIndexIT.java @@ -37,6 +37,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.core.TimeValue; import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexFormatVersion; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.engine.SegmentsStats; import org.elasticsearch.index.query.TermsQueryBuilder; @@ -109,7 +110,7 @@ private void splitToN(int sourceShards, int firstSplitShards, int secondSplitSha useRoutingPartition = randomBoolean(); } if (useRouting && useMixedRouting == false && useRoutingPartition) { - int numRoutingShards = MetadataCreateIndexService.calculateNumRoutingShards(secondSplitShards, Version.CURRENT) - 1; + int numRoutingShards = MetadataCreateIndexService.calculateNumRoutingShards(secondSplitShards, IndexFormatVersion.CURRENT) - 1; settings.put("index.routing_partition_size", randomIntBetween(1, numRoutingShards)); if (useNested) { createInitialIndex.setMapping("_routing", "required=true", "nested1", "type=nested"); diff --git a/server/src/main/java/org/elasticsearch/TransportVersion.java b/server/src/main/java/org/elasticsearch/TransportVersion.java index d2b10a9838cb4..5faa18bb5f9c5 100644 --- a/server/src/main/java/org/elasticsearch/TransportVersion.java +++ b/server/src/main/java/org/elasticsearch/TransportVersion.java @@ -182,7 +182,7 @@ static NavigableMap getAllVersionIds(Class cls) { + sameUniqueId + " have the same unique id. Each TransportVersion should have a different unique id"; } catch (IllegalAccessException e) { - assert false : "Version field [" + fieldName + "] should be public"; + assert false : "TransportVersion field [" + fieldName + "] should be public"; } } } diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java index 436470b3ebda1..d7769d9810ba2 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java @@ -41,6 +41,7 @@ import org.elasticsearch.core.Nullable; import org.elasticsearch.gateway.MetadataStateFormat; import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexFormatVersion; import org.elasticsearch.index.IndexMode; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.mapper.MapperService; @@ -337,9 +338,10 @@ public static APIBlock readFrom(StreamInput input) throws IOException { public static final String SETTING_VERSION_CREATED = "index.version.created"; - public static final Setting SETTING_INDEX_VERSION_CREATED = Setting.versionSetting( + public static final Setting SETTING_INDEX_VERSION_CREATED = new Setting<>( SETTING_VERSION_CREATED, - Version.V_EMPTY, + Integer.toString(IndexFormatVersion.ZERO.id), + s -> IndexFormatVersion.fromId(Integer.parseInt(s)), Property.IndexScope, Property.PrivateIndex ); @@ -361,19 +363,20 @@ public static APIBlock readFrom(StreamInput input) throws IOException { /** * See {@link #getCompatibilityVersion()} */ - public static final Setting SETTING_INDEX_VERSION_COMPATIBILITY = Setting.versionSetting( + public static final Setting SETTING_INDEX_VERSION_COMPATIBILITY = new Setting<>( SETTING_VERSION_COMPATIBILITY, SETTING_INDEX_VERSION_CREATED, // fall back to index.version.created + s -> IndexFormatVersion.fromId(Integer.parseInt(s)), new Setting.Validator<>() { @Override - public void validate(final Version compatibilityVersion) { + public void validate(final IndexFormatVersion compatibilityVersion) { } @Override - public void validate(final Version compatibilityVersion, final Map, Object> settings) { - Version createdVersion = (Version) settings.get(SETTING_INDEX_VERSION_CREATED); + public void validate(final IndexFormatVersion compatibilityVersion, final Map, Object> settings) { + IndexFormatVersion createdVersion = (IndexFormatVersion) settings.get(SETTING_INDEX_VERSION_CREATED); if (compatibilityVersion.before(createdVersion)) { throw new IllegalArgumentException( SETTING_VERSION_COMPATIBILITY @@ -393,7 +396,6 @@ public Iterator> settings() { final List> settings = List.of(SETTING_INDEX_VERSION_CREATED); return settings.iterator(); } - }, Property.IndexScope, Property.PrivateIndex @@ -578,8 +580,8 @@ public Iterator> settings() { private final DiscoveryNodeFilters excludeFilters; private final DiscoveryNodeFilters initialRecoveryFilters; - private final Version indexCreatedVersion; - private final Version indexCompatibilityVersion; + private final IndexFormatVersion indexCreatedVersion; + private final IndexFormatVersion indexCompatibilityVersion; private final ActiveShardCount waitForActiveShards; private final ImmutableOpenMap rolloverInfos; @@ -642,7 +644,7 @@ private IndexMetadata( final DiscoveryNodeFilters initialRecoveryFilters, final DiscoveryNodeFilters includeFilters, final DiscoveryNodeFilters excludeFilters, - final Version indexCreatedVersion, + final IndexFormatVersion indexCreatedVersion, final int routingNumShards, final int routingPartitionSize, final List routingPaths, @@ -664,7 +666,7 @@ private IndexMetadata( @Nullable final IndexMode indexMode, @Nullable final Instant timeSeriesStart, @Nullable final Instant timeSeriesEnd, - final Version indexCompatibilityVersion, + final IndexFormatVersion indexCompatibilityVersion, @Nullable final IndexMetadataStats stats, @Nullable final Double writeLoadForecast, @Nullable Long shardSizeInBytesForecast @@ -1039,7 +1041,7 @@ public long primaryTerm(int shardId) { * To check index compatibility (e.g. N-1 checks), use {@link #getCompatibilityVersion()} instead. */ public Version getCreationVersion() { - return indexCreatedVersion; + return indexCreatedVersion.toVersion(); } /** @@ -1050,7 +1052,7 @@ public Version getCreationVersion() { * a legacy index from an older snapshot, and its metadata has been converted to be handled by newer version nodes. */ public Version getCompatibilityVersion() { - return indexCompatibilityVersion; + return indexCompatibilityVersion.toVersion(); } public long getCreationDate() { @@ -2085,7 +2087,7 @@ IndexMetadata build(boolean repair) { } else { initialRecoveryFilters = DiscoveryNodeFilters.buildFromKeyValues(OR, initialRecoveryMap); } - Version indexCreatedVersion = indexCreatedVersion(settings); + IndexFormatVersion indexCreatedVersion = indexCreatedVersion(settings); if (primaryTerms == null) { initializePrimaryTerms(); @@ -2480,7 +2482,7 @@ public static IndexMetadata fromXContent(XContentParser parser, Map map * @throws IllegalArgumentException if the given index settings doesn't contain a value for the key * {@value IndexMetadata#SETTING_VERSION_CREATED} */ - private static Version indexCreatedVersion(Settings indexSettings) { - final Version indexVersion = IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(indexSettings); - if (indexVersion == Version.V_EMPTY) { + private static IndexFormatVersion indexCreatedVersion(Settings indexSettings) { + IndexFormatVersion indexVersion = IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(indexSettings); + if (indexVersion.equals(IndexFormatVersion.ZERO)) { final String message = String.format( Locale.ROOT, "[%s] is not present in the index settings for index with UUID [%s]", @@ -2635,8 +2637,8 @@ private static Version indexCreatedVersion(Settings indexSettings) { */ public static Settings addHumanReadableSettings(Settings settings) { Settings.Builder builder = Settings.builder().put(settings); - Version version = SETTING_INDEX_VERSION_CREATED.get(settings); - if (version != Version.V_EMPTY) { + IndexFormatVersion version = SETTING_INDEX_VERSION_CREATED.get(settings); + if (version.equals(IndexFormatVersion.ZERO) == false) { builder.put(SETTING_VERSION_CREATED_STRING, version.toString()); } Long creationDate = settings.getAsLong(SETTING_CREATION_DATE, null); diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java index 47cbbdf434ee8..3c46209705dc1 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java @@ -53,6 +53,7 @@ import org.elasticsearch.core.SuppressForbidden; import org.elasticsearch.env.Environment; import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexFormatVersion; import org.elasticsearch.index.IndexMode; import org.elasticsearch.index.IndexModule; import org.elasticsearch.index.IndexNotFoundException; @@ -1088,7 +1089,7 @@ static Settings aggregateIndexSettings( private static void validateSoftDeleteSettings(Settings indexSettings) { if (IndexSettings.INDEX_SOFT_DELETES_SETTING.get(indexSettings) == false - && IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(indexSettings).onOrAfter(Version.V_8_0_0)) { + && IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(indexSettings).onOrAfter(IndexFormatVersion.V_8_0_0)) { throw new IllegalArgumentException( "Creating indices with soft-deletes disabled is no longer supported. " + "Please do not specify a value for setting [index.soft_deletes.enabled]." @@ -1102,7 +1103,7 @@ private static void validateSoftDeleteSettings(Settings indexSettings) { */ static int getIndexNumberOfRoutingShards(Settings indexSettings, @Nullable IndexMetadata sourceMetadata) { final int numTargetShards = INDEX_NUMBER_OF_SHARDS_SETTING.get(indexSettings); - final Version indexVersionCreated = IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(indexSettings); + final IndexFormatVersion indexVersionCreated = IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(indexSettings); final int routingNumShards; if (sourceMetadata == null || sourceMetadata.getNumberOfShards() == 1) { // in this case we either have no index to recover from or @@ -1589,10 +1590,10 @@ static void prepareResizeIndexSettings( * allow any index to be split at least once and at most 10 times by a factor of two. The closer the number or shards gets to 1024 * the less default split operations are supported */ - public static int calculateNumRoutingShards(int numShards, Version indexVersionCreated) { - if (indexVersionCreated.onOrAfter(Version.V_7_0_0)) { + public static int calculateNumRoutingShards(int numShards, IndexFormatVersion indexVersionCreated) { + if (indexVersionCreated.onOrAfter(IndexFormatVersion.V_7_0_0)) { // only select this automatically for indices that are created on or after 7.0 this will prevent this new behaviour - // until we have a fully upgraded cluster. Additionally it will make integratin testing easier since mixed clusters + // until we have a fully upgraded cluster. Additionally it will make integrating testing easier since mixed clusters // will always have the behavior of the min node in the cluster. // // We use as a default number of routing shards the higher number that can be expressed @@ -1608,7 +1609,7 @@ public static int calculateNumRoutingShards(int numShards, Version indexVersionC } public static void validateTranslogRetentionSettings(Settings indexSettings) { - if (IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(indexSettings).onOrAfter(Version.V_8_0_0) + if (IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(indexSettings).onOrAfter(IndexFormatVersion.V_8_0_0) && (IndexSettings.INDEX_TRANSLOG_RETENTION_AGE_SETTING.exists(indexSettings) || IndexSettings.INDEX_TRANSLOG_RETENTION_SIZE_SETTING.exists(indexSettings))) { throw new IllegalArgumentException( diff --git a/server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java b/server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java index c4d765875764c..23d44cbccecc0 100644 --- a/server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java +++ b/server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java @@ -7,7 +7,6 @@ */ package org.elasticsearch.common.settings; -import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.MetadataIndexStateService; import org.elasticsearch.cluster.routing.UnassignedInfo; @@ -19,6 +18,7 @@ import org.elasticsearch.cluster.routing.allocation.decider.ShardsLimitAllocationDecider; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Setting.Property; +import org.elasticsearch.index.IndexFormatVersion; import org.elasticsearch.index.IndexModule; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.IndexSortConfig; @@ -241,12 +241,14 @@ public boolean isPrivateSetting(String key) { @Override protected void validateDeprecatedAndRemovedSettingV7(Settings settings, Setting setting) { - Version indexVersion = IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(settings); + IndexFormatVersion indexVersion = IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(settings); // At various stages in settings verification we will perform validation without having the // IndexMetadata at hand, in which case the setting version will be empty. We don't want to // error out on those validations, we will check with the creation version present at index // creation time, as well as on index update settings. - if (indexVersion.equals(Version.V_EMPTY) == false && indexVersion.major != Version.V_7_0_0.major) { + if (indexVersion.equals(IndexFormatVersion.ZERO) == false + && indexVersion.before(IndexFormatVersion.V_7_0_0) + && indexVersion.onOrAfter(IndexFormatVersion.V_8_0_0)) { throw new IllegalArgumentException("unknown setting [" + setting.getKey() + "]"); } } diff --git a/server/src/main/java/org/elasticsearch/index/IndexFormatVersion.java b/server/src/main/java/org/elasticsearch/index/IndexFormatVersion.java new file mode 100644 index 0000000000000..d6f16ddeadf29 --- /dev/null +++ b/server/src/main/java/org/elasticsearch/index/IndexFormatVersion.java @@ -0,0 +1,139 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +package org.elasticsearch.index; + +import org.elasticsearch.Version; + +import java.lang.reflect.Field; +import java.util.Collections; +import java.util.NavigableMap; +import java.util.Set; +import java.util.TreeMap; + +/** + * The index format version. + *

+ * Prior to 8.7.0, the node {@link Version} was used everywhere. This class separates the index format version + * from the running node version. + */ +public final class IndexFormatVersion implements Comparable { + public static final IndexFormatVersion ZERO = new IndexFormatVersion(0); + public static final IndexFormatVersion V_7_0_0 = new IndexFormatVersion(7_00_00_99); + public static final IndexFormatVersion V_7_2_0 = new IndexFormatVersion(7_02_00_99); + public static final IndexFormatVersion V_8_0_0 = new IndexFormatVersion(8_00_00_99); + public static final IndexFormatVersion V_8_8_0 = new IndexFormatVersion(8_08_00_99); + + public static final IndexFormatVersion CURRENT = V_8_8_0; + + public static final IndexFormatVersion MINIMUM_COMPATIBLE = V_7_0_0; + + static NavigableMap getAllVersionIds(Class cls) { + NavigableMap builder = new TreeMap<>(); + + Set ignore = Set.of("ZERO", "CURRENT", "MINIMUM_COMPATIBLE"); + for (Field declaredField : cls.getFields()) { + if (declaredField.getType().equals(IndexFormatVersion.class)) { + String fieldName = declaredField.getName(); + if (ignore.contains(fieldName)) { + continue; + } + try { + IndexFormatVersion version = (IndexFormatVersion) declaredField.get(null); + + IndexFormatVersion maybePrevious = builder.put(version.id, version); + assert maybePrevious == null + : "expected [" + version.id + "] to be uniquely mapped but saw [" + maybePrevious + "] and [" + version + "]"; + } catch (IllegalAccessException e) { + assert false : "IndexFormatVersion field [" + fieldName + "] should be public"; + } + } + } + + return Collections.unmodifiableNavigableMap(builder); + } + + private static final NavigableMap VERSION_IDS; + + static { + VERSION_IDS = getAllVersionIds(IndexFormatVersion.class); + } + + public final int id; + + IndexFormatVersion(int id) { + this.id = id; + } + + public static IndexFormatVersion fromId(int id) { + IndexFormatVersion known = VERSION_IDS.get(id); + if (known != null) { + return known; + } + // this is a version we don't otherwise know about - just create a placeholder + return new IndexFormatVersion(id); + } + + @Deprecated(forRemoval = true) + public Version toVersion() { + return Version.fromId(id); + } + + public boolean after(IndexFormatVersion version) { + return version.id < id; + } + + public boolean onOrAfter(IndexFormatVersion version) { + return version.id <= id; + } + + public boolean before(IndexFormatVersion version) { + return version.id > id; + } + + public boolean onOrBefore(IndexFormatVersion version) { + return version.id >= id; + } + + public boolean isLegacyIndexFormatVersion() { + return before(MINIMUM_COMPATIBLE); + } + + @Override + public int compareTo(IndexFormatVersion other) { + return Integer.compare(this.id, other.id); + } + + @Override + public String toString() { + return Integer.toString(id); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + IndexFormatVersion version = (IndexFormatVersion) o; + + if (id != version.id) { + return false; + } + + return true; + } + + @Override + public int hashCode() { + return id; + } +} diff --git a/server/src/main/java/org/elasticsearch/index/IndexSettings.java b/server/src/main/java/org/elasticsearch/index/IndexSettings.java index 16526e4926c16..c77f0bc7a0a43 100644 --- a/server/src/main/java/org/elasticsearch/index/IndexSettings.java +++ b/server/src/main/java/org/elasticsearch/index/IndexSettings.java @@ -581,7 +581,7 @@ public Iterator> settings() { ); private final Index index; - private final Version version; + private final IndexFormatVersion version; private final Logger logger; private final String nodeName; private final Settings nodeSettings; @@ -763,7 +763,7 @@ public IndexSettings(final IndexMetadata indexMetadata, final Settings nodeSetti mergeSchedulerConfig = new MergeSchedulerConfig(this); gcDeletesInMillis = scopedSettings.get(INDEX_GC_DELETES_SETTING).getMillis(); softDeleteEnabled = scopedSettings.get(INDEX_SOFT_DELETES_SETTING); - assert softDeleteEnabled || version.before(Version.V_8_0_0) : "soft deletes must be enabled in version " + version; + assert softDeleteEnabled || version.before(IndexFormatVersion.V_8_0_0) : "soft deletes must be enabled in version " + version; softDeleteRetentionOperations = scopedSettings.get(INDEX_SOFT_DELETES_RETENTION_OPERATIONS_SETTING); retentionLeaseMillis = scopedSettings.get(INDEX_SOFT_DELETES_RETENTION_LEASE_PERIOD_SETTING).millis(); warmerEnabled = scopedSettings.get(INDEX_WARMER_ENABLED_SETTING); @@ -939,7 +939,7 @@ public String customDataPath() { * @see IndexMetadata#SETTING_VERSION_CREATED */ public Version getIndexVersionCreated() { - return version; + return version.toVersion(); } /** @@ -993,12 +993,12 @@ public Settings getNodeSettings() { */ public synchronized boolean updateIndexMetadata(IndexMetadata indexMetadata) { final Settings newSettings = indexMetadata.getSettings(); - Version newIndexVersion = IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(newSettings); + IndexFormatVersion newIndexVersion = IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(newSettings); if (version.equals(newIndexVersion) == false) { throw new IllegalArgumentException("version mismatch on settings update expected: " + version + " but was: " + newIndexVersion); } - Version newCompatibilityVersion = IndexMetadata.SETTING_INDEX_VERSION_COMPATIBILITY.get(newSettings); - Version compatibilityVersion = IndexMetadata.SETTING_INDEX_VERSION_COMPATIBILITY.get(settings); + IndexFormatVersion newCompatibilityVersion = IndexMetadata.SETTING_INDEX_VERSION_COMPATIBILITY.get(newSettings); + IndexFormatVersion compatibilityVersion = IndexMetadata.SETTING_INDEX_VERSION_COMPATIBILITY.get(settings); if (compatibilityVersion.equals(newCompatibilityVersion) == false) { throw new IllegalArgumentException( "compatibility version mismatch on settings update expected: " diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexServiceTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexServiceTests.java index 94e4c2664f42f..b9a23184c2b4b 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexServiceTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexServiceTests.java @@ -38,6 +38,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.core.TimeValue; import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexFormatVersion; import org.elasticsearch.index.IndexModule; import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.IndexSettingProviders; @@ -606,17 +607,17 @@ private static void validateIndexName(MetadataCreateIndexService metadataCreateI } public void testCalculateNumRoutingShards() { - assertEquals(1024, MetadataCreateIndexService.calculateNumRoutingShards(1, Version.CURRENT)); - assertEquals(1024, MetadataCreateIndexService.calculateNumRoutingShards(2, Version.CURRENT)); - assertEquals(768, MetadataCreateIndexService.calculateNumRoutingShards(3, Version.CURRENT)); - assertEquals(576, MetadataCreateIndexService.calculateNumRoutingShards(9, Version.CURRENT)); - assertEquals(1024, MetadataCreateIndexService.calculateNumRoutingShards(512, Version.CURRENT)); - assertEquals(2048, MetadataCreateIndexService.calculateNumRoutingShards(1024, Version.CURRENT)); - assertEquals(4096, MetadataCreateIndexService.calculateNumRoutingShards(2048, Version.CURRENT)); + assertEquals(1024, MetadataCreateIndexService.calculateNumRoutingShards(1, IndexFormatVersion.CURRENT)); + assertEquals(1024, MetadataCreateIndexService.calculateNumRoutingShards(2, IndexFormatVersion.CURRENT)); + assertEquals(768, MetadataCreateIndexService.calculateNumRoutingShards(3, IndexFormatVersion.CURRENT)); + assertEquals(576, MetadataCreateIndexService.calculateNumRoutingShards(9, IndexFormatVersion.CURRENT)); + assertEquals(1024, MetadataCreateIndexService.calculateNumRoutingShards(512, IndexFormatVersion.CURRENT)); + assertEquals(2048, MetadataCreateIndexService.calculateNumRoutingShards(1024, IndexFormatVersion.CURRENT)); + assertEquals(4096, MetadataCreateIndexService.calculateNumRoutingShards(2048, IndexFormatVersion.CURRENT)); for (int i = 0; i < 1000; i++) { int randomNumShards = randomIntBetween(1, 10000); - int numRoutingShards = MetadataCreateIndexService.calculateNumRoutingShards(randomNumShards, Version.CURRENT); + int numRoutingShards = MetadataCreateIndexService.calculateNumRoutingShards(randomNumShards, IndexFormatVersion.CURRENT); if (numRoutingShards <= 1024) { assertTrue("numShards: " + randomNumShards, randomNumShards < 513); assertTrue("numRoutingShards: " + numRoutingShards, numRoutingShards > 512); From 63042b731fe183c89dae0f585253f54f651bdcf4 Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Tue, 28 Mar 2023 14:44:29 +0100 Subject: [PATCH 02/20] Test fixes --- .../org/elasticsearch/cluster/metadata/IndexMetadata.java | 2 +- .../elasticsearch/common/settings/IndexScopedSettings.java | 4 ++-- .../java/org/elasticsearch/index/IndexFormatVersion.java | 6 ++++++ .../cluster/metadata/HumanReadableIndexSettingsTests.java | 6 +++--- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java index d7769d9810ba2..a586560a9e91e 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java @@ -2152,7 +2152,7 @@ IndexMetadata build(boolean repair) { var aliasesMap = aliases.build(); for (AliasMetadata alias : aliasesMap.values()) { if (alias.alias().equals(index)) { - if (repair && indexCreatedVersion.equals(Version.V_8_5_0)) { + if (repair && indexCreatedVersion.equals(IndexFormatVersion.V_8_5_0)) { var updatedBuilder = ImmutableOpenMap.builder(aliasesMap); final var brokenAlias = updatedBuilder.remove(index); final var fixedAlias = AliasMetadata.newAliasMetadata(brokenAlias, index + "-alias-corrupted-by-8-5"); diff --git a/server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java b/server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java index 23d44cbccecc0..8dab241854a5a 100644 --- a/server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java +++ b/server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java @@ -247,8 +247,8 @@ protected void validateDeprecatedAndRemovedSettingV7(Settings settings, Setting< // error out on those validations, we will check with the creation version present at index // creation time, as well as on index update settings. if (indexVersion.equals(IndexFormatVersion.ZERO) == false - && indexVersion.before(IndexFormatVersion.V_7_0_0) - && indexVersion.onOrAfter(IndexFormatVersion.V_8_0_0)) { + && (indexVersion.before(IndexFormatVersion.V_7_0_0) + || indexVersion.onOrAfter(IndexFormatVersion.V_8_0_0))) { throw new IllegalArgumentException("unknown setting [" + setting.getKey() + "]"); } } diff --git a/server/src/main/java/org/elasticsearch/index/IndexFormatVersion.java b/server/src/main/java/org/elasticsearch/index/IndexFormatVersion.java index d6f16ddeadf29..751b8edbf534b 100644 --- a/server/src/main/java/org/elasticsearch/index/IndexFormatVersion.java +++ b/server/src/main/java/org/elasticsearch/index/IndexFormatVersion.java @@ -27,6 +27,7 @@ public final class IndexFormatVersion implements Comparable public static final IndexFormatVersion V_7_0_0 = new IndexFormatVersion(7_00_00_99); public static final IndexFormatVersion V_7_2_0 = new IndexFormatVersion(7_02_00_99); public static final IndexFormatVersion V_8_0_0 = new IndexFormatVersion(8_00_00_99); + public static final IndexFormatVersion V_8_5_0 = new IndexFormatVersion(8_05_00_99); public static final IndexFormatVersion V_8_8_0 = new IndexFormatVersion(8_08_00_99); public static final IndexFormatVersion CURRENT = V_8_8_0; @@ -84,6 +85,11 @@ public Version toVersion() { return Version.fromId(id); } + @Deprecated(forRemoval = true) + public static IndexFormatVersion fromVersion(Version version) { + return IndexFormatVersion.fromId(version.id); + } + public boolean after(IndexFormatVersion version) { return version.id < id; } diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/HumanReadableIndexSettingsTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/HumanReadableIndexSettingsTests.java index 7adb945c77e64..de7aaeb212f84 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/HumanReadableIndexSettingsTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/HumanReadableIndexSettingsTests.java @@ -8,8 +8,8 @@ package org.elasticsearch.cluster.metadata; -import org.elasticsearch.Version; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.IndexFormatVersion; import org.elasticsearch.test.ESTestCase; import java.time.Instant; @@ -21,10 +21,10 @@ public class HumanReadableIndexSettingsTests extends ESTestCase { public void testHumanReadableSettings() { - Version versionCreated = randomVersion(random()); + IndexFormatVersion versionCreated = IndexFormatVersion.fromVersion(randomVersion(random())); long created = System.currentTimeMillis(); Settings testSettings = Settings.builder() - .put(IndexMetadata.SETTING_VERSION_CREATED, versionCreated) + .put(IndexMetadata.SETTING_VERSION_CREATED, versionCreated.id) .put(IndexMetadata.SETTING_CREATION_DATE, created) .build(); From 36b29ade8296a19beab6b2a72224f23967f26a32 Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Tue, 28 Mar 2023 15:09:54 +0100 Subject: [PATCH 03/20] splotless --- .../org/elasticsearch/common/settings/IndexScopedSettings.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java b/server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java index 8dab241854a5a..0b38b2286296d 100644 --- a/server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java +++ b/server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java @@ -247,8 +247,7 @@ protected void validateDeprecatedAndRemovedSettingV7(Settings settings, Setting< // error out on those validations, we will check with the creation version present at index // creation time, as well as on index update settings. if (indexVersion.equals(IndexFormatVersion.ZERO) == false - && (indexVersion.before(IndexFormatVersion.V_7_0_0) - || indexVersion.onOrAfter(IndexFormatVersion.V_8_0_0))) { + && (indexVersion.before(IndexFormatVersion.V_7_0_0) || indexVersion.onOrAfter(IndexFormatVersion.V_8_0_0))) { throw new IllegalArgumentException("unknown setting [" + setting.getKey() + "]"); } } From ba2900446d8f10b0dbd32507561bc9ff88d2d12c Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Thu, 30 Mar 2023 12:44:57 +0100 Subject: [PATCH 04/20] Changes to IndexVersion --- .../admin/indices/create/SplitIndexIT.java | 4 +- .../cluster/metadata/IndexMetadata.java | 42 +-- .../metadata/MetadataCreateIndexService.java | 12 +- .../common/settings/IndexScopedSettings.java | 8 +- .../index/IndexFormatVersion.java | 145 ---------- .../elasticsearch/index/IndexSettings.java | 10 +- .../org/elasticsearch/index/IndexVersion.java | 252 ++++++++++++++++++ .../HumanReadableIndexSettingsTests.java | 4 +- .../MetadataCreateIndexServiceTests.java | 18 +- 9 files changed, 301 insertions(+), 194 deletions(-) delete mode 100644 server/src/main/java/org/elasticsearch/index/IndexFormatVersion.java create mode 100644 server/src/main/java/org/elasticsearch/index/IndexVersion.java diff --git a/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/create/SplitIndexIT.java b/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/create/SplitIndexIT.java index f468b065fe6af..d8c65d1380719 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/create/SplitIndexIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/create/SplitIndexIT.java @@ -37,7 +37,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.core.TimeValue; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexFormatVersion; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.engine.SegmentsStats; import org.elasticsearch.index.query.TermsQueryBuilder; @@ -110,7 +110,7 @@ private void splitToN(int sourceShards, int firstSplitShards, int secondSplitSha useRoutingPartition = randomBoolean(); } if (useRouting && useMixedRouting == false && useRoutingPartition) { - int numRoutingShards = MetadataCreateIndexService.calculateNumRoutingShards(secondSplitShards, IndexFormatVersion.CURRENT) - 1; + int numRoutingShards = MetadataCreateIndexService.calculateNumRoutingShards(secondSplitShards, IndexVersion.CURRENT) - 1; settings.put("index.routing_partition_size", randomIntBetween(1, numRoutingShards)); if (useNested) { createInitialIndex.setMapping("_routing", "required=true", "nested1", "type=nested"); diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java index a586560a9e91e..98cba492c401c 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java @@ -41,7 +41,7 @@ import org.elasticsearch.core.Nullable; import org.elasticsearch.gateway.MetadataStateFormat; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexFormatVersion; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.IndexMode; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.mapper.MapperService; @@ -338,10 +338,10 @@ public static APIBlock readFrom(StreamInput input) throws IOException { public static final String SETTING_VERSION_CREATED = "index.version.created"; - public static final Setting SETTING_INDEX_VERSION_CREATED = new Setting<>( + public static final Setting SETTING_INDEX_VERSION_CREATED = new Setting<>( SETTING_VERSION_CREATED, - Integer.toString(IndexFormatVersion.ZERO.id), - s -> IndexFormatVersion.fromId(Integer.parseInt(s)), + Integer.toString(IndexVersion.ZERO.id), + s -> IndexVersion.fromId(Integer.parseInt(s)), Property.IndexScope, Property.PrivateIndex ); @@ -363,20 +363,20 @@ public static APIBlock readFrom(StreamInput input) throws IOException { /** * See {@link #getCompatibilityVersion()} */ - public static final Setting SETTING_INDEX_VERSION_COMPATIBILITY = new Setting<>( + public static final Setting SETTING_INDEX_VERSION_COMPATIBILITY = new Setting<>( SETTING_VERSION_COMPATIBILITY, SETTING_INDEX_VERSION_CREATED, // fall back to index.version.created - s -> IndexFormatVersion.fromId(Integer.parseInt(s)), + s -> IndexVersion.fromId(Integer.parseInt(s)), new Setting.Validator<>() { @Override - public void validate(final IndexFormatVersion compatibilityVersion) { + public void validate(final IndexVersion compatibilityVersion) { } @Override - public void validate(final IndexFormatVersion compatibilityVersion, final Map, Object> settings) { - IndexFormatVersion createdVersion = (IndexFormatVersion) settings.get(SETTING_INDEX_VERSION_CREATED); + public void validate(final IndexVersion compatibilityVersion, final Map, Object> settings) { + IndexVersion createdVersion = (IndexVersion) settings.get(SETTING_INDEX_VERSION_CREATED); if (compatibilityVersion.before(createdVersion)) { throw new IllegalArgumentException( SETTING_VERSION_COMPATIBILITY @@ -580,8 +580,8 @@ public Iterator> settings() { private final DiscoveryNodeFilters excludeFilters; private final DiscoveryNodeFilters initialRecoveryFilters; - private final IndexFormatVersion indexCreatedVersion; - private final IndexFormatVersion indexCompatibilityVersion; + private final IndexVersion indexCreatedVersion; + private final IndexVersion indexCompatibilityVersion; private final ActiveShardCount waitForActiveShards; private final ImmutableOpenMap rolloverInfos; @@ -644,7 +644,7 @@ private IndexMetadata( final DiscoveryNodeFilters initialRecoveryFilters, final DiscoveryNodeFilters includeFilters, final DiscoveryNodeFilters excludeFilters, - final IndexFormatVersion indexCreatedVersion, + final IndexVersion indexCreatedVersion, final int routingNumShards, final int routingPartitionSize, final List routingPaths, @@ -666,7 +666,7 @@ private IndexMetadata( @Nullable final IndexMode indexMode, @Nullable final Instant timeSeriesStart, @Nullable final Instant timeSeriesEnd, - final IndexFormatVersion indexCompatibilityVersion, + final IndexVersion indexCompatibilityVersion, @Nullable final IndexMetadataStats stats, @Nullable final Double writeLoadForecast, @Nullable Long shardSizeInBytesForecast @@ -2087,7 +2087,7 @@ IndexMetadata build(boolean repair) { } else { initialRecoveryFilters = DiscoveryNodeFilters.buildFromKeyValues(OR, initialRecoveryMap); } - IndexFormatVersion indexCreatedVersion = indexCreatedVersion(settings); + IndexVersion indexCreatedVersion = indexCreatedVersion(settings); if (primaryTerms == null) { initializePrimaryTerms(); @@ -2152,7 +2152,7 @@ IndexMetadata build(boolean repair) { var aliasesMap = aliases.build(); for (AliasMetadata alias : aliasesMap.values()) { if (alias.alias().equals(index)) { - if (repair && indexCreatedVersion.equals(IndexFormatVersion.V_8_5_0)) { + if (repair && indexCreatedVersion.equals(IndexVersion.V_8_5_0)) { var updatedBuilder = ImmutableOpenMap.builder(aliasesMap); final var brokenAlias = updatedBuilder.remove(index); final var fixedAlias = AliasMetadata.newAliasMetadata(brokenAlias, index + "-alias-corrupted-by-8-5"); @@ -2482,7 +2482,7 @@ public static IndexMetadata fromXContent(XContentParser parser, Map map * @throws IllegalArgumentException if the given index settings doesn't contain a value for the key * {@value IndexMetadata#SETTING_VERSION_CREATED} */ - private static IndexFormatVersion indexCreatedVersion(Settings indexSettings) { - IndexFormatVersion indexVersion = IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(indexSettings); - if (indexVersion.equals(IndexFormatVersion.ZERO)) { + private static IndexVersion indexCreatedVersion(Settings indexSettings) { + IndexVersion indexVersion = IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(indexSettings); + if (indexVersion.equals(IndexVersion.ZERO)) { final String message = String.format( Locale.ROOT, "[%s] is not present in the index settings for index with UUID [%s]", @@ -2637,8 +2637,8 @@ private static IndexFormatVersion indexCreatedVersion(Settings indexSettings) { */ public static Settings addHumanReadableSettings(Settings settings) { Settings.Builder builder = Settings.builder().put(settings); - IndexFormatVersion version = SETTING_INDEX_VERSION_CREATED.get(settings); - if (version.equals(IndexFormatVersion.ZERO) == false) { + IndexVersion version = SETTING_INDEX_VERSION_CREATED.get(settings); + if (version.equals(IndexVersion.ZERO) == false) { builder.put(SETTING_VERSION_CREATED_STRING, version.toString()); } Long creationDate = settings.getAsLong(SETTING_CREATION_DATE, null); diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java index 3c46209705dc1..063d7dd487350 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java @@ -53,7 +53,7 @@ import org.elasticsearch.core.SuppressForbidden; import org.elasticsearch.env.Environment; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexFormatVersion; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.IndexMode; import org.elasticsearch.index.IndexModule; import org.elasticsearch.index.IndexNotFoundException; @@ -1089,7 +1089,7 @@ static Settings aggregateIndexSettings( private static void validateSoftDeleteSettings(Settings indexSettings) { if (IndexSettings.INDEX_SOFT_DELETES_SETTING.get(indexSettings) == false - && IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(indexSettings).onOrAfter(IndexFormatVersion.V_8_0_0)) { + && IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(indexSettings).onOrAfter(IndexVersion.V_8_0_0)) { throw new IllegalArgumentException( "Creating indices with soft-deletes disabled is no longer supported. " + "Please do not specify a value for setting [index.soft_deletes.enabled]." @@ -1103,7 +1103,7 @@ private static void validateSoftDeleteSettings(Settings indexSettings) { */ static int getIndexNumberOfRoutingShards(Settings indexSettings, @Nullable IndexMetadata sourceMetadata) { final int numTargetShards = INDEX_NUMBER_OF_SHARDS_SETTING.get(indexSettings); - final IndexFormatVersion indexVersionCreated = IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(indexSettings); + final IndexVersion indexVersionCreated = IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(indexSettings); final int routingNumShards; if (sourceMetadata == null || sourceMetadata.getNumberOfShards() == 1) { // in this case we either have no index to recover from or @@ -1590,8 +1590,8 @@ static void prepareResizeIndexSettings( * allow any index to be split at least once and at most 10 times by a factor of two. The closer the number or shards gets to 1024 * the less default split operations are supported */ - public static int calculateNumRoutingShards(int numShards, IndexFormatVersion indexVersionCreated) { - if (indexVersionCreated.onOrAfter(IndexFormatVersion.V_7_0_0)) { + public static int calculateNumRoutingShards(int numShards, IndexVersion indexVersionCreated) { + if (indexVersionCreated.onOrAfter(IndexVersion.V_7_0_0)) { // only select this automatically for indices that are created on or after 7.0 this will prevent this new behaviour // until we have a fully upgraded cluster. Additionally it will make integrating testing easier since mixed clusters // will always have the behavior of the min node in the cluster. @@ -1609,7 +1609,7 @@ public static int calculateNumRoutingShards(int numShards, IndexFormatVersion in } public static void validateTranslogRetentionSettings(Settings indexSettings) { - if (IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(indexSettings).onOrAfter(IndexFormatVersion.V_8_0_0) + if (IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(indexSettings).onOrAfter(IndexVersion.V_8_0_0) && (IndexSettings.INDEX_TRANSLOG_RETENTION_AGE_SETTING.exists(indexSettings) || IndexSettings.INDEX_TRANSLOG_RETENTION_SIZE_SETTING.exists(indexSettings))) { throw new IllegalArgumentException( diff --git a/server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java b/server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java index 0b38b2286296d..bcabd2966ad7a 100644 --- a/server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java +++ b/server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java @@ -18,7 +18,7 @@ import org.elasticsearch.cluster.routing.allocation.decider.ShardsLimitAllocationDecider; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Setting.Property; -import org.elasticsearch.index.IndexFormatVersion; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.IndexModule; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.IndexSortConfig; @@ -241,13 +241,13 @@ public boolean isPrivateSetting(String key) { @Override protected void validateDeprecatedAndRemovedSettingV7(Settings settings, Setting setting) { - IndexFormatVersion indexVersion = IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(settings); + IndexVersion indexVersion = IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(settings); // At various stages in settings verification we will perform validation without having the // IndexMetadata at hand, in which case the setting version will be empty. We don't want to // error out on those validations, we will check with the creation version present at index // creation time, as well as on index update settings. - if (indexVersion.equals(IndexFormatVersion.ZERO) == false - && (indexVersion.before(IndexFormatVersion.V_7_0_0) || indexVersion.onOrAfter(IndexFormatVersion.V_8_0_0))) { + if (indexVersion.equals(IndexVersion.ZERO) == false + && (indexVersion.before(IndexVersion.V_7_0_0) || indexVersion.onOrAfter(IndexVersion.V_8_0_0))) { throw new IllegalArgumentException("unknown setting [" + setting.getKey() + "]"); } } diff --git a/server/src/main/java/org/elasticsearch/index/IndexFormatVersion.java b/server/src/main/java/org/elasticsearch/index/IndexFormatVersion.java deleted file mode 100644 index 751b8edbf534b..0000000000000 --- a/server/src/main/java/org/elasticsearch/index/IndexFormatVersion.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.index; - -import org.elasticsearch.Version; - -import java.lang.reflect.Field; -import java.util.Collections; -import java.util.NavigableMap; -import java.util.Set; -import java.util.TreeMap; - -/** - * The index format version. - *

- * Prior to 8.7.0, the node {@link Version} was used everywhere. This class separates the index format version - * from the running node version. - */ -public final class IndexFormatVersion implements Comparable { - public static final IndexFormatVersion ZERO = new IndexFormatVersion(0); - public static final IndexFormatVersion V_7_0_0 = new IndexFormatVersion(7_00_00_99); - public static final IndexFormatVersion V_7_2_0 = new IndexFormatVersion(7_02_00_99); - public static final IndexFormatVersion V_8_0_0 = new IndexFormatVersion(8_00_00_99); - public static final IndexFormatVersion V_8_5_0 = new IndexFormatVersion(8_05_00_99); - public static final IndexFormatVersion V_8_8_0 = new IndexFormatVersion(8_08_00_99); - - public static final IndexFormatVersion CURRENT = V_8_8_0; - - public static final IndexFormatVersion MINIMUM_COMPATIBLE = V_7_0_0; - - static NavigableMap getAllVersionIds(Class cls) { - NavigableMap builder = new TreeMap<>(); - - Set ignore = Set.of("ZERO", "CURRENT", "MINIMUM_COMPATIBLE"); - for (Field declaredField : cls.getFields()) { - if (declaredField.getType().equals(IndexFormatVersion.class)) { - String fieldName = declaredField.getName(); - if (ignore.contains(fieldName)) { - continue; - } - try { - IndexFormatVersion version = (IndexFormatVersion) declaredField.get(null); - - IndexFormatVersion maybePrevious = builder.put(version.id, version); - assert maybePrevious == null - : "expected [" + version.id + "] to be uniquely mapped but saw [" + maybePrevious + "] and [" + version + "]"; - } catch (IllegalAccessException e) { - assert false : "IndexFormatVersion field [" + fieldName + "] should be public"; - } - } - } - - return Collections.unmodifiableNavigableMap(builder); - } - - private static final NavigableMap VERSION_IDS; - - static { - VERSION_IDS = getAllVersionIds(IndexFormatVersion.class); - } - - public final int id; - - IndexFormatVersion(int id) { - this.id = id; - } - - public static IndexFormatVersion fromId(int id) { - IndexFormatVersion known = VERSION_IDS.get(id); - if (known != null) { - return known; - } - // this is a version we don't otherwise know about - just create a placeholder - return new IndexFormatVersion(id); - } - - @Deprecated(forRemoval = true) - public Version toVersion() { - return Version.fromId(id); - } - - @Deprecated(forRemoval = true) - public static IndexFormatVersion fromVersion(Version version) { - return IndexFormatVersion.fromId(version.id); - } - - public boolean after(IndexFormatVersion version) { - return version.id < id; - } - - public boolean onOrAfter(IndexFormatVersion version) { - return version.id <= id; - } - - public boolean before(IndexFormatVersion version) { - return version.id > id; - } - - public boolean onOrBefore(IndexFormatVersion version) { - return version.id >= id; - } - - public boolean isLegacyIndexFormatVersion() { - return before(MINIMUM_COMPATIBLE); - } - - @Override - public int compareTo(IndexFormatVersion other) { - return Integer.compare(this.id, other.id); - } - - @Override - public String toString() { - return Integer.toString(id); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - IndexFormatVersion version = (IndexFormatVersion) o; - - if (id != version.id) { - return false; - } - - return true; - } - - @Override - public int hashCode() { - return id; - } -} diff --git a/server/src/main/java/org/elasticsearch/index/IndexSettings.java b/server/src/main/java/org/elasticsearch/index/IndexSettings.java index c77f0bc7a0a43..f4bbc4e194703 100644 --- a/server/src/main/java/org/elasticsearch/index/IndexSettings.java +++ b/server/src/main/java/org/elasticsearch/index/IndexSettings.java @@ -581,7 +581,7 @@ public Iterator> settings() { ); private final Index index; - private final IndexFormatVersion version; + private final IndexVersion version; private final Logger logger; private final String nodeName; private final Settings nodeSettings; @@ -763,7 +763,7 @@ public IndexSettings(final IndexMetadata indexMetadata, final Settings nodeSetti mergeSchedulerConfig = new MergeSchedulerConfig(this); gcDeletesInMillis = scopedSettings.get(INDEX_GC_DELETES_SETTING).getMillis(); softDeleteEnabled = scopedSettings.get(INDEX_SOFT_DELETES_SETTING); - assert softDeleteEnabled || version.before(IndexFormatVersion.V_8_0_0) : "soft deletes must be enabled in version " + version; + assert softDeleteEnabled || version.before(IndexVersion.V_8_0_0) : "soft deletes must be enabled in version " + version; softDeleteRetentionOperations = scopedSettings.get(INDEX_SOFT_DELETES_RETENTION_OPERATIONS_SETTING); retentionLeaseMillis = scopedSettings.get(INDEX_SOFT_DELETES_RETENTION_LEASE_PERIOD_SETTING).millis(); warmerEnabled = scopedSettings.get(INDEX_WARMER_ENABLED_SETTING); @@ -993,12 +993,12 @@ public Settings getNodeSettings() { */ public synchronized boolean updateIndexMetadata(IndexMetadata indexMetadata) { final Settings newSettings = indexMetadata.getSettings(); - IndexFormatVersion newIndexVersion = IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(newSettings); + IndexVersion newIndexVersion = IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(newSettings); if (version.equals(newIndexVersion) == false) { throw new IllegalArgumentException("version mismatch on settings update expected: " + version + " but was: " + newIndexVersion); } - IndexFormatVersion newCompatibilityVersion = IndexMetadata.SETTING_INDEX_VERSION_COMPATIBILITY.get(newSettings); - IndexFormatVersion compatibilityVersion = IndexMetadata.SETTING_INDEX_VERSION_COMPATIBILITY.get(settings); + IndexVersion newCompatibilityVersion = IndexMetadata.SETTING_INDEX_VERSION_COMPATIBILITY.get(newSettings); + IndexVersion compatibilityVersion = IndexMetadata.SETTING_INDEX_VERSION_COMPATIBILITY.get(settings); if (compatibilityVersion.equals(newCompatibilityVersion) == false) { throw new IllegalArgumentException( "compatibility version mismatch on settings update expected: " diff --git a/server/src/main/java/org/elasticsearch/index/IndexVersion.java b/server/src/main/java/org/elasticsearch/index/IndexVersion.java new file mode 100644 index 0000000000000..87ae520b7f35d --- /dev/null +++ b/server/src/main/java/org/elasticsearch/index/IndexVersion.java @@ -0,0 +1,252 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +package org.elasticsearch.index; + +import org.apache.lucene.util.Version; +import org.elasticsearch.TransportVersion; +import org.elasticsearch.common.Strings; + +import java.lang.reflect.Field; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.NavigableMap; +import java.util.Objects; +import java.util.Set; +import java.util.TreeMap; + +/** + * The index version. + *

+ * Prior to 8.8.0, the node {@link Version} was used everywhere. This class separates the index format version + * from the running node version. + */ +@SuppressWarnings("checkstyle:linelength") +public final class IndexVersion implements Comparable { + public static final IndexVersion ZERO = new IndexVersion(0, Version.LATEST, "00000000-0000-0000-0000-000000000000"); + public static final IndexVersion V_7_0_0 = new IndexVersion(7_00_00_99, Version.LUCENE_8_0_0); + public static final IndexVersion V_7_0_1 = new IndexVersion(7_00_01_99, Version.LUCENE_8_0_0); + public static final IndexVersion V_7_1_0 = new IndexVersion(7_01_00_99, Version.LUCENE_8_0_0); + public static final IndexVersion V_7_1_1 = new IndexVersion(7_01_01_99, Version.LUCENE_8_0_0); + public static final IndexVersion V_7_2_0 = new IndexVersion(7_02_00_99, Version.LUCENE_8_0_0); + public static final IndexVersion V_7_2_1 = new IndexVersion(7_02_01_99, Version.LUCENE_8_0_0); + public static final IndexVersion V_7_3_0 = new IndexVersion(7_03_00_99, Version.LUCENE_8_1_0); + public static final IndexVersion V_7_3_1 = new IndexVersion(7_03_01_99, Version.LUCENE_8_1_0); + public static final IndexVersion V_7_3_2 = new IndexVersion(7_03_02_99, Version.LUCENE_8_1_0); + public static final IndexVersion V_7_4_0 = new IndexVersion(7_04_00_99, Version.LUCENE_8_2_0); + public static final IndexVersion V_7_4_1 = new IndexVersion(7_04_01_99, Version.LUCENE_8_2_0); + public static final IndexVersion V_7_4_2 = new IndexVersion(7_04_02_99, Version.LUCENE_8_2_0); + public static final IndexVersion V_7_5_0 = new IndexVersion(7_05_00_99, Version.LUCENE_8_3_0); + public static final IndexVersion V_7_5_1 = new IndexVersion(7_05_01_99, Version.LUCENE_8_3_0); + public static final IndexVersion V_7_5_2 = new IndexVersion(7_05_02_99, Version.LUCENE_8_3_0); + public static final IndexVersion V_7_6_0 = new IndexVersion(7_06_00_99, Version.LUCENE_8_4_0); + public static final IndexVersion V_7_6_1 = new IndexVersion(7_06_01_99, Version.LUCENE_8_4_0); + public static final IndexVersion V_7_6_2 = new IndexVersion(7_06_02_99, Version.LUCENE_8_4_0); + public static final IndexVersion V_7_7_0 = new IndexVersion(7_07_00_99, Version.LUCENE_8_5_1); + public static final IndexVersion V_7_7_1 = new IndexVersion(7_07_01_99, Version.LUCENE_8_5_1); + public static final IndexVersion V_7_8_0 = new IndexVersion(7_08_00_99, Version.LUCENE_8_5_1); + public static final IndexVersion V_7_8_1 = new IndexVersion(7_08_01_99, Version.LUCENE_8_5_1); + public static final IndexVersion V_7_9_0 = new IndexVersion(7_09_00_99, Version.LUCENE_8_6_0); + public static final IndexVersion V_7_9_1 = new IndexVersion(7_09_01_99, Version.LUCENE_8_6_2); + public static final IndexVersion V_7_9_2 = new IndexVersion(7_09_02_99, Version.LUCENE_8_6_2); + public static final IndexVersion V_7_9_3 = new IndexVersion(7_09_03_99, Version.LUCENE_8_6_2); + public static final IndexVersion V_7_10_0 = new IndexVersion(7_10_00_99, Version.LUCENE_8_7_0); + public static final IndexVersion V_7_10_1 = new IndexVersion(7_10_01_99, Version.LUCENE_8_7_0); + public static final IndexVersion V_7_10_2 = new IndexVersion(7_10_02_99, Version.LUCENE_8_7_0); + public static final IndexVersion V_7_11_0 = new IndexVersion(7_11_00_99, Version.LUCENE_8_7_0); + public static final IndexVersion V_7_11_1 = new IndexVersion(7_11_01_99, Version.LUCENE_8_7_0); + public static final IndexVersion V_7_11_2 = new IndexVersion(7_11_02_99, Version.LUCENE_8_7_0); + public static final IndexVersion V_7_12_0 = new IndexVersion(7_12_00_99, Version.LUCENE_8_8_0); + public static final IndexVersion V_7_12_1 = new IndexVersion(7_12_01_99, Version.LUCENE_8_8_0); + public static final IndexVersion V_7_13_0 = new IndexVersion(7_13_00_99, Version.LUCENE_8_8_2); + public static final IndexVersion V_7_13_1 = new IndexVersion(7_13_01_99, Version.LUCENE_8_8_2); + public static final IndexVersion V_7_13_2 = new IndexVersion(7_13_02_99, Version.LUCENE_8_8_2); + public static final IndexVersion V_7_13_3 = new IndexVersion(7_13_03_99, Version.LUCENE_8_8_2); + public static final IndexVersion V_7_13_4 = new IndexVersion(7_13_04_99, Version.LUCENE_8_8_2); + public static final IndexVersion V_7_14_0 = new IndexVersion(7_14_00_99, Version.LUCENE_8_9_0); + public static final IndexVersion V_7_14_1 = new IndexVersion(7_14_01_99, Version.LUCENE_8_9_0); + public static final IndexVersion V_7_14_2 = new IndexVersion(7_14_02_99, Version.LUCENE_8_9_0); + public static final IndexVersion V_7_15_0 = new IndexVersion(7_15_00_99, Version.LUCENE_8_9_0); + public static final IndexVersion V_7_15_1 = new IndexVersion(7_15_01_99, Version.LUCENE_8_9_0); + public static final IndexVersion V_7_15_2 = new IndexVersion(7_15_02_99, Version.LUCENE_8_9_0); + public static final IndexVersion V_7_16_0 = new IndexVersion(7_16_00_99, Version.LUCENE_8_10_1); + public static final IndexVersion V_7_16_1 = new IndexVersion(7_16_01_99, Version.LUCENE_8_10_1); + public static final IndexVersion V_7_16_2 = new IndexVersion(7_16_02_99, Version.LUCENE_8_10_1); + public static final IndexVersion V_7_16_3 = new IndexVersion(7_16_03_99, Version.LUCENE_8_10_1); + public static final IndexVersion V_7_17_0 = new IndexVersion(7_17_00_99, Version.LUCENE_8_11_1); + public static final IndexVersion V_7_17_1 = new IndexVersion(7_17_01_99, Version.LUCENE_8_11_1); + public static final IndexVersion V_7_17_2 = new IndexVersion(7_17_02_99, Version.LUCENE_8_11_1); + public static final IndexVersion V_7_17_3 = new IndexVersion(7_17_03_99, Version.LUCENE_8_11_1); + public static final IndexVersion V_7_17_4 = new IndexVersion(7_17_04_99, Version.LUCENE_8_11_1); + public static final IndexVersion V_7_17_5 = new IndexVersion(7_17_05_99, Version.LUCENE_8_11_1); + public static final IndexVersion V_7_17_6 = new IndexVersion(7_17_06_99, Version.LUCENE_8_11_1); + public static final IndexVersion V_7_17_7 = new IndexVersion(7_17_07_99, Version.LUCENE_8_11_1); + public static final IndexVersion V_7_17_8 = new IndexVersion(7_17_08_99, Version.LUCENE_8_11_1); + public static final IndexVersion V_7_17_9 = new IndexVersion(7_17_09_99, Version.LUCENE_8_11_1); + public static final IndexVersion V_7_17_10 = new IndexVersion(7_17_10_99, Version.LUCENE_8_11_1); + public static final IndexVersion V_8_0_0 = new IndexVersion(8_00_00_99, Version.LUCENE_9_0_0); + public static final IndexVersion V_8_0_1 = new IndexVersion(8_00_01_99, Version.LUCENE_9_0_0); + public static final IndexVersion V_8_1_0 = new IndexVersion(8_01_00_99, Version.LUCENE_9_0_0); + public static final IndexVersion V_8_1_1 = new IndexVersion(8_01_01_99, Version.LUCENE_9_0_0); + public static final IndexVersion V_8_1_2 = new IndexVersion(8_01_02_99, Version.LUCENE_9_0_0); + public static final IndexVersion V_8_1_3 = new IndexVersion(8_01_03_99, Version.LUCENE_9_0_0); + public static final IndexVersion V_8_2_0 = new IndexVersion(8_02_00_99, Version.LUCENE_9_1_0); + public static final IndexVersion V_8_2_1 = new IndexVersion(8_02_01_99, Version.LUCENE_9_1_0); + public static final IndexVersion V_8_2_2 = new IndexVersion(8_02_02_99, Version.LUCENE_9_1_0); + public static final IndexVersion V_8_2_3 = new IndexVersion(8_02_03_99, Version.LUCENE_9_1_0); + public static final IndexVersion V_8_3_0 = new IndexVersion(8_03_00_99, Version.LUCENE_9_2_0); + public static final IndexVersion V_8_3_1 = new IndexVersion(8_03_01_99, Version.LUCENE_9_2_0); + public static final IndexVersion V_8_3_2 = new IndexVersion(8_03_02_99, Version.LUCENE_9_2_0); + public static final IndexVersion V_8_3_3 = new IndexVersion(8_03_03_99, Version.LUCENE_9_2_0); + public static final IndexVersion V_8_4_0 = new IndexVersion(8_04_00_99, Version.LUCENE_9_3_0); + public static final IndexVersion V_8_4_1 = new IndexVersion(8_04_01_99, Version.LUCENE_9_3_0); + public static final IndexVersion V_8_4_2 = new IndexVersion(8_04_02_99, Version.LUCENE_9_3_0); + public static final IndexVersion V_8_4_3 = new IndexVersion(8_04_03_99, Version.LUCENE_9_3_0); + public static final IndexVersion V_8_5_0 = new IndexVersion(8_05_00_99, Version.LUCENE_9_4_1); + public static final IndexVersion V_8_5_1 = new IndexVersion(8_05_01_99, Version.LUCENE_9_4_1); + public static final IndexVersion V_8_5_2 = new IndexVersion(8_05_02_99, Version.LUCENE_9_4_1); + public static final IndexVersion V_8_5_3 = new IndexVersion(8_05_03_99, Version.LUCENE_9_4_2); + public static final IndexVersion V_8_6_0 = new IndexVersion(8_06_00_99, Version.LUCENE_9_4_2); + public static final IndexVersion V_8_6_1 = new IndexVersion(8_06_01_99, Version.LUCENE_9_4_2); + public static final IndexVersion V_8_6_2 = new IndexVersion(8_06_02_99, Version.LUCENE_9_4_2); + public static final IndexVersion V_8_6_3 = new IndexVersion(8_06_03_99, Version.LUCENE_9_4_2); + public static final IndexVersion V_8_7_0 = new IndexVersion(8_07_00_99, Version.LUCENE_9_5_0); + + public static final IndexVersion V_8_8_0 = new IndexVersion(8_08_00_99, Version.LUCENE_9_6_0); + + public static final IndexVersion CURRENT = V_8_8_0; + + public static final IndexVersion MINIMUM_COMPATIBLE = V_7_0_0; + + static NavigableMap getAllVersionIds(Class cls) { + NavigableMap builder = new TreeMap<>(); + Map uniqueIds = new HashMap<>(); + + Set ignore = Set.of("ZERO", "CURRENT", "MINIMUM_COMPATIBLE"); + for (Field declaredField : cls.getFields()) { + if (declaredField.getType().equals(TransportVersion.class)) { + String fieldName = declaredField.getName(); + if (ignore.contains(fieldName)) { + continue; + } + try { + IndexVersion version = (IndexVersion) declaredField.get(null); + + IndexVersion maybePrevious = builder.put(version.id, version); + assert maybePrevious == null + : "expected [" + version.id + "] to be uniquely mapped but saw [" + maybePrevious + "] and [" + version + "]"; + + IndexVersion sameUniqueId = uniqueIds.put(version.uniqueId, version); + assert sameUniqueId == null + : "Versions " + + version + + " and " + + sameUniqueId + + " have the same unique id. Each IndexVersion should have a different unique id"; + } catch (IllegalAccessException e) { + assert false : "IndexVersion field [" + fieldName + "] should be public"; + } + } + } + + return Collections.unmodifiableNavigableMap(builder); + } + + private static final NavigableMap VERSION_IDS; + + static { + VERSION_IDS = getAllVersionIds(IndexVersion.class); + } + + static Collection getAllVersions() { + return VERSION_IDS.values(); + } + + public final int id; + public final Version luceneVersion; + private final String uniqueId; + + IndexVersion(int id, Version luceneVersion, String uniqueId) { + this.id = id; + this.luceneVersion = Objects.requireNonNull(luceneVersion); + this.uniqueId = Strings.requireNonEmpty(uniqueId, "Each IndexVersion needs a unique string id"); + } + + public static IndexVersion fromId(int id) { + IndexVersion known = VERSION_IDS.get(id); + if (known != null) { + return known; + } + // this is a version we don't otherwise know about - just create a placeholder + // We need to guess the lucene version. + // Our best guess is to use the same lucene version as the previous + // version in the list, assuming that it didn't change. + + return new IndexVersion(id, ""); + } + + @Deprecated(forRemoval = true) + public org.elasticsearch.Version toVersion() { + return org.elasticsearch.Version.fromId(id); + } + + public boolean after(IndexVersion version) { + return version.id < id; + } + + public boolean onOrAfter(IndexVersion version) { + return version.id <= id; + } + + public boolean before(IndexVersion version) { + return version.id > id; + } + + public boolean onOrBefore(IndexVersion version) { + return version.id >= id; + } + + public boolean isLegacyIndexFormatVersion() { + return before(MINIMUM_COMPATIBLE); + } + + @Override + public int compareTo(IndexVersion other) { + return Integer.compare(this.id, other.id); + } + + @Override + public String toString() { + return Integer.toString(id); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + IndexVersion version = (IndexVersion) o; + + if (id != version.id) { + return false; + } + + return true; + } + + @Override + public int hashCode() { + return id; + } +} diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/HumanReadableIndexSettingsTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/HumanReadableIndexSettingsTests.java index de7aaeb212f84..a18b0daabe62c 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/HumanReadableIndexSettingsTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/HumanReadableIndexSettingsTests.java @@ -9,7 +9,7 @@ package org.elasticsearch.cluster.metadata; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.IndexFormatVersion; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.test.ESTestCase; import java.time.Instant; @@ -21,7 +21,7 @@ public class HumanReadableIndexSettingsTests extends ESTestCase { public void testHumanReadableSettings() { - IndexFormatVersion versionCreated = IndexFormatVersion.fromVersion(randomVersion(random())); + IndexVersion versionCreated = IndexVersion.fromVersion(randomVersion(random())); long created = System.currentTimeMillis(); Settings testSettings = Settings.builder() .put(IndexMetadata.SETTING_VERSION_CREATED, versionCreated.id) diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexServiceTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexServiceTests.java index b9a23184c2b4b..7144ecf1c7ede 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexServiceTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexServiceTests.java @@ -38,7 +38,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.core.TimeValue; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexFormatVersion; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.IndexModule; import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.IndexSettingProviders; @@ -607,17 +607,17 @@ private static void validateIndexName(MetadataCreateIndexService metadataCreateI } public void testCalculateNumRoutingShards() { - assertEquals(1024, MetadataCreateIndexService.calculateNumRoutingShards(1, IndexFormatVersion.CURRENT)); - assertEquals(1024, MetadataCreateIndexService.calculateNumRoutingShards(2, IndexFormatVersion.CURRENT)); - assertEquals(768, MetadataCreateIndexService.calculateNumRoutingShards(3, IndexFormatVersion.CURRENT)); - assertEquals(576, MetadataCreateIndexService.calculateNumRoutingShards(9, IndexFormatVersion.CURRENT)); - assertEquals(1024, MetadataCreateIndexService.calculateNumRoutingShards(512, IndexFormatVersion.CURRENT)); - assertEquals(2048, MetadataCreateIndexService.calculateNumRoutingShards(1024, IndexFormatVersion.CURRENT)); - assertEquals(4096, MetadataCreateIndexService.calculateNumRoutingShards(2048, IndexFormatVersion.CURRENT)); + assertEquals(1024, MetadataCreateIndexService.calculateNumRoutingShards(1, IndexVersion.CURRENT)); + assertEquals(1024, MetadataCreateIndexService.calculateNumRoutingShards(2, IndexVersion.CURRENT)); + assertEquals(768, MetadataCreateIndexService.calculateNumRoutingShards(3, IndexVersion.CURRENT)); + assertEquals(576, MetadataCreateIndexService.calculateNumRoutingShards(9, IndexVersion.CURRENT)); + assertEquals(1024, MetadataCreateIndexService.calculateNumRoutingShards(512, IndexVersion.CURRENT)); + assertEquals(2048, MetadataCreateIndexService.calculateNumRoutingShards(1024, IndexVersion.CURRENT)); + assertEquals(4096, MetadataCreateIndexService.calculateNumRoutingShards(2048, IndexVersion.CURRENT)); for (int i = 0; i < 1000; i++) { int randomNumShards = randomIntBetween(1, 10000); - int numRoutingShards = MetadataCreateIndexService.calculateNumRoutingShards(randomNumShards, IndexFormatVersion.CURRENT); + int numRoutingShards = MetadataCreateIndexService.calculateNumRoutingShards(randomNumShards, IndexVersion.CURRENT); if (numRoutingShards <= 1024) { assertTrue("numShards: " + randomNumShards, randomNumShards < 513); assertTrue("numRoutingShards: " + numRoutingShards, numRoutingShards > 512); From 1ac3fabae11b1839b7bd4c215ee0fce15b449c9b Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Thu, 30 Mar 2023 13:18:59 +0100 Subject: [PATCH 05/20] Move lucene version to IndexVersion --- .../gradle/internal/BwcVersions.java | 1 + .../upgrades/FullClusterRestartIT.java | 7 +- .../VerifyVersionConstantsIT.java | 2 +- .../plan/ShardSnapshotsServiceIT.java | 3 +- .../main/java/org/elasticsearch/Version.java | 217 ++++++++---------- .../action/main/MainResponse.java | 2 +- .../bootstrap/Elasticsearch.java | 5 +- .../org/elasticsearch/index/IndexVersion.java | 190 +++++++-------- .../analysis/PreConfiguredCharFilter.java | 2 +- .../analysis/PreConfiguredTokenFilter.java | 2 +- .../analysis/PreConfiguredTokenizer.java | 2 +- .../index/similarity/SimilarityService.java | 6 +- .../org/elasticsearch/index/store/Store.java | 5 +- .../analysis/PreBuiltCacheFactory.java | 4 +- .../indices/recovery/RecoverySettings.java | 3 +- .../java/org/elasticsearch/VersionTests.java | 15 +- .../action/main/MainResponseTests.java | 2 +- .../common/lucene/uid/VersionsTests.java | 8 +- .../gateway/ReplicaShardAllocatorTests.java | 3 +- .../index/engine/InternalEngineTests.java | 5 +- .../snapshots/blobstore/FileInfoTests.java | 4 +- .../elasticsearch/index/store/StoreTests.java | 4 +- .../indices/analysis/AnalysisModuleTests.java | 10 +- .../indices/recovery/RecoveryStatusTests.java | 4 +- .../ShardSnapshotTaskRunnerTests.java | 3 +- .../org/elasticsearch/test/ESTestCase.java | 3 +- ...SearchableSnapshotDirectoryStatsTests.java | 3 +- .../SearchableSnapshotDirectoryTests.java | 3 +- .../CachedBlobContainerIndexInputTests.java | 6 +- .../store/input/FrozenIndexInputTests.java | 3 +- .../plan/SnapshotsRecoveryPlannerService.java | 3 +- .../SnapshotsRecoveryPlannerServiceTests.java | 9 +- 32 files changed, 273 insertions(+), 266 deletions(-) diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BwcVersions.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BwcVersions.java index a76b211cf582d..738b328d50650 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BwcVersions.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BwcVersions.java @@ -96,6 +96,7 @@ public BwcVersions(Version currentVersionProperty, List allVersions } private static List parseVersionLines(List versionLines) { + return versionLines.stream() .map(LINE_PATTERN::matcher) .filter(Matcher::matches) diff --git a/qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/upgrades/FullClusterRestartIT.java b/qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/upgrades/FullClusterRestartIT.java index 3f9a007e6bf4e..5162d0f48505a 100644 --- a/qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/upgrades/FullClusterRestartIT.java +++ b/qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/upgrades/FullClusterRestartIT.java @@ -26,6 +26,7 @@ import org.elasticsearch.core.Booleans; import org.elasticsearch.core.CheckedFunction; import org.elasticsearch.index.IndexSettings; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.mapper.DateFieldMapper; import org.elasticsearch.rest.action.admin.indices.RestPutIndexTemplateAction; import org.elasticsearch.test.NotEqualMessageBuilder; @@ -958,9 +959,9 @@ public void testRecovery() throws Exception { 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 = Version.CURRENT.luceneVersion.toString(); - String bwcLuceneVersion = getOldClusterVersion().luceneVersion.toString(); - String minCompatibleBWCVersion = Version.CURRENT.minimumCompatibilityVersion().luceneVersion.toString(); + String currentLuceneVersion = IndexVersion.CURRENT.luceneVersion.toString(); + String bwcLuceneVersion = getOldClusterVersion().luceneVersion().toString(); + String minCompatibleBWCVersion = Version.CURRENT.minimumCompatibilityVersion().luceneVersion().toString(); if (shouldHaveTranslog && false == currentLuceneVersion.equals(bwcLuceneVersion)) { int numCurrentVersion = 0; int numBwcVersion = 0; diff --git a/qa/verify-version-constants/src/test/java/org/elasticsearch/qa/verify_version_constants/VerifyVersionConstantsIT.java b/qa/verify-version-constants/src/test/java/org/elasticsearch/qa/verify_version_constants/VerifyVersionConstantsIT.java index 801270ba89737..145d150ca61d5 100644 --- a/qa/verify-version-constants/src/test/java/org/elasticsearch/qa/verify_version_constants/VerifyVersionConstantsIT.java +++ b/qa/verify-version-constants/src/test/java/org/elasticsearch/qa/verify_version_constants/VerifyVersionConstantsIT.java @@ -32,7 +32,7 @@ public void testLuceneVersionConstant() throws IOException, ParseException { final Version elasticsearchVersion = Version.fromString(elasticsearchVersionString.replace("-SNAPSHOT", "")); final String luceneVersionString = objectPath.evaluate("version.lucene_version").toString(); final org.apache.lucene.util.Version luceneVersion = org.apache.lucene.util.Version.parse(luceneVersionString); - assertThat(elasticsearchVersion.luceneVersion, equalTo(luceneVersion)); + assertThat(elasticsearchVersion.luceneVersion(), equalTo(luceneVersion)); } @Override diff --git a/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/plan/ShardSnapshotsServiceIT.java b/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/plan/ShardSnapshotsServiceIT.java index a1439c3d5fa06..842a83589b625 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/plan/ShardSnapshotsServiceIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/plan/ShardSnapshotsServiceIT.java @@ -20,6 +20,7 @@ import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.core.Tuple; import org.elasticsearch.env.Environment; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot; import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshots; @@ -192,7 +193,7 @@ public void testOnlyFetchesSnapshotFromEnabledRepositories() throws Exception { assertThat(commitVersion, is(equalTo(Version.CURRENT))); final org.apache.lucene.util.Version commitLuceneVersion = shardSnapshotData.getCommitLuceneVersion(); assertThat(commitLuceneVersion, is(notNullValue())); - assertThat(commitLuceneVersion, is(equalTo(Version.CURRENT.luceneVersion))); + assertThat(commitLuceneVersion, is(equalTo(IndexVersion.CURRENT.luceneVersion))); assertThat(shardSnapshotInfo.getShardId(), is(equalTo(shardId))); assertThat(shardSnapshotInfo.getSnapshot().getSnapshotId().getName(), is(equalTo(snapshotName))); diff --git a/server/src/main/java/org/elasticsearch/Version.java b/server/src/main/java/org/elasticsearch/Version.java index 3955623472c42..c0cb1e5a606e4 100644 --- a/server/src/main/java/org/elasticsearch/Version.java +++ b/server/src/main/java/org/elasticsearch/Version.java @@ -14,6 +14,7 @@ import org.elasticsearch.core.Assertions; import org.elasticsearch.core.RestApiVersion; import org.elasticsearch.core.SuppressForbidden; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.monitor.jvm.JvmInfo; import org.elasticsearch.xcontent.ToXContentFragment; import org.elasticsearch.xcontent.XContentBuilder; @@ -31,7 +32,6 @@ import java.util.Objects; import java.util.TreeMap; -@SuppressWarnings("checkstyle:linelength") public class Version implements Comparable, ToXContentFragment { /* * The logic for ID is: XXYYZZAA, where XX is major version, YY is minor version, ZZ is revision, and AA is alpha/beta/rc indicator AA @@ -50,96 +50,96 @@ public class Version implements Comparable, ToXContentFragment { */ public static final int V_EMPTY_ID = 0; - public static final Version V_EMPTY = new Version(V_EMPTY_ID, TransportVersion.ZERO, org.apache.lucene.util.Version.LATEST); - public static final Version V_7_0_0 = new Version(7_00_00_99, TransportVersion.V_7_0_0, org.apache.lucene.util.Version.LUCENE_8_0_0); - public static final Version V_7_0_1 = new Version(7_00_01_99, TransportVersion.V_7_0_1, org.apache.lucene.util.Version.LUCENE_8_0_0); - public static final Version V_7_1_0 = new Version(7_01_00_99, TransportVersion.V_7_1_0, org.apache.lucene.util.Version.LUCENE_8_0_0); - public static final Version V_7_1_1 = new Version(7_01_01_99, TransportVersion.V_7_1_1, org.apache.lucene.util.Version.LUCENE_8_0_0); - public static final Version V_7_2_0 = new Version(7_02_00_99, TransportVersion.V_7_2_0, org.apache.lucene.util.Version.LUCENE_8_0_0); - public static final Version V_7_2_1 = new Version(7_02_01_99, TransportVersion.V_7_2_1, org.apache.lucene.util.Version.LUCENE_8_0_0); - public static final Version V_7_3_0 = new Version(7_03_00_99, TransportVersion.V_7_3_0, org.apache.lucene.util.Version.LUCENE_8_1_0); - public static final Version V_7_3_1 = new Version(7_03_01_99, TransportVersion.V_7_3_1, org.apache.lucene.util.Version.LUCENE_8_1_0); - public static final Version V_7_3_2 = new Version(7_03_02_99, TransportVersion.V_7_3_2, org.apache.lucene.util.Version.LUCENE_8_1_0); - public static final Version V_7_4_0 = new Version(7_04_00_99, TransportVersion.V_7_4_0, org.apache.lucene.util.Version.LUCENE_8_2_0); - public static final Version V_7_4_1 = new Version(7_04_01_99, TransportVersion.V_7_4_1, org.apache.lucene.util.Version.LUCENE_8_2_0); - public static final Version V_7_4_2 = new Version(7_04_02_99, TransportVersion.V_7_4_2, org.apache.lucene.util.Version.LUCENE_8_2_0); - public static final Version V_7_5_0 = new Version(7_05_00_99, TransportVersion.V_7_5_0, org.apache.lucene.util.Version.LUCENE_8_3_0); - public static final Version V_7_5_1 = new Version(7_05_01_99, TransportVersion.V_7_5_1, org.apache.lucene.util.Version.LUCENE_8_3_0); - public static final Version V_7_5_2 = new Version(7_05_02_99, TransportVersion.V_7_5_2, org.apache.lucene.util.Version.LUCENE_8_3_0); - public static final Version V_7_6_0 = new Version(7_06_00_99, TransportVersion.V_7_6_0, org.apache.lucene.util.Version.LUCENE_8_4_0); - public static final Version V_7_6_1 = new Version(7_06_01_99, TransportVersion.V_7_6_1, org.apache.lucene.util.Version.LUCENE_8_4_0); - public static final Version V_7_6_2 = new Version(7_06_02_99, TransportVersion.V_7_6_2, org.apache.lucene.util.Version.LUCENE_8_4_0); - public static final Version V_7_7_0 = new Version(7_07_00_99, TransportVersion.V_7_7_0, org.apache.lucene.util.Version.LUCENE_8_5_1); - public static final Version V_7_7_1 = new Version(7_07_01_99, TransportVersion.V_7_7_1, org.apache.lucene.util.Version.LUCENE_8_5_1); - public static final Version V_7_8_0 = new Version(7_08_00_99, TransportVersion.V_7_8_0, org.apache.lucene.util.Version.LUCENE_8_5_1); - public static final Version V_7_8_1 = new Version(7_08_01_99, TransportVersion.V_7_8_1, org.apache.lucene.util.Version.LUCENE_8_5_1); - public static final Version V_7_9_0 = new Version(7_09_00_99, TransportVersion.V_7_9_0, org.apache.lucene.util.Version.LUCENE_8_6_0); - public static final Version V_7_9_1 = new Version(7_09_01_99, TransportVersion.V_7_9_1, org.apache.lucene.util.Version.LUCENE_8_6_2); - public static final Version V_7_9_2 = new Version(7_09_02_99, TransportVersion.V_7_9_2, org.apache.lucene.util.Version.LUCENE_8_6_2); - public static final Version V_7_9_3 = new Version(7_09_03_99, TransportVersion.V_7_9_3, org.apache.lucene.util.Version.LUCENE_8_6_2); - public static final Version V_7_10_0 = new Version(7_10_00_99, TransportVersion.V_7_10_0, org.apache.lucene.util.Version.LUCENE_8_7_0); - public static final Version V_7_10_1 = new Version(7_10_01_99, TransportVersion.V_7_10_1, org.apache.lucene.util.Version.LUCENE_8_7_0); - public static final Version V_7_10_2 = new Version(7_10_02_99, TransportVersion.V_7_10_2, org.apache.lucene.util.Version.LUCENE_8_7_0); - public static final Version V_7_11_0 = new Version(7_11_00_99, TransportVersion.V_7_11_0, org.apache.lucene.util.Version.LUCENE_8_7_0); - public static final Version V_7_11_1 = new Version(7_11_01_99, TransportVersion.V_7_11_1, org.apache.lucene.util.Version.LUCENE_8_7_0); - public static final Version V_7_11_2 = new Version(7_11_02_99, TransportVersion.V_7_11_2, org.apache.lucene.util.Version.LUCENE_8_7_0); - public static final Version V_7_12_0 = new Version(7_12_00_99, TransportVersion.V_7_12_0, org.apache.lucene.util.Version.LUCENE_8_8_0); - public static final Version V_7_12_1 = new Version(7_12_01_99, TransportVersion.V_7_12_1, org.apache.lucene.util.Version.LUCENE_8_8_0); - public static final Version V_7_13_0 = new Version(7_13_00_99, TransportVersion.V_7_13_0, org.apache.lucene.util.Version.LUCENE_8_8_2); - public static final Version V_7_13_1 = new Version(7_13_01_99, TransportVersion.V_7_13_1, org.apache.lucene.util.Version.LUCENE_8_8_2); - public static final Version V_7_13_2 = new Version(7_13_02_99, TransportVersion.V_7_13_2, org.apache.lucene.util.Version.LUCENE_8_8_2); - public static final Version V_7_13_3 = new Version(7_13_03_99, TransportVersion.V_7_13_3, org.apache.lucene.util.Version.LUCENE_8_8_2); - public static final Version V_7_13_4 = new Version(7_13_04_99, TransportVersion.V_7_13_4, org.apache.lucene.util.Version.LUCENE_8_8_2); - public static final Version V_7_14_0 = new Version(7_14_00_99, TransportVersion.V_7_14_0, org.apache.lucene.util.Version.LUCENE_8_9_0); - public static final Version V_7_14_1 = new Version(7_14_01_99, TransportVersion.V_7_14_1, org.apache.lucene.util.Version.LUCENE_8_9_0); - public static final Version V_7_14_2 = new Version(7_14_02_99, TransportVersion.V_7_14_2, org.apache.lucene.util.Version.LUCENE_8_9_0); - public static final Version V_7_15_0 = new Version(7_15_00_99, TransportVersion.V_7_15_0, org.apache.lucene.util.Version.LUCENE_8_9_0); - public static final Version V_7_15_1 = new Version(7_15_01_99, TransportVersion.V_7_15_1, org.apache.lucene.util.Version.LUCENE_8_9_0); - public static final Version V_7_15_2 = new Version(7_15_02_99, TransportVersion.V_7_15_2, org.apache.lucene.util.Version.LUCENE_8_9_0); - public static final Version V_7_16_0 = new Version(7_16_00_99, TransportVersion.V_7_16_0, org.apache.lucene.util.Version.LUCENE_8_10_1); - public static final Version V_7_16_1 = new Version(7_16_01_99, TransportVersion.V_7_16_1, org.apache.lucene.util.Version.LUCENE_8_10_1); - public static final Version V_7_16_2 = new Version(7_16_02_99, TransportVersion.V_7_16_2, org.apache.lucene.util.Version.LUCENE_8_10_1); - public static final Version V_7_16_3 = new Version(7_16_03_99, TransportVersion.V_7_16_3, org.apache.lucene.util.Version.LUCENE_8_10_1); - public static final Version V_7_17_0 = new Version(7_17_00_99, TransportVersion.V_7_17_0, org.apache.lucene.util.Version.LUCENE_8_11_1); - public static final Version V_7_17_1 = new Version(7_17_01_99, TransportVersion.V_7_17_1, org.apache.lucene.util.Version.LUCENE_8_11_1); - public static final Version V_7_17_2 = new Version(7_17_02_99, TransportVersion.V_7_17_2, org.apache.lucene.util.Version.LUCENE_8_11_1); - public static final Version V_7_17_3 = new Version(7_17_03_99, TransportVersion.V_7_17_3, org.apache.lucene.util.Version.LUCENE_8_11_1); - public static final Version V_7_17_4 = new Version(7_17_04_99, TransportVersion.V_7_17_4, org.apache.lucene.util.Version.LUCENE_8_11_1); - public static final Version V_7_17_5 = new Version(7_17_05_99, TransportVersion.V_7_17_5, org.apache.lucene.util.Version.LUCENE_8_11_1); - public static final Version V_7_17_6 = new Version(7_17_06_99, TransportVersion.V_7_17_6, org.apache.lucene.util.Version.LUCENE_8_11_1); - public static final Version V_7_17_7 = new Version(7_17_07_99, TransportVersion.V_7_17_7, org.apache.lucene.util.Version.LUCENE_8_11_1); - public static final Version V_7_17_8 = new Version(7_17_08_99, TransportVersion.V_7_17_8, org.apache.lucene.util.Version.LUCENE_8_11_1); - public static final Version V_7_17_9 = new Version(7_17_09_99, TransportVersion.V_7_17_9, org.apache.lucene.util.Version.LUCENE_8_11_1); - public static final Version V_7_17_10 = new Version(7_17_10_99, TransportVersion.V_7_17_10, org.apache.lucene.util.Version.LUCENE_8_11_1); - public static final Version V_8_0_0 = new Version(8_00_00_99, TransportVersion.V_8_0_0, org.apache.lucene.util.Version.LUCENE_9_0_0); - public static final Version V_8_0_1 = new Version(8_00_01_99, TransportVersion.V_8_0_1, org.apache.lucene.util.Version.LUCENE_9_0_0); - public static final Version V_8_1_0 = new Version(8_01_00_99, TransportVersion.V_8_1_0, org.apache.lucene.util.Version.LUCENE_9_0_0); - public static final Version V_8_1_1 = new Version(8_01_01_99, TransportVersion.V_8_1_1, org.apache.lucene.util.Version.LUCENE_9_0_0); - public static final Version V_8_1_2 = new Version(8_01_02_99, TransportVersion.V_8_1_2, org.apache.lucene.util.Version.LUCENE_9_0_0); - public static final Version V_8_1_3 = new Version(8_01_03_99, TransportVersion.V_8_1_3, org.apache.lucene.util.Version.LUCENE_9_0_0); - public static final Version V_8_2_0 = new Version(8_02_00_99, TransportVersion.V_8_2_0, org.apache.lucene.util.Version.LUCENE_9_1_0); - public static final Version V_8_2_1 = new Version(8_02_01_99, TransportVersion.V_8_2_1, org.apache.lucene.util.Version.LUCENE_9_1_0); - public static final Version V_8_2_2 = new Version(8_02_02_99, TransportVersion.V_8_2_2, org.apache.lucene.util.Version.LUCENE_9_1_0); - public static final Version V_8_2_3 = new Version(8_02_03_99, TransportVersion.V_8_2_3, org.apache.lucene.util.Version.LUCENE_9_1_0); - public static final Version V_8_3_0 = new Version(8_03_00_99, TransportVersion.V_8_3_0, org.apache.lucene.util.Version.LUCENE_9_2_0); - public static final Version V_8_3_1 = new Version(8_03_01_99, TransportVersion.V_8_3_1, org.apache.lucene.util.Version.LUCENE_9_2_0); - public static final Version V_8_3_2 = new Version(8_03_02_99, TransportVersion.V_8_3_2, org.apache.lucene.util.Version.LUCENE_9_2_0); - public static final Version V_8_3_3 = new Version(8_03_03_99, TransportVersion.V_8_3_3, org.apache.lucene.util.Version.LUCENE_9_2_0); - public static final Version V_8_4_0 = new Version(8_04_00_99, TransportVersion.V_8_4_0, org.apache.lucene.util.Version.LUCENE_9_3_0); - public static final Version V_8_4_1 = new Version(8_04_01_99, TransportVersion.V_8_4_1, org.apache.lucene.util.Version.LUCENE_9_3_0); - public static final Version V_8_4_2 = new Version(8_04_02_99, TransportVersion.V_8_4_2, org.apache.lucene.util.Version.LUCENE_9_3_0); - public static final Version V_8_4_3 = new Version(8_04_03_99, TransportVersion.V_8_4_3, org.apache.lucene.util.Version.LUCENE_9_3_0); - public static final Version V_8_5_0 = new Version(8_05_00_99, TransportVersion.V_8_5_0, org.apache.lucene.util.Version.LUCENE_9_4_1); - public static final Version V_8_5_1 = new Version(8_05_01_99, TransportVersion.V_8_5_1, org.apache.lucene.util.Version.LUCENE_9_4_1); - public static final Version V_8_5_2 = new Version(8_05_02_99, TransportVersion.V_8_5_2, org.apache.lucene.util.Version.LUCENE_9_4_1); - public static final Version V_8_5_3 = new Version(8_05_03_99, TransportVersion.V_8_5_3, org.apache.lucene.util.Version.LUCENE_9_4_2); - public static final Version V_8_6_0 = new Version(8_06_00_99, TransportVersion.V_8_6_0, org.apache.lucene.util.Version.LUCENE_9_4_2); - public static final Version V_8_6_1 = new Version(8_06_01_99, TransportVersion.V_8_6_1, org.apache.lucene.util.Version.LUCENE_9_4_2); - public static final Version V_8_6_2 = new Version(8_06_02_99, TransportVersion.V_8_6_2, org.apache.lucene.util.Version.LUCENE_9_4_2); - public static final Version V_8_6_3 = new Version(8_06_03_99, TransportVersion.V_8_6_3, org.apache.lucene.util.Version.LUCENE_9_4_2); - public static final Version V_8_7_0 = new Version(8_07_00_99, TransportVersion.V_8_7_0, org.apache.lucene.util.Version.LUCENE_9_5_0); - - public static final Version V_8_8_0 = new Version(8_08_00_99, TransportVersion.V_8_8_0, org.apache.lucene.util.Version.LUCENE_9_6_0); + public static final Version V_EMPTY = new Version(V_EMPTY_ID, TransportVersion.ZERO, IndexVersion.ZERO); + public static final Version V_7_0_0 = new Version(7_00_00_99, TransportVersion.V_7_0_0, IndexVersion.V_7_0_0); + public static final Version V_7_0_1 = new Version(7_00_01_99, TransportVersion.V_7_0_1, IndexVersion.V_7_0_1); + public static final Version V_7_1_0 = new Version(7_01_00_99, TransportVersion.V_7_1_0, IndexVersion.V_7_1_0); + public static final Version V_7_1_1 = new Version(7_01_01_99, TransportVersion.V_7_1_1, IndexVersion.V_7_1_1); + public static final Version V_7_2_0 = new Version(7_02_00_99, TransportVersion.V_7_2_0, IndexVersion.V_7_2_0); + public static final Version V_7_2_1 = new Version(7_02_01_99, TransportVersion.V_7_2_1, IndexVersion.V_7_2_1); + public static final Version V_7_3_0 = new Version(7_03_00_99, TransportVersion.V_7_3_0, IndexVersion.V_7_3_0); + public static final Version V_7_3_1 = new Version(7_03_01_99, TransportVersion.V_7_3_1, IndexVersion.V_7_3_1); + public static final Version V_7_3_2 = new Version(7_03_02_99, TransportVersion.V_7_3_2, IndexVersion.V_7_3_2); + public static final Version V_7_4_0 = new Version(7_04_00_99, TransportVersion.V_7_4_0, IndexVersion.V_7_4_0); + public static final Version V_7_4_1 = new Version(7_04_01_99, TransportVersion.V_7_4_1, IndexVersion.V_7_4_1); + public static final Version V_7_4_2 = new Version(7_04_02_99, TransportVersion.V_7_4_2, IndexVersion.V_7_4_2); + public static final Version V_7_5_0 = new Version(7_05_00_99, TransportVersion.V_7_5_0, IndexVersion.V_7_5_0); + public static final Version V_7_5_1 = new Version(7_05_01_99, TransportVersion.V_7_5_1, IndexVersion.V_7_5_1); + public static final Version V_7_5_2 = new Version(7_05_02_99, TransportVersion.V_7_5_2, IndexVersion.V_7_5_2); + public static final Version V_7_6_0 = new Version(7_06_00_99, TransportVersion.V_7_6_0, IndexVersion.V_7_6_0); + public static final Version V_7_6_1 = new Version(7_06_01_99, TransportVersion.V_7_6_1, IndexVersion.V_7_6_1); + public static final Version V_7_6_2 = new Version(7_06_02_99, TransportVersion.V_7_6_2, IndexVersion.V_7_6_2); + public static final Version V_7_7_0 = new Version(7_07_00_99, TransportVersion.V_7_7_0, IndexVersion.V_7_7_0); + public static final Version V_7_7_1 = new Version(7_07_01_99, TransportVersion.V_7_7_1, IndexVersion.V_7_7_1); + public static final Version V_7_8_0 = new Version(7_08_00_99, TransportVersion.V_7_8_0, IndexVersion.V_7_8_0); + public static final Version V_7_8_1 = new Version(7_08_01_99, TransportVersion.V_7_8_1, IndexVersion.V_7_8_1); + public static final Version V_7_9_0 = new Version(7_09_00_99, TransportVersion.V_7_9_0, IndexVersion.V_7_9_0); + public static final Version V_7_9_1 = new Version(7_09_01_99, TransportVersion.V_7_9_1, IndexVersion.V_7_9_1); + public static final Version V_7_9_2 = new Version(7_09_02_99, TransportVersion.V_7_9_2, IndexVersion.V_7_9_2); + public static final Version V_7_9_3 = new Version(7_09_03_99, TransportVersion.V_7_9_3, IndexVersion.V_7_9_3); + public static final Version V_7_10_0 = new Version(7_10_00_99, TransportVersion.V_7_10_0, IndexVersion.V_7_10_0); + public static final Version V_7_10_1 = new Version(7_10_01_99, TransportVersion.V_7_10_1, IndexVersion.V_7_10_1); + public static final Version V_7_10_2 = new Version(7_10_02_99, TransportVersion.V_7_10_2, IndexVersion.V_7_10_2); + public static final Version V_7_11_0 = new Version(7_11_00_99, TransportVersion.V_7_11_0, IndexVersion.V_7_11_0); + public static final Version V_7_11_1 = new Version(7_11_01_99, TransportVersion.V_7_11_1, IndexVersion.V_7_11_1); + public static final Version V_7_11_2 = new Version(7_11_02_99, TransportVersion.V_7_11_2, IndexVersion.V_7_11_2); + public static final Version V_7_12_0 = new Version(7_12_00_99, TransportVersion.V_7_12_0, IndexVersion.V_7_12_0); + public static final Version V_7_12_1 = new Version(7_12_01_99, TransportVersion.V_7_12_1, IndexVersion.V_7_12_1); + public static final Version V_7_13_0 = new Version(7_13_00_99, TransportVersion.V_7_13_0, IndexVersion.V_7_13_0); + public static final Version V_7_13_1 = new Version(7_13_01_99, TransportVersion.V_7_13_1, IndexVersion.V_7_13_1); + public static final Version V_7_13_2 = new Version(7_13_02_99, TransportVersion.V_7_13_2, IndexVersion.V_7_13_2); + public static final Version V_7_13_3 = new Version(7_13_03_99, TransportVersion.V_7_13_3, IndexVersion.V_7_13_3); + public static final Version V_7_13_4 = new Version(7_13_04_99, TransportVersion.V_7_13_4, IndexVersion.V_7_13_4); + public static final Version V_7_14_0 = new Version(7_14_00_99, TransportVersion.V_7_14_0, IndexVersion.V_7_14_0); + public static final Version V_7_14_1 = new Version(7_14_01_99, TransportVersion.V_7_14_1, IndexVersion.V_7_14_1); + public static final Version V_7_14_2 = new Version(7_14_02_99, TransportVersion.V_7_14_2, IndexVersion.V_7_14_2); + public static final Version V_7_15_0 = new Version(7_15_00_99, TransportVersion.V_7_15_0, IndexVersion.V_7_15_0); + public static final Version V_7_15_1 = new Version(7_15_01_99, TransportVersion.V_7_15_1, IndexVersion.V_7_15_1); + public static final Version V_7_15_2 = new Version(7_15_02_99, TransportVersion.V_7_15_2, IndexVersion.V_7_15_2); + public static final Version V_7_16_0 = new Version(7_16_00_99, TransportVersion.V_7_16_0, IndexVersion.V_7_16_0); + public static final Version V_7_16_1 = new Version(7_16_01_99, TransportVersion.V_7_16_1, IndexVersion.V_7_16_1); + public static final Version V_7_16_2 = new Version(7_16_02_99, TransportVersion.V_7_16_2, IndexVersion.V_7_16_2); + public static final Version V_7_16_3 = new Version(7_16_03_99, TransportVersion.V_7_16_3, IndexVersion.V_7_16_3); + public static final Version V_7_17_0 = new Version(7_17_00_99, TransportVersion.V_7_17_0, IndexVersion.V_7_17_0); + public static final Version V_7_17_1 = new Version(7_17_01_99, TransportVersion.V_7_17_1, IndexVersion.V_7_17_1); + public static final Version V_7_17_2 = new Version(7_17_02_99, TransportVersion.V_7_17_2, IndexVersion.V_7_17_2); + public static final Version V_7_17_3 = new Version(7_17_03_99, TransportVersion.V_7_17_3, IndexVersion.V_7_17_3); + public static final Version V_7_17_4 = new Version(7_17_04_99, TransportVersion.V_7_17_4, IndexVersion.V_7_17_4); + public static final Version V_7_17_5 = new Version(7_17_05_99, TransportVersion.V_7_17_5, IndexVersion.V_7_17_5); + public static final Version V_7_17_6 = new Version(7_17_06_99, TransportVersion.V_7_17_6, IndexVersion.V_7_17_6); + public static final Version V_7_17_7 = new Version(7_17_07_99, TransportVersion.V_7_17_7, IndexVersion.V_7_17_7); + public static final Version V_7_17_8 = new Version(7_17_08_99, TransportVersion.V_7_17_8, IndexVersion.V_7_17_8); + public static final Version V_7_17_9 = new Version(7_17_09_99, TransportVersion.V_7_17_9, IndexVersion.V_7_17_9); + public static final Version V_7_17_10 = new Version(7_17_10_99, TransportVersion.V_7_17_10, IndexVersion.V_7_17_10); + public static final Version V_8_0_0 = new Version(8_00_00_99, TransportVersion.V_8_0_0, IndexVersion.V_8_0_0); + public static final Version V_8_0_1 = new Version(8_00_01_99, TransportVersion.V_8_0_1, IndexVersion.V_8_0_1); + public static final Version V_8_1_0 = new Version(8_01_00_99, TransportVersion.V_8_1_0, IndexVersion.V_8_1_0); + public static final Version V_8_1_1 = new Version(8_01_01_99, TransportVersion.V_8_1_1, IndexVersion.V_8_1_1); + public static final Version V_8_1_2 = new Version(8_01_02_99, TransportVersion.V_8_1_2, IndexVersion.V_8_1_2); + public static final Version V_8_1_3 = new Version(8_01_03_99, TransportVersion.V_8_1_3, IndexVersion.V_8_1_3); + public static final Version V_8_2_0 = new Version(8_02_00_99, TransportVersion.V_8_2_0, IndexVersion.V_8_2_0); + public static final Version V_8_2_1 = new Version(8_02_01_99, TransportVersion.V_8_2_1, IndexVersion.V_8_2_1); + public static final Version V_8_2_2 = new Version(8_02_02_99, TransportVersion.V_8_2_2, IndexVersion.V_8_2_2); + public static final Version V_8_2_3 = new Version(8_02_03_99, TransportVersion.V_8_2_3, IndexVersion.V_8_2_3); + public static final Version V_8_3_0 = new Version(8_03_00_99, TransportVersion.V_8_3_0, IndexVersion.V_8_3_0); + public static final Version V_8_3_1 = new Version(8_03_01_99, TransportVersion.V_8_3_1, IndexVersion.V_8_3_1); + public static final Version V_8_3_2 = new Version(8_03_02_99, TransportVersion.V_8_3_2, IndexVersion.V_8_3_2); + public static final Version V_8_3_3 = new Version(8_03_03_99, TransportVersion.V_8_3_3, IndexVersion.V_8_3_3); + public static final Version V_8_4_0 = new Version(8_04_00_99, TransportVersion.V_8_4_0, IndexVersion.V_8_4_0); + public static final Version V_8_4_1 = new Version(8_04_01_99, TransportVersion.V_8_4_1, IndexVersion.V_8_4_1); + public static final Version V_8_4_2 = new Version(8_04_02_99, TransportVersion.V_8_4_2, IndexVersion.V_8_4_2); + public static final Version V_8_4_3 = new Version(8_04_03_99, TransportVersion.V_8_4_3, IndexVersion.V_8_4_3); + public static final Version V_8_5_0 = new Version(8_05_00_99, TransportVersion.V_8_5_0, IndexVersion.V_8_5_0); + public static final Version V_8_5_1 = new Version(8_05_01_99, TransportVersion.V_8_5_1, IndexVersion.V_8_5_1); + public static final Version V_8_5_2 = new Version(8_05_02_99, TransportVersion.V_8_5_2, IndexVersion.V_8_5_2); + public static final Version V_8_5_3 = new Version(8_05_03_99, TransportVersion.V_8_5_3, IndexVersion.V_8_5_3); + public static final Version V_8_6_0 = new Version(8_06_00_99, TransportVersion.V_8_6_0, IndexVersion.V_8_6_0); + public static final Version V_8_6_1 = new Version(8_06_01_99, TransportVersion.V_8_6_1, IndexVersion.V_8_6_1); + public static final Version V_8_6_2 = new Version(8_06_02_99, TransportVersion.V_8_6_2, IndexVersion.V_8_6_2); + public static final Version V_8_6_3 = new Version(8_06_03_99, TransportVersion.V_8_6_3, IndexVersion.V_8_6_3); + public static final Version V_8_7_0 = new Version(8_07_00_99, TransportVersion.V_8_7_0, IndexVersion.V_8_7_0); + + public static final Version V_8_8_0 = new Version(8_08_00_99, TransportVersion.V_8_8_0, IndexVersion.V_8_8_0); public static final Version CURRENT = V_8_8_0; private static final NavigableMap VERSION_IDS; @@ -176,8 +176,6 @@ public class Version implements Comparable, ToXContentFragment { } } } - assert CURRENT.luceneVersion.equals(org.apache.lucene.util.Version.LATEST) - : "Version must be upgraded to [" + org.apache.lucene.util.Version.LATEST + "] is still set to [" + CURRENT.luceneVersion + "]"; assert RestApiVersion.current().major == CURRENT.major && RestApiVersion.previous().major == CURRENT.major - 1 : "RestApiVersion must be upgraded " + "to reflect major from Version.CURRENT [" @@ -206,28 +204,9 @@ public static Version fromId(int id) { } private static Version fromIdSlow(int id) { - // We need at least the major of the Lucene version to be correct. - // Our best guess is to use the same Lucene version as the previous - // version in the list, assuming that it didn't change. - List versions = DeclaredVersionsHolder.DECLARED_VERSIONS; - Version tmp = new Version(id, TransportVersion.CURRENT, org.apache.lucene.util.Version.LATEST); - int index = Collections.binarySearch(versions, tmp); - if (index < 0) { - index = -2 - index; - } else { - assert false : "Version [" + tmp + "] is declared but absent from the switch statement in Version#fromId"; - } - final org.apache.lucene.util.Version luceneVersion; - if (index == -1) { - // this version is older than any supported version, so we - // assume it is the previous major to the oldest Lucene version - // that we know about - luceneVersion = org.apache.lucene.util.Version.fromBits(versions.get(0).luceneVersion.major - 1, 0, 0); - } else { - luceneVersion = versions.get(index).luceneVersion; - } // TODO: assume this is an old version that has transport version == release version - return new Version(id, TransportVersion.fromId(id), luceneVersion); + // TODO: assume this is an old version that has index version == release version + return new Version(id, TransportVersion.fromId(id), IndexVersion.fromId(id)); } public static void writeVersion(Version version, StreamOutput out) throws IOException { @@ -311,18 +290,18 @@ private static Version fromStringSlow(String version) { public final byte revision; public final byte build; public final TransportVersion transportVersion; - public final org.apache.lucene.util.Version luceneVersion; + public final IndexVersion indexVersion; private final String toString; private final int previousMajorId; - Version(int id, TransportVersion transportVersion, org.apache.lucene.util.Version luceneVersion) { + Version(int id, TransportVersion transportVersion, IndexVersion indexVersion) { this.id = id; this.major = (byte) ((id / 1000000) % 100); this.minor = (byte) ((id / 10000) % 100); this.revision = (byte) ((id / 100) % 100); this.build = (byte) (id % 100); this.transportVersion = Objects.requireNonNull(transportVersion); - this.luceneVersion = Objects.requireNonNull(luceneVersion); + this.indexVersion = Objects.requireNonNull(indexVersion); this.toString = major + "." + minor + "." + revision; this.previousMajorId = major > 0 ? (major - 1) * 1000000 + 99 : major; } @@ -353,6 +332,10 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws return builder.value(toString()); } + public org.apache.lucene.util.Version luceneVersion() { + return indexVersion.luceneVersion; + } + /* * We need the declared versions when computing the minimum compatibility version. As computing the declared versions uses reflection it * is not cheap. Since computing the minimum compatibility version can occur often, we use this holder to compute the declared versions diff --git a/server/src/main/java/org/elasticsearch/action/main/MainResponse.java b/server/src/main/java/org/elasticsearch/action/main/MainResponse.java index 445b78b0029da..7b6b45942763b 100644 --- a/server/src/main/java/org/elasticsearch/action/main/MainResponse.java +++ b/server/src/main/java/org/elasticsearch/action/main/MainResponse.java @@ -92,7 +92,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws .field("build_hash", build.hash()) .field("build_date", build.date()) .field("build_snapshot", build.isSnapshot()) - .field("lucene_version", version.luceneVersion.toString()) + .field("lucene_version", version.luceneVersion().toString()) .field("minimum_wire_compatibility_version", version.minimumCompatibilityVersion().toString()) .field("minimum_index_compatibility_version", version.minimumIndexCompatibilityVersion().toString()) .endObject(); diff --git a/server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java b/server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java index bfaf712d4872f..e29928334bb63 100644 --- a/server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java +++ b/server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java @@ -27,6 +27,7 @@ import org.elasticsearch.core.IOUtils; import org.elasticsearch.core.SuppressForbidden; import org.elasticsearch.env.Environment; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.jdk.JarHell; import org.elasticsearch.monitor.jvm.HotThreads; import org.elasticsearch.monitor.jvm.JvmInfo; @@ -322,10 +323,10 @@ static void initializeProbes() { } static void checkLucene() { - if (Version.CURRENT.luceneVersion.equals(org.apache.lucene.util.Version.LATEST) == false) { + if (IndexVersion.CURRENT.luceneVersion.equals(org.apache.lucene.util.Version.LATEST) == false) { throw new AssertionError( "Lucene version mismatch this version of Elasticsearch requires lucene version [" - + Version.CURRENT.luceneVersion + + IndexVersion.CURRENT.luceneVersion + "] but the current lucene version is [" + org.apache.lucene.util.Version.LATEST + "]" diff --git a/server/src/main/java/org/elasticsearch/index/IndexVersion.java b/server/src/main/java/org/elasticsearch/index/IndexVersion.java index 87ae520b7f35d..7f23591edfabb 100644 --- a/server/src/main/java/org/elasticsearch/index/IndexVersion.java +++ b/server/src/main/java/org/elasticsearch/index/IndexVersion.java @@ -31,95 +31,94 @@ @SuppressWarnings("checkstyle:linelength") public final class IndexVersion implements Comparable { public static final IndexVersion ZERO = new IndexVersion(0, Version.LATEST, "00000000-0000-0000-0000-000000000000"); - public static final IndexVersion V_7_0_0 = new IndexVersion(7_00_00_99, Version.LUCENE_8_0_0); - public static final IndexVersion V_7_0_1 = new IndexVersion(7_00_01_99, Version.LUCENE_8_0_0); - public static final IndexVersion V_7_1_0 = new IndexVersion(7_01_00_99, Version.LUCENE_8_0_0); - public static final IndexVersion V_7_1_1 = new IndexVersion(7_01_01_99, Version.LUCENE_8_0_0); - public static final IndexVersion V_7_2_0 = new IndexVersion(7_02_00_99, Version.LUCENE_8_0_0); - public static final IndexVersion V_7_2_1 = new IndexVersion(7_02_01_99, Version.LUCENE_8_0_0); - public static final IndexVersion V_7_3_0 = new IndexVersion(7_03_00_99, Version.LUCENE_8_1_0); - public static final IndexVersion V_7_3_1 = new IndexVersion(7_03_01_99, Version.LUCENE_8_1_0); - public static final IndexVersion V_7_3_2 = new IndexVersion(7_03_02_99, Version.LUCENE_8_1_0); - public static final IndexVersion V_7_4_0 = new IndexVersion(7_04_00_99, Version.LUCENE_8_2_0); - public static final IndexVersion V_7_4_1 = new IndexVersion(7_04_01_99, Version.LUCENE_8_2_0); - public static final IndexVersion V_7_4_2 = new IndexVersion(7_04_02_99, Version.LUCENE_8_2_0); - public static final IndexVersion V_7_5_0 = new IndexVersion(7_05_00_99, Version.LUCENE_8_3_0); - public static final IndexVersion V_7_5_1 = new IndexVersion(7_05_01_99, Version.LUCENE_8_3_0); - public static final IndexVersion V_7_5_2 = new IndexVersion(7_05_02_99, Version.LUCENE_8_3_0); - public static final IndexVersion V_7_6_0 = new IndexVersion(7_06_00_99, Version.LUCENE_8_4_0); - public static final IndexVersion V_7_6_1 = new IndexVersion(7_06_01_99, Version.LUCENE_8_4_0); - public static final IndexVersion V_7_6_2 = new IndexVersion(7_06_02_99, Version.LUCENE_8_4_0); - public static final IndexVersion V_7_7_0 = new IndexVersion(7_07_00_99, Version.LUCENE_8_5_1); - public static final IndexVersion V_7_7_1 = new IndexVersion(7_07_01_99, Version.LUCENE_8_5_1); - public static final IndexVersion V_7_8_0 = new IndexVersion(7_08_00_99, Version.LUCENE_8_5_1); - public static final IndexVersion V_7_8_1 = new IndexVersion(7_08_01_99, Version.LUCENE_8_5_1); - public static final IndexVersion V_7_9_0 = new IndexVersion(7_09_00_99, Version.LUCENE_8_6_0); - public static final IndexVersion V_7_9_1 = new IndexVersion(7_09_01_99, Version.LUCENE_8_6_2); - public static final IndexVersion V_7_9_2 = new IndexVersion(7_09_02_99, Version.LUCENE_8_6_2); - public static final IndexVersion V_7_9_3 = new IndexVersion(7_09_03_99, Version.LUCENE_8_6_2); - public static final IndexVersion V_7_10_0 = new IndexVersion(7_10_00_99, Version.LUCENE_8_7_0); - public static final IndexVersion V_7_10_1 = new IndexVersion(7_10_01_99, Version.LUCENE_8_7_0); - public static final IndexVersion V_7_10_2 = new IndexVersion(7_10_02_99, Version.LUCENE_8_7_0); - public static final IndexVersion V_7_11_0 = new IndexVersion(7_11_00_99, Version.LUCENE_8_7_0); - public static final IndexVersion V_7_11_1 = new IndexVersion(7_11_01_99, Version.LUCENE_8_7_0); - public static final IndexVersion V_7_11_2 = new IndexVersion(7_11_02_99, Version.LUCENE_8_7_0); - public static final IndexVersion V_7_12_0 = new IndexVersion(7_12_00_99, Version.LUCENE_8_8_0); - public static final IndexVersion V_7_12_1 = new IndexVersion(7_12_01_99, Version.LUCENE_8_8_0); - public static final IndexVersion V_7_13_0 = new IndexVersion(7_13_00_99, Version.LUCENE_8_8_2); - public static final IndexVersion V_7_13_1 = new IndexVersion(7_13_01_99, Version.LUCENE_8_8_2); - public static final IndexVersion V_7_13_2 = new IndexVersion(7_13_02_99, Version.LUCENE_8_8_2); - public static final IndexVersion V_7_13_3 = new IndexVersion(7_13_03_99, Version.LUCENE_8_8_2); - public static final IndexVersion V_7_13_4 = new IndexVersion(7_13_04_99, Version.LUCENE_8_8_2); - public static final IndexVersion V_7_14_0 = new IndexVersion(7_14_00_99, Version.LUCENE_8_9_0); - public static final IndexVersion V_7_14_1 = new IndexVersion(7_14_01_99, Version.LUCENE_8_9_0); - public static final IndexVersion V_7_14_2 = new IndexVersion(7_14_02_99, Version.LUCENE_8_9_0); - public static final IndexVersion V_7_15_0 = new IndexVersion(7_15_00_99, Version.LUCENE_8_9_0); - public static final IndexVersion V_7_15_1 = new IndexVersion(7_15_01_99, Version.LUCENE_8_9_0); - public static final IndexVersion V_7_15_2 = new IndexVersion(7_15_02_99, Version.LUCENE_8_9_0); - public static final IndexVersion V_7_16_0 = new IndexVersion(7_16_00_99, Version.LUCENE_8_10_1); - public static final IndexVersion V_7_16_1 = new IndexVersion(7_16_01_99, Version.LUCENE_8_10_1); - public static final IndexVersion V_7_16_2 = new IndexVersion(7_16_02_99, Version.LUCENE_8_10_1); - public static final IndexVersion V_7_16_3 = new IndexVersion(7_16_03_99, Version.LUCENE_8_10_1); - public static final IndexVersion V_7_17_0 = new IndexVersion(7_17_00_99, Version.LUCENE_8_11_1); - public static final IndexVersion V_7_17_1 = new IndexVersion(7_17_01_99, Version.LUCENE_8_11_1); - public static final IndexVersion V_7_17_2 = new IndexVersion(7_17_02_99, Version.LUCENE_8_11_1); - public static final IndexVersion V_7_17_3 = new IndexVersion(7_17_03_99, Version.LUCENE_8_11_1); - public static final IndexVersion V_7_17_4 = new IndexVersion(7_17_04_99, Version.LUCENE_8_11_1); - public static final IndexVersion V_7_17_5 = new IndexVersion(7_17_05_99, Version.LUCENE_8_11_1); - public static final IndexVersion V_7_17_6 = new IndexVersion(7_17_06_99, Version.LUCENE_8_11_1); - public static final IndexVersion V_7_17_7 = new IndexVersion(7_17_07_99, Version.LUCENE_8_11_1); - public static final IndexVersion V_7_17_8 = new IndexVersion(7_17_08_99, Version.LUCENE_8_11_1); - public static final IndexVersion V_7_17_9 = new IndexVersion(7_17_09_99, Version.LUCENE_8_11_1); - public static final IndexVersion V_7_17_10 = new IndexVersion(7_17_10_99, Version.LUCENE_8_11_1); - public static final IndexVersion V_8_0_0 = new IndexVersion(8_00_00_99, Version.LUCENE_9_0_0); - public static final IndexVersion V_8_0_1 = new IndexVersion(8_00_01_99, Version.LUCENE_9_0_0); - public static final IndexVersion V_8_1_0 = new IndexVersion(8_01_00_99, Version.LUCENE_9_0_0); - public static final IndexVersion V_8_1_1 = new IndexVersion(8_01_01_99, Version.LUCENE_9_0_0); - public static final IndexVersion V_8_1_2 = new IndexVersion(8_01_02_99, Version.LUCENE_9_0_0); - public static final IndexVersion V_8_1_3 = new IndexVersion(8_01_03_99, Version.LUCENE_9_0_0); - public static final IndexVersion V_8_2_0 = new IndexVersion(8_02_00_99, Version.LUCENE_9_1_0); - public static final IndexVersion V_8_2_1 = new IndexVersion(8_02_01_99, Version.LUCENE_9_1_0); - public static final IndexVersion V_8_2_2 = new IndexVersion(8_02_02_99, Version.LUCENE_9_1_0); - public static final IndexVersion V_8_2_3 = new IndexVersion(8_02_03_99, Version.LUCENE_9_1_0); - public static final IndexVersion V_8_3_0 = new IndexVersion(8_03_00_99, Version.LUCENE_9_2_0); - public static final IndexVersion V_8_3_1 = new IndexVersion(8_03_01_99, Version.LUCENE_9_2_0); - public static final IndexVersion V_8_3_2 = new IndexVersion(8_03_02_99, Version.LUCENE_9_2_0); - public static final IndexVersion V_8_3_3 = new IndexVersion(8_03_03_99, Version.LUCENE_9_2_0); - public static final IndexVersion V_8_4_0 = new IndexVersion(8_04_00_99, Version.LUCENE_9_3_0); - public static final IndexVersion V_8_4_1 = new IndexVersion(8_04_01_99, Version.LUCENE_9_3_0); - public static final IndexVersion V_8_4_2 = new IndexVersion(8_04_02_99, Version.LUCENE_9_3_0); - public static final IndexVersion V_8_4_3 = new IndexVersion(8_04_03_99, Version.LUCENE_9_3_0); - public static final IndexVersion V_8_5_0 = new IndexVersion(8_05_00_99, Version.LUCENE_9_4_1); - public static final IndexVersion V_8_5_1 = new IndexVersion(8_05_01_99, Version.LUCENE_9_4_1); - public static final IndexVersion V_8_5_2 = new IndexVersion(8_05_02_99, Version.LUCENE_9_4_1); - public static final IndexVersion V_8_5_3 = new IndexVersion(8_05_03_99, Version.LUCENE_9_4_2); - public static final IndexVersion V_8_6_0 = new IndexVersion(8_06_00_99, Version.LUCENE_9_4_2); - public static final IndexVersion V_8_6_1 = new IndexVersion(8_06_01_99, Version.LUCENE_9_4_2); - public static final IndexVersion V_8_6_2 = new IndexVersion(8_06_02_99, Version.LUCENE_9_4_2); - public static final IndexVersion V_8_6_3 = new IndexVersion(8_06_03_99, Version.LUCENE_9_4_2); - public static final IndexVersion V_8_7_0 = new IndexVersion(8_07_00_99, Version.LUCENE_9_5_0); - - public static final IndexVersion V_8_8_0 = new IndexVersion(8_08_00_99, Version.LUCENE_9_6_0); + public static final IndexVersion V_7_0_0 = new IndexVersion(7_00_00_99, Version.LUCENE_8_0_0, "b32be92d-c403-4858-a4a3-20d699a47ae6"); + public static final IndexVersion V_7_0_1 = new IndexVersion(7_00_01_99, Version.LUCENE_8_0_0, "a03ed728-eac8-4e50-bcce-864806bb10e0"); + public static final IndexVersion V_7_1_0 = new IndexVersion(7_01_00_99, Version.LUCENE_8_0_0, "f9964d87-9f20-4b26-af32-be1f979216ec"); + public static final IndexVersion V_7_1_1 = new IndexVersion(7_01_01_99, Version.LUCENE_8_0_0, "29a3fb69-55d0-4389-aea9-96c98ce23830"); + public static final IndexVersion V_7_2_0 = new IndexVersion(7_02_00_99, Version.LUCENE_8_0_0, "dba49448-87d4-45bb-ba19-f7b4eb85c757"); + public static final IndexVersion V_7_2_1 = new IndexVersion(7_02_01_99, Version.LUCENE_8_0_0, "58874b45-f9f8-4c04-92a9-67548a8b21c3"); + public static final IndexVersion V_7_3_0 = new IndexVersion(7_03_00_99, Version.LUCENE_8_1_0, "3d8a21df-58a4-4d7a-ba5d-438c92c16a7b"); + public static final IndexVersion V_7_3_1 = new IndexVersion(7_03_01_99, Version.LUCENE_8_1_0, "5687797f-448b-490d-94d4-d7e8cfac0c98"); + public static final IndexVersion V_7_3_2 = new IndexVersion(7_03_02_99, Version.LUCENE_8_1_0, "5a3462e5-d2fe-4b7b-9a7e-c0234412271f"); + public static final IndexVersion V_7_4_0 = new IndexVersion(7_04_00_99, Version.LUCENE_8_2_0, "c1fe73ba-0173-476c-aba2-855c2b31ac18"); + public static final IndexVersion V_7_4_1 = new IndexVersion(7_04_01_99, Version.LUCENE_8_2_0, "8a917374-bd4f-45e3-9052-575c4cf741cd"); + public static final IndexVersion V_7_4_2 = new IndexVersion(7_04_02_99, Version.LUCENE_8_2_0, "f073a867-cba2-41e4-8150-a2f2a96f1e0b"); + public static final IndexVersion V_7_5_0 = new IndexVersion(7_05_00_99, Version.LUCENE_8_3_0, "ab08ae25-ede2-4e57-a43f-89d96aa989e4"); + public static final IndexVersion V_7_5_1 = new IndexVersion(7_05_01_99, Version.LUCENE_8_3_0, "a386d62e-cb85-4a37-b5f9-c9468bbfc457"); + public static final IndexVersion V_7_5_2 = new IndexVersion(7_05_02_99, Version.LUCENE_8_3_0, "706715ca-3b91-40d2-8c2e-c34c459b5d0d"); + public static final IndexVersion V_7_6_0 = new IndexVersion(7_06_00_99, Version.LUCENE_8_4_0, "63acbdb9-51c8-4976-bb3d-e55052a4fbd4"); + public static final IndexVersion V_7_6_1 = new IndexVersion(7_06_01_99, Version.LUCENE_8_4_0, "1acc33d3-28dc-448d-953a-664dad3bf1f5"); + public static final IndexVersion V_7_6_2 = new IndexVersion(7_06_02_99, Version.LUCENE_8_4_0, "3aa17069-fa04-4bf9-96af-fe8b903faa75"); + public static final IndexVersion V_7_7_0 = new IndexVersion(7_07_00_99, Version.LUCENE_8_5_1, "6fff8238-e6ce-4fb2-85de-196492026e49"); + public static final IndexVersion V_7_7_1 = new IndexVersion(7_07_01_99, Version.LUCENE_8_5_1, "4ce6641d-157b-4c59-8261-7997ac0f6e40"); + public static final IndexVersion V_7_8_0 = new IndexVersion(7_08_00_99, Version.LUCENE_8_5_1, "81d7d459-f386-4c20-8235-f8fce8af7f0e"); + public static final IndexVersion V_7_8_1 = new IndexVersion(7_08_01_99, Version.LUCENE_8_5_1, "a1b015bc-d020-453f-85a6-9413e169304a"); + public static final IndexVersion V_7_9_0 = new IndexVersion(7_09_00_99, Version.LUCENE_8_6_0, "0fa951a2-43ce-4f76-91bf-066c1ecf8a93"); + public static final IndexVersion V_7_9_1 = new IndexVersion(7_09_01_99, Version.LUCENE_8_6_2, "5fc4aabc-080e-4840-af4f-a724deba98b1"); + public static final IndexVersion V_7_9_2 = new IndexVersion(7_09_02_99, Version.LUCENE_8_6_2, "ef824617-332e-4b63-969e-ebb73a868462"); + public static final IndexVersion V_7_9_3 = new IndexVersion(7_09_03_99, Version.LUCENE_8_6_2, "499c810a-0f37-4dfd-92ad-55e4936f3578"); + public static final IndexVersion V_7_10_0 = new IndexVersion(7_10_00_99, Version.LUCENE_8_7_0, "92ccd91c-0251-4263-8873-9f1abfac3c10"); + public static final IndexVersion V_7_10_1 = new IndexVersion(7_10_01_99, Version.LUCENE_8_7_0, "8ce37467-964f-43eb-ad2d-a51a50116868"); + public static final IndexVersion V_7_10_2 = new IndexVersion(7_10_02_99, Version.LUCENE_8_7_0, "cb277ccb-3081-4238-be2c-c3167316a435"); + public static final IndexVersion V_7_11_0 = new IndexVersion(7_11_00_99, Version.LUCENE_8_7_0, "e6d65f96-26d5-4669-ac5a-2964b9b1699f"); + public static final IndexVersion V_7_11_1 = new IndexVersion(7_11_01_99, Version.LUCENE_8_7_0, "e3655b78-14f7-4432-aa28-34cd1ef2d229"); + public static final IndexVersion V_7_11_2 = new IndexVersion(7_11_02_99, Version.LUCENE_8_7_0, "1ecfd0ee-4868-4384-b2a0-af6ecb01e496"); + public static final IndexVersion V_7_12_0 = new IndexVersion(7_12_00_99, Version.LUCENE_8_8_0, "39e2989a-a9a4-4f1a-b185-2e6015f74b1c"); + public static final IndexVersion V_7_12_1 = new IndexVersion(7_12_01_99, Version.LUCENE_8_8_0, "a8307f67-8295-4567-a7eb-2a6e69046282"); + public static final IndexVersion V_7_13_0 = new IndexVersion(7_13_00_99, Version.LUCENE_8_8_2, "28b21fe0-4d1f-4c04-95cc-74df494ae0cf"); + public static final IndexVersion V_7_13_1 = new IndexVersion(7_13_01_99, Version.LUCENE_8_8_2, "4952d7a7-d9f5-443b-b362-8c5ebdc57f81"); + public static final IndexVersion V_7_13_2 = new IndexVersion(7_13_02_99, Version.LUCENE_8_8_2, "d77c4245-9d26-4da3-aa61-78ab34c3c792"); + public static final IndexVersion V_7_13_3 = new IndexVersion(7_13_03_99, Version.LUCENE_8_8_2, "a263a47e-4075-4c68-8a42-15a37455c30f"); + public static final IndexVersion V_7_13_4 = new IndexVersion(7_13_04_99, Version.LUCENE_8_8_2, "d17644c8-3144-495d-8f6c-42cd36698e98"); + public static final IndexVersion V_7_14_0 = new IndexVersion(7_14_00_99, Version.LUCENE_8_9_0, "b45bb223-bb73-4379-a46f-7dc74d38aaca"); + public static final IndexVersion V_7_14_1 = new IndexVersion(7_14_01_99, Version.LUCENE_8_9_0, "ee4a6d62-9e05-490b-93dd-b316f9a62d71"); + public static final IndexVersion V_7_14_2 = new IndexVersion(7_14_02_99, Version.LUCENE_8_9_0, "285d3293-2896-431c-97dd-180890840947"); + public static final IndexVersion V_7_15_0 = new IndexVersion(7_15_00_99, Version.LUCENE_8_9_0, "ab666b02-b866-4b64-9ba3-d511e86c55b5"); + public static final IndexVersion V_7_15_1 = new IndexVersion(7_15_01_99, Version.LUCENE_8_9_0, "5643957d-9b68-414a-8917-ea75cf549f67"); + public static final IndexVersion V_7_15_2 = new IndexVersion(7_15_02_99, Version.LUCENE_8_9_0, "1a618039-d665-47ce-b6ca-886e88c64051"); + public static final IndexVersion V_7_16_0 = new IndexVersion(7_16_00_99, Version.LUCENE_8_10_1, "a582e900-2d92-474c-9be3-2e08fa88be4b"); + public static final IndexVersion V_7_16_1 = new IndexVersion(7_16_01_99, Version.LUCENE_8_10_1, "bf666306-9b0d-468b-99dc-f2706dae9c11"); + public static final IndexVersion V_7_16_2 = new IndexVersion(7_16_02_99, Version.LUCENE_8_10_1, "167c6d69-cae2-4281-8f37-984231620ee9"); + public static final IndexVersion V_7_16_3 = new IndexVersion(7_16_03_99, Version.LUCENE_8_10_1, "5d25a795-2be6-4663-93dc-10d88efb7e3d"); + public static final IndexVersion V_7_17_0 = new IndexVersion(7_17_00_99, Version.LUCENE_8_11_1, "18766ab8-4691-40a2-94f1-526f3b71420c"); + public static final IndexVersion V_7_17_1 = new IndexVersion(7_17_01_99, Version.LUCENE_8_11_1, "8ad49144-4a1c-4322-b33d-614a569fba9b"); + public static final IndexVersion V_7_17_2 = new IndexVersion(7_17_02_99, Version.LUCENE_8_11_1, "50033cde-c905-4923-83d6-8139f3f110e1"); + public static final IndexVersion V_7_17_3 = new IndexVersion(7_17_03_99, Version.LUCENE_8_11_1, "460b91d1-4f3d-4f56-8dca-8d9e15f5b862"); + public static final IndexVersion V_7_17_4 = new IndexVersion(7_17_04_99, Version.LUCENE_8_11_1, "26e40d6f-ac7c-43a3-bd0c-1ec6c3093f66"); + public static final IndexVersion V_7_17_5 = new IndexVersion(7_17_05_99, Version.LUCENE_8_11_1, "d80bc13c-7139-4ff9-979d-42701d480e33"); + public static final IndexVersion V_7_17_6 = new IndexVersion(7_17_06_99, Version.LUCENE_8_11_1, "0b47328e-341a-4f97-927d-c49f5050778d"); + public static final IndexVersion V_7_17_7 = new IndexVersion(7_17_07_99, Version.LUCENE_8_11_1, "b672ff6b-8078-4f6e-b426-6fcf7f8687b4"); + public static final IndexVersion V_7_17_8 = new IndexVersion(7_17_08_99, Version.LUCENE_8_11_1, "0faffa1b-5fb3-4439-9367-f154fb25395f"); + public static final IndexVersion V_7_17_9 = new IndexVersion(7_17_09_99, Version.LUCENE_8_11_1, "8044989f-77ef-4d6d-9dd8-1bdd805cef74"); + public static final IndexVersion V_7_17_10 = new IndexVersion(7_17_10_99, Version.LUCENE_8_11_1, "66b743fb-8be6-443f-8920-d8c5ed561857"); + public static final IndexVersion V_8_0_0 = new IndexVersion(8_00_00_99, Version.LUCENE_9_0_0, "ff18a13c-1fa7-4cf7-a3b1-4fdcd9461d5b"); + public static final IndexVersion V_8_0_1 = new IndexVersion(8_00_01_99, Version.LUCENE_9_0_0, "4bd5650f-3eff-418f-a7a6-ad46b2a9c941"); + public static final IndexVersion V_8_1_0 = new IndexVersion(8_01_00_99, Version.LUCENE_9_0_0, "b4742461-ee43-4fd0-a260-29f8388b82ec"); + public static final IndexVersion V_8_1_1 = new IndexVersion(8_01_01_99, Version.LUCENE_9_0_0, "3883e088-9a1c-4494-8d71-768820485f33"); + public static final IndexVersion V_8_1_2 = new IndexVersion(8_01_02_99, Version.LUCENE_9_0_0, "859a745a-81d3-463e-af58-615179a22d4f"); + public static final IndexVersion V_8_1_3 = new IndexVersion(8_01_03_99, Version.LUCENE_9_0_0, "27a49f3f-d3ac-4b0e-8bba-1be24daf4a56"); + public static final IndexVersion V_8_2_0 = new IndexVersion(8_02_00_99, Version.LUCENE_9_1_0, "af0ed990-2f32-42b5-aaf3-59d21a3dca7a"); + public static final IndexVersion V_8_2_1 = new IndexVersion(8_02_01_99, Version.LUCENE_9_1_0, "6e2a3812-062a-4d08-8c35-ddc930e8e246"); + public static final IndexVersion V_8_2_2 = new IndexVersion(8_02_02_99, Version.LUCENE_9_1_0, "93d1434c-3956-408b-8204-93be8ab78856"); + public static final IndexVersion V_8_2_3 = new IndexVersion(8_02_03_99, Version.LUCENE_9_1_0, "026f6904-2a04-4476-8097-02a75e37e0f7"); + public static final IndexVersion V_8_3_0 = new IndexVersion(8_03_00_99, Version.LUCENE_9_2_0, "eca8e8a3-0724-4247-a58d-e4eafcec4b3f"); + public static final IndexVersion V_8_3_1 = new IndexVersion(8_03_01_99, Version.LUCENE_9_2_0, "dac08798-c0b5-46c9-bf27-d82c617ce41f"); + public static final IndexVersion V_8_3_2 = new IndexVersion(8_03_02_99, Version.LUCENE_9_2_0, "2a0c5fb9-e8a5-4788-89f8-f5723bd68cee"); + public static final IndexVersion V_8_3_3 = new IndexVersion(8_03_03_99, Version.LUCENE_9_2_0, "440a5f5c-767a-49f7-8593-dc7627b30397"); + public static final IndexVersion V_8_4_0 = new IndexVersion(8_04_00_99, Version.LUCENE_9_3_0, "d27324da-b36c-452a-93a8-9b69a6c302a1"); + public static final IndexVersion V_8_4_1 = new IndexVersion(8_04_01_99, Version.LUCENE_9_3_0, "44108ecd-839b-423e-9ef1-9d457f244fff"); + public static final IndexVersion V_8_4_2 = new IndexVersion(8_04_02_99, Version.LUCENE_9_3_0, "9c20ed39-8c32-4cf0-9f06-42735cbf604e"); + public static final IndexVersion V_8_4_3 = new IndexVersion(8_04_03_99, Version.LUCENE_9_3_0, "e7d17607-47c0-4662-b308-beeb9a8ec552"); + public static final IndexVersion V_8_5_0 = new IndexVersion(8_05_00_99, Version.LUCENE_9_4_1, "c5284b51-7fee-4f34-a837-241bb57a7aa6"); + public static final IndexVersion V_8_5_1 = new IndexVersion(8_05_01_99, Version.LUCENE_9_4_1, "b23a983c-9630-4a2b-8352-0f52b55ff87e"); + public static final IndexVersion V_8_5_2 = new IndexVersion(8_05_02_99, Version.LUCENE_9_4_1, "cfc80b6f-cb5c-4a4c-b3af-5fa1000508a8"); + public static final IndexVersion V_8_5_3 = new IndexVersion(8_05_03_99, Version.LUCENE_9_4_2, "f8ac8061-1b17-4cab-b2f6-94df31f7552e"); + public static final IndexVersion V_8_6_0 = new IndexVersion(8_06_00_99, Version.LUCENE_9_4_2, "5e78c76c-74aa-464e-9383-89bdffb74db9"); + public static final IndexVersion V_8_6_1 = new IndexVersion(8_06_01_99, Version.LUCENE_9_4_2, "8dc502be-ef27-43b3-a27b-1cb925cbef7d"); + public static final IndexVersion V_8_6_2 = new IndexVersion(8_06_02_99, Version.LUCENE_9_4_2, "e1e73b88-d188-4d82-b5e1-dee261418783"); + public static final IndexVersion V_8_6_3 = new IndexVersion(8_06_03_99, Version.LUCENE_9_4_2, "b3d4a28b-4e0c-47dc-b1e9-5640c0749937"); + public static final IndexVersion V_8_7_0 = new IndexVersion(8_07_00_99, Version.LUCENE_9_5_0, "f9227941-d6f4-462b-957f-2bcd36c28382"); + public static final IndexVersion V_8_8_0 = new IndexVersion(8_08_00_99, Version.LUCENE_9_6_0, "d6ffc8d7-f6bd-469b-8495-01688c310000"); public static final IndexVersion CURRENT = V_8_8_0; @@ -163,6 +162,9 @@ static NavigableMap getAllVersionIds(Class cls) { static { VERSION_IDS = getAllVersionIds(IndexVersion.class); + + assert CURRENT.luceneVersion.equals(org.apache.lucene.util.Version.LATEST) + : "IndexVersion must be upgraded to [" + org.apache.lucene.util.Version.LATEST + "] is still set to [" + CURRENT.luceneVersion + "]"; } static Collection getAllVersions() { @@ -184,12 +186,18 @@ public static IndexVersion fromId(int id) { if (known != null) { return known; } - // this is a version we don't otherwise know about - just create a placeholder + + // this is a version we don't otherwise know about // We need to guess the lucene version. // Our best guess is to use the same lucene version as the previous // version in the list, assuming that it didn't change. + // if it's older than any known version use the previous major to the oldest known lucene version + var prev = VERSION_IDS.floorEntry(id); + Version luceneVersion = prev != null + ? prev.getValue().luceneVersion + : Version.fromBits(VERSION_IDS.firstEntry().getValue().luceneVersion.major - 1, 0, 0); - return new IndexVersion(id, ""); + return new IndexVersion(id, luceneVersion, ""); } @Deprecated(forRemoval = true) diff --git a/server/src/main/java/org/elasticsearch/index/analysis/PreConfiguredCharFilter.java b/server/src/main/java/org/elasticsearch/index/analysis/PreConfiguredCharFilter.java index ae5d4c2c4a42f..877a6600fd3a9 100644 --- a/server/src/main/java/org/elasticsearch/index/analysis/PreConfiguredCharFilter.java +++ b/server/src/main/java/org/elasticsearch/index/analysis/PreConfiguredCharFilter.java @@ -61,7 +61,7 @@ public static PreConfiguredCharFilter luceneVersion( name, CachingStrategy.LUCENE, useFilterForMultitermQueries, - (reader, version) -> create.apply(reader, version.luceneVersion) + (reader, version) -> create.apply(reader, version.luceneVersion()) ); } diff --git a/server/src/main/java/org/elasticsearch/index/analysis/PreConfiguredTokenFilter.java b/server/src/main/java/org/elasticsearch/index/analysis/PreConfiguredTokenFilter.java index e88be4244e360..d9d724ca153c3 100644 --- a/server/src/main/java/org/elasticsearch/index/analysis/PreConfiguredTokenFilter.java +++ b/server/src/main/java/org/elasticsearch/index/analysis/PreConfiguredTokenFilter.java @@ -70,7 +70,7 @@ public static PreConfiguredTokenFilter luceneVersion( useFilterForMultitermQueries, true, CachingStrategy.LUCENE, - (tokenStream, version) -> create.apply(tokenStream, version.luceneVersion) + (tokenStream, version) -> create.apply(tokenStream, version.luceneVersion()) ); } diff --git a/server/src/main/java/org/elasticsearch/index/analysis/PreConfiguredTokenizer.java b/server/src/main/java/org/elasticsearch/index/analysis/PreConfiguredTokenizer.java index 0c0a0afc51ec9..558218053c0b0 100644 --- a/server/src/main/java/org/elasticsearch/index/analysis/PreConfiguredTokenizer.java +++ b/server/src/main/java/org/elasticsearch/index/analysis/PreConfiguredTokenizer.java @@ -37,7 +37,7 @@ public static PreConfiguredTokenizer singleton(String name, Supplier * @param create builds the tokenizer */ public static PreConfiguredTokenizer luceneVersion(String name, Function create) { - return new PreConfiguredTokenizer(name, CachingStrategy.LUCENE, version -> create.apply(version.luceneVersion)); + return new PreConfiguredTokenizer(name, CachingStrategy.LUCENE, version -> create.apply(version.luceneVersion())); } /** diff --git a/server/src/main/java/org/elasticsearch/index/similarity/SimilarityService.java b/server/src/main/java/org/elasticsearch/index/similarity/SimilarityService.java index a03702df14523..bc1c69c755d5f 100644 --- a/server/src/main/java/org/elasticsearch/index/similarity/SimilarityService.java +++ b/server/src/main/java/org/elasticsearch/index/similarity/SimilarityService.java @@ -176,7 +176,7 @@ private static void validateScoresArePositive(Version indexCreatedVersion, Simil TermStatistics termStats = new TermStatistics(new BytesRef("some_value"), 100, 130); SimScorer scorer = similarity.scorer(2f, collectionStats, termStats); FieldInvertState state = new FieldInvertState( - indexCreatedVersion.luceneVersion.major, + indexCreatedVersion.luceneVersion().major, "some_field", IndexOptions.DOCS_AND_FREQS, 20, @@ -202,7 +202,7 @@ private static void validateScoresDoNotDecreaseWithFreq(Version indexCreatedVers TermStatistics termStats = new TermStatistics(new BytesRef("some_value"), 100, 130); SimScorer scorer = similarity.scorer(2f, collectionStats, termStats); FieldInvertState state = new FieldInvertState( - indexCreatedVersion.luceneVersion.major, + indexCreatedVersion.luceneVersion().major, "some_field", IndexOptions.DOCS_AND_FREQS, 20, @@ -237,7 +237,7 @@ private static void validateScoresDoNotIncreaseWithNorm(Version indexCreatedVers float previousScore = Float.MAX_VALUE; for (int length = 1; length <= 10; ++length) { FieldInvertState state = new FieldInvertState( - indexCreatedVersion.luceneVersion.major, + indexCreatedVersion.luceneVersion().major, "some_field", IndexOptions.DOCS_AND_FREQS, length, diff --git a/server/src/main/java/org/elasticsearch/index/store/Store.java b/server/src/main/java/org/elasticsearch/index/store/Store.java index e5f69a3ee8a58..c675113e7c375 100644 --- a/server/src/main/java/org/elasticsearch/index/store/Store.java +++ b/server/src/main/java/org/elasticsearch/index/store/Store.java @@ -61,6 +61,7 @@ import org.elasticsearch.env.ShardLock; import org.elasticsearch.env.ShardLockObtainFailedException; import org.elasticsearch.index.IndexSettings; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.engine.CombinedDeletionPolicy; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.seqno.SequenceNumbers; @@ -817,7 +818,7 @@ static MetadataSnapshot loadFromIndexCommit(IndexCommit commit, Directory direct } } if (maxVersion == null) { - maxVersion = org.elasticsearch.Version.CURRENT.minimumIndexCompatibilityVersion().luceneVersion; + maxVersion = IndexVersion.MINIMUM_COMPATIBLE.luceneVersion; } final String segmentsFile = segmentCommitInfos.getSegmentsFileName(); checksumFromLuceneFile( @@ -1470,7 +1471,7 @@ public void accept(ShardLock Lock) {} * creates an empty lucene index and a corresponding empty translog. Any existing data will be deleted. */ public void createEmpty() throws IOException { - Version luceneVersion = indexSettings.getIndexVersionCreated().luceneVersion; + Version luceneVersion = indexSettings.getIndexVersionCreated().luceneVersion(); metadataLock.writeLock().lock(); try (IndexWriter writer = newTemporaryEmptyIndexWriter(directory, luceneVersion)) { final Map map = new HashMap<>(); diff --git a/server/src/main/java/org/elasticsearch/indices/analysis/PreBuiltCacheFactory.java b/server/src/main/java/org/elasticsearch/indices/analysis/PreBuiltCacheFactory.java index b77402f4a0ab7..41ca6fe466123 100644 --- a/server/src/main/java/org/elasticsearch/indices/analysis/PreBuiltCacheFactory.java +++ b/server/src/main/java/org/elasticsearch/indices/analysis/PreBuiltCacheFactory.java @@ -104,12 +104,12 @@ private static class PreBuiltCacheStrategyLucene implements PreBuiltCache @Override public T get(Version version) { - return mapModel.get(version.luceneVersion); + return mapModel.get(version.luceneVersion()); } @Override public void put(org.elasticsearch.Version version, T model) { - mapModel.put(version.luceneVersion, model); + mapModel.put(version.luceneVersion(), model); } @Override diff --git a/server/src/main/java/org/elasticsearch/indices/recovery/RecoverySettings.java b/server/src/main/java/org/elasticsearch/indices/recovery/RecoverySettings.java index 2b700668ef1ed..bcea029376ed8 100644 --- a/server/src/main/java/org/elasticsearch/indices/recovery/RecoverySettings.java +++ b/server/src/main/java/org/elasticsearch/indices/recovery/RecoverySettings.java @@ -27,6 +27,7 @@ import org.elasticsearch.core.Releasable; import org.elasticsearch.core.Releasables; import org.elasticsearch.core.TimeValue; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.monitor.os.OsProbe; import org.elasticsearch.node.NodeRoleSettings; @@ -45,7 +46,7 @@ public class RecoverySettings { public static final Version SNAPSHOT_RECOVERIES_SUPPORTED_VERSION = Version.V_7_15_0; public static final TransportVersion SNAPSHOT_RECOVERIES_SUPPORTED_TRANSPORT_VERSION = TransportVersion.V_7_15_0; - public static final Version SEQ_NO_SNAPSHOT_RECOVERIES_SUPPORTED_VERSION = Version.V_7_16_0; + public static final IndexVersion SEQ_NO_SNAPSHOT_RECOVERIES_SUPPORTED_VERSION = IndexVersion.V_7_16_0; public static final TransportVersion SNAPSHOT_FILE_DOWNLOAD_THROTTLING_SUPPORTED_TRANSPORT_VERSION = TransportVersion.V_7_16_0; private static final Logger logger = LogManager.getLogger(RecoverySettings.class); diff --git a/server/src/test/java/org/elasticsearch/VersionTests.java b/server/src/test/java/org/elasticsearch/VersionTests.java index 26a5415473d07..405f29acd153c 100644 --- a/server/src/test/java/org/elasticsearch/VersionTests.java +++ b/server/src/test/java/org/elasticsearch/VersionTests.java @@ -91,12 +91,12 @@ public void testMinimumIndexCompatibilityVersion() { public void testVersionConstantPresent() { assertThat(Version.CURRENT, sameInstance(Version.fromId(Version.CURRENT.id))); - assertThat(Version.CURRENT.luceneVersion, equalTo(org.apache.lucene.util.Version.LATEST)); + assertThat(Version.CURRENT.luceneVersion(), equalTo(org.apache.lucene.util.Version.LATEST)); final int iters = scaledRandomIntBetween(20, 100); for (int i = 0; i < iters; i++) { Version version = randomVersion(random()); assertThat(version, sameInstance(Version.fromId(version.id))); - assertThat(version.luceneVersion, sameInstance(Version.fromId(version.id).luceneVersion)); + assertThat(version.luceneVersion(), sameInstance(Version.fromId(version.id).luceneVersion())); } } @@ -178,7 +178,7 @@ public void testParseVersion() { for (int i = 0; i < iters; i++) { Version version = randomVersion(random()); if (random().nextBoolean()) { - version = new Version(version.id, version.transportVersion, version.luceneVersion); + version = new Version(version.id, version.transportVersion, version.indexVersion); } Version parsedVersion = Version.fromString(version.toString()); assertEquals(version, parsedVersion); @@ -195,7 +195,7 @@ public void testParseVersion() { public void testParseLenient() { // note this is just a silly sanity check, we test it in lucene for (Version version : VersionUtils.allReleasedVersions()) { - org.apache.lucene.util.Version luceneVersion = version.luceneVersion; + org.apache.lucene.util.Version luceneVersion = version.luceneVersion(); String string = luceneVersion.toString().toUpperCase(Locale.ROOT).replaceFirst("^LUCENE_(\\d+)_(\\d+)$", "$1.$2"); assertThat(luceneVersion, Matchers.equalTo(Lucene.parseVersionLenient(string, null))); } @@ -253,11 +253,12 @@ public void testLuceneVersionIsSameOnMinorRelease() { for (Version version : VersionUtils.allReleasedVersions()) { for (Version other : VersionUtils.allReleasedVersions()) { if (other.onOrAfter(version)) { - assertTrue("lucene versions must be " + other + " >= " + version, other.luceneVersion.onOrAfter(version.luceneVersion)); + assertTrue("lucene versions must be " + other + " >= " + version, + other.luceneVersion().onOrAfter(version.luceneVersion())); } if (other.major == version.major && other.minor == version.minor) { - assertEquals(version + " vs. " + other, other.luceneVersion.major, version.luceneVersion.major); - assertEquals(version + " vs. " + other, other.luceneVersion.minor, version.luceneVersion.minor); + assertEquals(version + " vs. " + other, other.luceneVersion().major, version.luceneVersion().major); + assertEquals(version + " vs. " + other, other.luceneVersion().minor, version.luceneVersion().minor); // should we also assert the lucene bugfix version? } } diff --git a/server/src/test/java/org/elasticsearch/action/main/MainResponseTests.java b/server/src/test/java/org/elasticsearch/action/main/MainResponseTests.java index f591a40315aef..21d11a24459ab 100644 --- a/server/src/test/java/org/elasticsearch/action/main/MainResponseTests.java +++ b/server/src/test/java/org/elasticsearch/action/main/MainResponseTests.java @@ -83,7 +83,7 @@ public void testToXContent() throws IOException { current.hash(), current.date(), current.isSnapshot(), - version.luceneVersion.toString(), + version.luceneVersion().toString(), version.minimumCompatibilityVersion().toString(), version.minimumIndexCompatibilityVersion().toString() ) diff --git a/server/src/test/java/org/elasticsearch/common/lucene/uid/VersionsTests.java b/server/src/test/java/org/elasticsearch/common/lucene/uid/VersionsTests.java index 000022481c76e..6c834d02160b0 100644 --- a/server/src/test/java/org/elasticsearch/common/lucene/uid/VersionsTests.java +++ b/server/src/test/java/org/elasticsearch/common/lucene/uid/VersionsTests.java @@ -204,19 +204,19 @@ public void testLuceneVersionOnUnknownVersions() { final Version nextVersion = Version.fromId(version.id + 100); if (Version.getDeclaredVersions(Version.class).contains(nextVersion) == false) { // the version is not known, we make an assumption the Lucene version stays the same - assertEquals(nextVersion.luceneVersion, version.luceneVersion); + assertEquals(nextVersion.luceneVersion(), version.luceneVersion()); } else { // the version is known, the most we can assert is that the Lucene version is not earlier - assertTrue(nextVersion.luceneVersion.onOrAfter(version.luceneVersion)); + assertTrue(nextVersion.luceneVersion().onOrAfter(version.luceneVersion())); } // too old version, major should be the oldest supported lucene version minus 1 version = Version.fromString("5.2.1"); - assertEquals(VersionUtils.getFirstVersion().luceneVersion.major - 1, version.luceneVersion.major); + assertEquals(VersionUtils.getFirstVersion().luceneVersion().major - 1, version.luceneVersion().major); // future version, should be the same version as today version = Version.fromId(Version.CURRENT.id + 100); - assertEquals(Version.CURRENT.luceneVersion, version.luceneVersion); + assertEquals(Version.CURRENT.luceneVersion(), version.luceneVersion()); } public void testTimeSeriesLoadDocIdAndVersion() throws Exception { diff --git a/server/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java b/server/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java index 12ea5490028ea..93ccd57aed943 100644 --- a/server/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java +++ b/server/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java @@ -36,6 +36,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.core.TimeValue; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.seqno.ReplicationTracker; import org.elasticsearch.index.seqno.RetentionLease; @@ -65,7 +66,7 @@ import static org.hamcrest.Matchers.hasSize; public class ReplicaShardAllocatorTests extends ESAllocationTestCase { - private static final String MIN_SUPPORTED_LUCENE_VERSION = Version.CURRENT.minimumIndexCompatibilityVersion().luceneVersion.toString(); + private static final String MIN_SUPPORTED_LUCENE_VERSION = IndexVersion.MINIMUM_COMPATIBLE.luceneVersion.toString(); private final ShardId shardId = new ShardId("test", "_na_", 0); private final DiscoveryNode node1 = newNode("node1"); diff --git a/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java b/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java index 40e9c76e25ca5..11b0561b69031 100644 --- a/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java +++ b/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java @@ -99,6 +99,7 @@ import org.elasticsearch.core.Tuple; import org.elasticsearch.index.IndexModule; import org.elasticsearch.index.IndexSettings; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.VersionType; import org.elasticsearch.index.codec.CodecService; import org.elasticsearch.index.fieldvisitor.FieldsVisitor; @@ -6688,7 +6689,7 @@ public long softUpdateDocuments(Term term, Iterable userData = new HashMap<>(store.readLastCommittedSegmentsInfo().userData); userData.remove(Engine.MIN_RETAINED_SEQNO); IndexWriterConfig indexWriterConfig = new IndexWriterConfig(null).setOpenMode(IndexWriterConfig.OpenMode.APPEND) - .setIndexCreatedVersionMajor(Version.CURRENT.luceneVersion.major) + .setIndexCreatedVersionMajor(IndexVersion.CURRENT.luceneVersion.major) .setSoftDeletesField(Lucene.SOFT_DELETES_FIELD) .setCommitOnClose(false) .setMergePolicy(NoMergePolicy.INSTANCE); @@ -6748,7 +6749,7 @@ public void testStoreHonorsLuceneVersion() throws IOException { engine.refresh("test"); try (Engine.Searcher searcher = engine.acquireSearcher("test")) { LeafReader leafReader = getOnlyLeafReader(searcher.getIndexReader()); - assertEquals(createdVersion.luceneVersion.major, leafReader.getMetaData().getCreatedVersionMajor()); + assertEquals(createdVersion.luceneVersion().major, leafReader.getMetaData().getCreatedVersionMajor()); } } } diff --git a/server/src/test/java/org/elasticsearch/index/snapshots/blobstore/FileInfoTests.java b/server/src/test/java/org/elasticsearch/index/snapshots/blobstore/FileInfoTests.java index adbcff702318f..5ba754143503c 100644 --- a/server/src/test/java/org/elasticsearch/index/snapshots/blobstore/FileInfoTests.java +++ b/server/src/test/java/org/elasticsearch/index/snapshots/blobstore/FileInfoTests.java @@ -12,6 +12,7 @@ import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.unit.ByteSizeValue; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot.FileInfo; import org.elasticsearch.index.store.StoreFileMetadata; import org.elasticsearch.test.ESTestCase; @@ -31,8 +32,7 @@ import static org.hamcrest.Matchers.is; public class FileInfoTests extends ESTestCase { - private static final org.apache.lucene.util.Version MIN_SUPPORTED_LUCENE_VERSION = org.elasticsearch.Version.CURRENT - .minimumIndexCompatibilityVersion().luceneVersion; + private static final org.apache.lucene.util.Version MIN_SUPPORTED_LUCENE_VERSION = IndexVersion.MINIMUM_COMPATIBLE.luceneVersion; public void testToFromXContent() throws IOException { final int iters = scaledRandomIntBetween(1, 10); diff --git a/server/src/test/java/org/elasticsearch/index/store/StoreTests.java b/server/src/test/java/org/elasticsearch/index/store/StoreTests.java index 31f8ff75f3bfb..2615abbfccdc4 100644 --- a/server/src/test/java/org/elasticsearch/index/store/StoreTests.java +++ b/server/src/test/java/org/elasticsearch/index/store/StoreTests.java @@ -54,6 +54,7 @@ import org.elasticsearch.env.ShardLock; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexSettings; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.seqno.ReplicationTracker; import org.elasticsearch.index.seqno.RetentionLease; @@ -105,8 +106,7 @@ public class StoreTests extends ESTestCase { "index", Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, org.elasticsearch.Version.CURRENT).build() ); - private static final Version MIN_SUPPORTED_LUCENE_VERSION = org.elasticsearch.Version.CURRENT - .minimumIndexCompatibilityVersion().luceneVersion; + private static final Version MIN_SUPPORTED_LUCENE_VERSION = IndexVersion.MINIMUM_COMPATIBLE.luceneVersion; public void testRefCount() { final ShardId shardId = new ShardId("index", "_na_", 1); diff --git a/server/src/test/java/org/elasticsearch/indices/analysis/AnalysisModuleTests.java b/server/src/test/java/org/elasticsearch/indices/analysis/AnalysisModuleTests.java index ef07c5efe43c0..1207ffac602f5 100644 --- a/server/src/test/java/org/elasticsearch/indices/analysis/AnalysisModuleTests.java +++ b/server/src/test/java/org/elasticsearch/indices/analysis/AnalysisModuleTests.java @@ -274,7 +274,7 @@ public Map> getTokenizers() { .build() ); assertTokenStreamContents(analyzers.get("no_version").tokenStream("", "test"), new String[] { "testno_version" }); - assertTokenStreamContents(analyzers.get("lucene_version").tokenStream("", "test"), new String[] { "test" + version.luceneVersion }); + assertTokenStreamContents(analyzers.get("lucene_version").tokenStream("", "test"), new String[] { "test" + version.luceneVersion() }); assertTokenStreamContents(analyzers.get("elasticsearch_version").tokenStream("", "test"), new String[] { "test" + version }); assertEquals( @@ -282,7 +282,7 @@ public Map> getTokenizers() { analyzers.get("no_version").normalize("", "test").utf8ToString() ); assertEquals( - "test" + (luceneVersionSupportsMultiTerm ? version.luceneVersion.toString() : ""), + "test" + (luceneVersionSupportsMultiTerm ? version.luceneVersion().toString() : ""), analyzers.get("lucene_version").normalize("", "test").utf8ToString() ); assertEquals( @@ -340,7 +340,7 @@ public List getPreConfiguredTokenFilters() { .build() ); assertTokenStreamContents(analyzers.get("no_version").tokenStream("", "test"), new String[] { "testno_version" }); - assertTokenStreamContents(analyzers.get("lucene_version").tokenStream("", "test"), new String[] { "test" + version.luceneVersion }); + assertTokenStreamContents(analyzers.get("lucene_version").tokenStream("", "test"), new String[] { "test" + version.luceneVersion() }); assertTokenStreamContents(analyzers.get("elasticsearch_version").tokenStream("", "test"), new String[] { "test" + version }); assertEquals( @@ -348,7 +348,7 @@ public List getPreConfiguredTokenFilters() { analyzers.get("no_version").normalize("", "test").utf8ToString() ); assertEquals( - "test" + (luceneVersionSupportsMultiTerm ? version.luceneVersion.toString() : ""), + "test" + (luceneVersionSupportsMultiTerm ? version.luceneVersion().toString() : ""), analyzers.get("lucene_version").normalize("", "test").utf8ToString() ); assertEquals( @@ -426,7 +426,7 @@ public List getPreConfiguredTokenizers() { assertTokenStreamContents(analyzers.get("no_version").tokenStream("", "test"), new String[] { "no_version" }); assertTokenStreamContents( analyzers.get("lucene_version").tokenStream("", "test"), - new String[] { version.luceneVersion.toString() } + new String[] { version.luceneVersion().toString() } ); assertTokenStreamContents(analyzers.get("elasticsearch_version").tokenStream("", "test"), new String[] { version.toString() }); diff --git a/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryStatusTests.java b/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryStatusTests.java index f0f3b6fabd51f..c04988b8ac92b 100644 --- a/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryStatusTests.java +++ b/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryStatusTests.java @@ -12,6 +12,7 @@ import org.apache.lucene.store.IndexOutput; import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.index.IndexService; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.shard.IndexShard; import org.elasticsearch.index.store.StoreFileMetadata; import org.elasticsearch.test.ESSingleNodeTestCase; @@ -21,8 +22,7 @@ import java.util.regex.Pattern; public class RecoveryStatusTests extends ESSingleNodeTestCase { - private static final org.apache.lucene.util.Version MIN_SUPPORTED_LUCENE_VERSION = org.elasticsearch.Version.CURRENT - .minimumIndexCompatibilityVersion().luceneVersion; + private static final org.apache.lucene.util.Version MIN_SUPPORTED_LUCENE_VERSION = IndexVersion.MINIMUM_COMPATIBLE.luceneVersion; public void testRenameTempFiles() throws IOException { IndexService service = createIndex("foo"); diff --git a/server/src/test/java/org/elasticsearch/repositories/blobstore/ShardSnapshotTaskRunnerTests.java b/server/src/test/java/org/elasticsearch/repositories/blobstore/ShardSnapshotTaskRunnerTests.java index f0aa256ff0317..769b2a1c1f75b 100644 --- a/server/src/test/java/org/elasticsearch/repositories/blobstore/ShardSnapshotTaskRunnerTests.java +++ b/server/src/test/java/org/elasticsearch/repositories/blobstore/ShardSnapshotTaskRunnerTests.java @@ -16,6 +16,7 @@ import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.IndexSettings; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.snapshots.IndexShardSnapshotStatus; @@ -100,7 +101,7 @@ public int finishedShardSnapshotTasks() { public static BlobStoreIndexShardSnapshot.FileInfo dummyFileInfo() { String filename = randomAlphaOfLength(10); - StoreFileMetadata metadata = new StoreFileMetadata(filename, 10, "CHECKSUM", Version.CURRENT.luceneVersion.toString()); + StoreFileMetadata metadata = new StoreFileMetadata(filename, 10, "CHECKSUM", IndexVersion.CURRENT.luceneVersion.toString()); return new BlobStoreIndexShardSnapshot.FileInfo(filename, metadata, null); } diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java index 9d26585aa6405..40227cdbfe90c 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java @@ -81,6 +81,7 @@ import org.elasticsearch.env.TestEnvironment; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexSettings; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.analysis.AnalysisRegistry; import org.elasticsearch.index.analysis.AnalyzerScope; import org.elasticsearch.index.analysis.CharFilterFactory; @@ -1871,7 +1872,7 @@ public String toString() { * @param message an additional message or link with information on the fix */ protected void skipTestWaitingForLuceneFix(org.apache.lucene.util.Version luceneVersionWithFix, String message) { - final boolean currentVersionHasFix = Version.CURRENT.luceneVersion.onOrAfter(luceneVersionWithFix); + final boolean currentVersionHasFix = IndexVersion.CURRENT.luceneVersion.onOrAfter(luceneVersionWithFix); assumeTrue("Skipping test as it is waiting on a Lucene fix: " + message, currentVersionHasFix); fail("Remove call of skipTestWaitingForLuceneFix in " + RandomizedTest.getContext().getTargetMethod()); } diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryStatsTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryStatsTests.java index f862f79d9b1ab..a830dcf73141b 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryStatsTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryStatsTests.java @@ -27,6 +27,7 @@ import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.core.TimeValue; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardPath; import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot; @@ -640,7 +641,7 @@ private void executeTestCase( fileName, fileContent.length, fileChecksum, - Version.CURRENT.luceneVersion.toString() + IndexVersion.CURRENT.luceneVersion.toString() ); final List files = List.of(new FileInfo(blobName, metadata, ByteSizeValue.ofBytes(fileContent.length))); final BlobStoreIndexShardSnapshot snapshot = new BlobStoreIndexShardSnapshot(snapshotId.getName(), 0L, files, 0L, 0L, 0, 0L); diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryTests.java index a36f6e699490e..8c427c6ff86e7 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryTests.java @@ -69,6 +69,7 @@ import org.elasticsearch.env.Environment; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexSettings; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.seqno.SequenceNumbers; import org.elasticsearch.index.shard.ShardId; @@ -733,7 +734,7 @@ public void testClearCache() throws Exception { randomFiles.add( new BlobStoreIndexShardSnapshot.FileInfo( blobName, - new StoreFileMetadata(fileName, input.length, checksum, Version.CURRENT.luceneVersion.toString()), + new StoreFileMetadata(fileName, input.length, checksum, IndexVersion.CURRENT.luceneVersion.toString()), ByteSizeValue.ofBytes(input.length) ) ); diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/CachedBlobContainerIndexInputTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/CachedBlobContainerIndexInputTests.java index 7e240858fe90e..0ef2c73bdc89c 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/CachedBlobContainerIndexInputTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/CachedBlobContainerIndexInputTests.java @@ -8,7 +8,6 @@ import org.apache.lucene.store.IndexInput; import org.elasticsearch.ExceptionsHelper; -import org.elasticsearch.Version; import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.blobcache.BlobCacheTestUtils; import org.elasticsearch.blobcache.shared.SharedBlobCacheService; @@ -17,6 +16,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.core.Tuple; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardPath; import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot; @@ -75,7 +75,7 @@ public void testRandomReads() throws Exception { fileName, input.length, checksum, - Version.CURRENT.luceneVersion.toString() + IndexVersion.CURRENT.luceneVersion.toString() ); final int partSize = randomBoolean() ? input.length : randomIntBetween(1, input.length); @@ -195,7 +195,7 @@ public void testThrowsEOFException() throws Exception { fileName, input.length, checksum, - Version.CURRENT.luceneVersion.toString() + IndexVersion.CURRENT.luceneVersion.toString() ); final BlobStoreIndexShardSnapshot snapshot = new BlobStoreIndexShardSnapshot( diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/FrozenIndexInputTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/FrozenIndexInputTests.java index f0868a550f6c6..9736016eeab8e 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/FrozenIndexInputTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/FrozenIndexInputTests.java @@ -19,6 +19,7 @@ import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.env.TestEnvironment; import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardPath; import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot; @@ -55,7 +56,7 @@ public void testRandomReads() throws IOException { final FileInfo fileInfo = new FileInfo( randomAlphaOfLength(10), - new StoreFileMetadata(fileName, fileData.length, checksum, Version.CURRENT.luceneVersion.toString()), + new StoreFileMetadata(fileName, fileData.length, checksum, IndexVersion.CURRENT.luceneVersion.toString()), ByteSizeValue.ofBytes(fileData.length) ); diff --git a/x-pack/plugin/snapshot-based-recoveries/src/main/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerService.java b/x-pack/plugin/snapshot-based-recoveries/src/main/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerService.java index 3d625f580e37e..edc434e86f1c2 100644 --- a/x-pack/plugin/snapshot-based-recoveries/src/main/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerService.java +++ b/x-pack/plugin/snapshot-based-recoveries/src/main/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerService.java @@ -13,6 +13,7 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.common.Strings; import org.elasticsearch.core.Nullable; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot; import org.elasticsearch.index.store.Store; @@ -188,7 +189,7 @@ private boolean isSnapshotVersionCompatible(ShardSnapshot snapshot) { // same version. if (commitVersion == null) { assert SEQ_NO_SNAPSHOT_RECOVERIES_SUPPORTED_VERSION.luceneVersion.onOrAfter(snapshot.getCommitLuceneVersion()); - return Version.CURRENT.luceneVersion.onOrAfter(snapshot.getCommitLuceneVersion()); + return IndexVersion.CURRENT.luceneVersion.onOrAfter(snapshot.getCommitLuceneVersion()); } return commitVersion.onOrBefore(Version.CURRENT); } diff --git a/x-pack/plugin/snapshot-based-recoveries/src/test/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerServiceTests.java b/x-pack/plugin/snapshot-based-recoveries/src/test/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerServiceTests.java index 3626b8ea8901e..a83053a189ca9 100644 --- a/x-pack/plugin/snapshot-based-recoveries/src/test/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerServiceTests.java +++ b/x-pack/plugin/snapshot-based-recoveries/src/test/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerServiceTests.java @@ -27,6 +27,7 @@ import org.elasticsearch.core.CheckedConsumer; import org.elasticsearch.core.IOUtils; import org.elasticsearch.index.IndexSettings; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot; import org.elasticsearch.index.store.Store; @@ -220,9 +221,9 @@ public void testLogicallyEquivalentSnapshotIsUsedEvenIfFilesAreDifferent() throw random(), Version.V_7_0_0, RecoverySettings.SNAPSHOT_RECOVERIES_SUPPORTED_VERSION - ).luceneVersion; + ).luceneVersion(); } else { - luceneVersion = randomCompatibleVersion(random(), Version.CURRENT).luceneVersion; + luceneVersion = randomCompatibleVersion(random(), Version.CURRENT).luceneVersion(); } } else { snapshotVersion = Version.fromId(Integer.MAX_VALUE); @@ -603,7 +604,7 @@ private void writeRandomDocs(Store store, int numDocs) throws IOException { } private ShardSnapshot createShardSnapshotThatDoNotShareSegmentFiles(String repoName) { - return createShardSnapshotThatDoNotShareSegmentFiles(repoName, Version.CURRENT, Version.CURRENT.luceneVersion); + return createShardSnapshotThatDoNotShareSegmentFiles(repoName, Version.CURRENT, IndexVersion.CURRENT.luceneVersion); } private ShardSnapshot createShardSnapshotThatDoNotShareSegmentFiles( @@ -632,7 +633,7 @@ private ShardSnapshot createShardSnapshotThatSharesSegmentFiles(Store store, Str ); snapshotFiles.add(fileInfo); } - return createShardSnapshot(repository, snapshotFiles, Version.CURRENT, Version.CURRENT.luceneVersion); + return createShardSnapshot(repository, snapshotFiles, Version.CURRENT, IndexVersion.CURRENT.luceneVersion); } private ShardSnapshot createShardSnapshot( From 0a40ea64673f4a09603cb861c317fd839ad126b4 Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Fri, 31 Mar 2023 14:03:28 +0100 Subject: [PATCH 06/20] Update some tests --- .../admin/indices/create/SplitIndexIT.java | 2 +- .../cluster/metadata/IndexMetadata.java | 2 +- .../metadata/MetadataCreateIndexService.java | 2 +- .../common/settings/IndexScopedSettings.java | 2 +- .../org/elasticsearch/index/IndexVersion.java | 20 +++++++++++++------ .../java/org/elasticsearch/VersionTests.java | 6 ++++-- .../HumanReadableIndexSettingsTests.java | 2 +- .../MetadataCreateIndexServiceTests.java | 2 +- .../indices/analysis/AnalysisModuleTests.java | 10 ++++++++-- .../store/input/FrozenIndexInputTests.java | 1 - .../SnapshotsRecoveryPlannerServiceTests.java | 7 ++----- 11 files changed, 34 insertions(+), 22 deletions(-) diff --git a/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/create/SplitIndexIT.java b/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/create/SplitIndexIT.java index d8c65d1380719..4ebbeb1c83b7b 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/create/SplitIndexIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/create/SplitIndexIT.java @@ -37,8 +37,8 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.core.TimeValue; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.IndexService; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.engine.SegmentsStats; import org.elasticsearch.index.query.TermsQueryBuilder; import org.elasticsearch.index.seqno.SeqNoStats; diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java index 98cba492c401c..e7fa0511db78e 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java @@ -41,9 +41,9 @@ import org.elasticsearch.core.Nullable; import org.elasticsearch.gateway.MetadataStateFormat; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.IndexMode; import org.elasticsearch.index.IndexSettings; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.seqno.SequenceNumbers; import org.elasticsearch.index.shard.IndexLongFieldRange; diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java index 063d7dd487350..8c0d7828275ef 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java @@ -53,7 +53,6 @@ import org.elasticsearch.core.SuppressForbidden; import org.elasticsearch.env.Environment; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.IndexMode; import org.elasticsearch.index.IndexModule; import org.elasticsearch.index.IndexNotFoundException; @@ -61,6 +60,7 @@ import org.elasticsearch.index.IndexSettingProvider; import org.elasticsearch.index.IndexSettingProviders; import org.elasticsearch.index.IndexSettings; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.mapper.DocumentMapper; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.MapperService.MergeReason; diff --git a/server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java b/server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java index bcabd2966ad7a..2da2a01d448bd 100644 --- a/server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java +++ b/server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java @@ -18,10 +18,10 @@ import org.elasticsearch.cluster.routing.allocation.decider.ShardsLimitAllocationDecider; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Setting.Property; -import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.IndexModule; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.IndexSortConfig; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.IndexingSlowLog; import org.elasticsearch.index.MergePolicyConfig; import org.elasticsearch.index.MergeSchedulerConfig; diff --git a/server/src/main/java/org/elasticsearch/index/IndexVersion.java b/server/src/main/java/org/elasticsearch/index/IndexVersion.java index 7f23591edfabb..2bb4ad756ca5a 100644 --- a/server/src/main/java/org/elasticsearch/index/IndexVersion.java +++ b/server/src/main/java/org/elasticsearch/index/IndexVersion.java @@ -90,7 +90,11 @@ public final class IndexVersion implements Comparable { public static final IndexVersion V_7_17_7 = new IndexVersion(7_17_07_99, Version.LUCENE_8_11_1, "b672ff6b-8078-4f6e-b426-6fcf7f8687b4"); public static final IndexVersion V_7_17_8 = new IndexVersion(7_17_08_99, Version.LUCENE_8_11_1, "0faffa1b-5fb3-4439-9367-f154fb25395f"); public static final IndexVersion V_7_17_9 = new IndexVersion(7_17_09_99, Version.LUCENE_8_11_1, "8044989f-77ef-4d6d-9dd8-1bdd805cef74"); - public static final IndexVersion V_7_17_10 = new IndexVersion(7_17_10_99, Version.LUCENE_8_11_1, "66b743fb-8be6-443f-8920-d8c5ed561857"); + public static final IndexVersion V_7_17_10 = new IndexVersion( + 7_17_10_99, + Version.LUCENE_8_11_1, + "66b743fb-8be6-443f-8920-d8c5ed561857" + ); public static final IndexVersion V_8_0_0 = new IndexVersion(8_00_00_99, Version.LUCENE_9_0_0, "ff18a13c-1fa7-4cf7-a3b1-4fdcd9461d5b"); public static final IndexVersion V_8_0_1 = new IndexVersion(8_00_01_99, Version.LUCENE_9_0_0, "4bd5650f-3eff-418f-a7a6-ad46b2a9c941"); public static final IndexVersion V_8_1_0 = new IndexVersion(8_01_00_99, Version.LUCENE_9_0_0, "b4742461-ee43-4fd0-a260-29f8388b82ec"); @@ -145,10 +149,10 @@ static NavigableMap getAllVersionIds(Class cls) { IndexVersion sameUniqueId = uniqueIds.put(version.uniqueId, version); assert sameUniqueId == null : "Versions " - + version - + " and " - + sameUniqueId - + " have the same unique id. Each IndexVersion should have a different unique id"; + + version + + " and " + + sameUniqueId + + " have the same unique id. Each IndexVersion should have a different unique id"; } catch (IllegalAccessException e) { assert false : "IndexVersion field [" + fieldName + "] should be public"; } @@ -164,7 +168,11 @@ static NavigableMap getAllVersionIds(Class cls) { VERSION_IDS = getAllVersionIds(IndexVersion.class); assert CURRENT.luceneVersion.equals(org.apache.lucene.util.Version.LATEST) - : "IndexVersion must be upgraded to [" + org.apache.lucene.util.Version.LATEST + "] is still set to [" + CURRENT.luceneVersion + "]"; + : "IndexVersion must be upgraded to [" + + org.apache.lucene.util.Version.LATEST + + "] is still set to [" + + CURRENT.luceneVersion + + "]"; } static Collection getAllVersions() { diff --git a/server/src/test/java/org/elasticsearch/VersionTests.java b/server/src/test/java/org/elasticsearch/VersionTests.java index 405f29acd153c..c9a8101e4f60e 100644 --- a/server/src/test/java/org/elasticsearch/VersionTests.java +++ b/server/src/test/java/org/elasticsearch/VersionTests.java @@ -253,8 +253,10 @@ public void testLuceneVersionIsSameOnMinorRelease() { for (Version version : VersionUtils.allReleasedVersions()) { for (Version other : VersionUtils.allReleasedVersions()) { if (other.onOrAfter(version)) { - assertTrue("lucene versions must be " + other + " >= " + version, - other.luceneVersion().onOrAfter(version.luceneVersion())); + assertTrue( + "lucene versions must be " + other + " >= " + version, + other.luceneVersion().onOrAfter(version.luceneVersion()) + ); } if (other.major == version.major && other.minor == version.minor) { assertEquals(version + " vs. " + other, other.luceneVersion().major, version.luceneVersion().major); diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/HumanReadableIndexSettingsTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/HumanReadableIndexSettingsTests.java index a18b0daabe62c..14ef7a17ce31d 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/HumanReadableIndexSettingsTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/HumanReadableIndexSettingsTests.java @@ -21,7 +21,7 @@ public class HumanReadableIndexSettingsTests extends ESTestCase { public void testHumanReadableSettings() { - IndexVersion versionCreated = IndexVersion.fromVersion(randomVersion(random())); + IndexVersion versionCreated = randomVersion(random()).indexVersion; long created = System.currentTimeMillis(); Settings testSettings = Settings.builder() .put(IndexMetadata.SETTING_VERSION_CREATED, versionCreated.id) diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexServiceTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexServiceTests.java index 7144ecf1c7ede..40d1221ed7608 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexServiceTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexServiceTests.java @@ -38,11 +38,11 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.core.TimeValue; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.IndexModule; import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.IndexSettingProviders; import org.elasticsearch.index.IndexSettings; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.query.SearchExecutionContext; import org.elasticsearch.indices.EmptySystemIndices; diff --git a/server/src/test/java/org/elasticsearch/indices/analysis/AnalysisModuleTests.java b/server/src/test/java/org/elasticsearch/indices/analysis/AnalysisModuleTests.java index 1207ffac602f5..d23561610c930 100644 --- a/server/src/test/java/org/elasticsearch/indices/analysis/AnalysisModuleTests.java +++ b/server/src/test/java/org/elasticsearch/indices/analysis/AnalysisModuleTests.java @@ -274,7 +274,10 @@ public Map> getTokenizers() { .build() ); assertTokenStreamContents(analyzers.get("no_version").tokenStream("", "test"), new String[] { "testno_version" }); - assertTokenStreamContents(analyzers.get("lucene_version").tokenStream("", "test"), new String[] { "test" + version.luceneVersion() }); + assertTokenStreamContents( + analyzers.get("lucene_version").tokenStream("", "test"), + new String[] { "test" + version.luceneVersion() } + ); assertTokenStreamContents(analyzers.get("elasticsearch_version").tokenStream("", "test"), new String[] { "test" + version }); assertEquals( @@ -340,7 +343,10 @@ public List getPreConfiguredTokenFilters() { .build() ); assertTokenStreamContents(analyzers.get("no_version").tokenStream("", "test"), new String[] { "testno_version" }); - assertTokenStreamContents(analyzers.get("lucene_version").tokenStream("", "test"), new String[] { "test" + version.luceneVersion() }); + assertTokenStreamContents( + analyzers.get("lucene_version").tokenStream("", "test"), + new String[] { "test" + version.luceneVersion() } + ); assertTokenStreamContents(analyzers.get("elasticsearch_version").tokenStream("", "test"), new String[] { "test" + version }); assertEquals( diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/FrozenIndexInputTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/FrozenIndexInputTests.java index 9736016eeab8e..1ea66db8cdb4e 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/FrozenIndexInputTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/FrozenIndexInputTests.java @@ -8,7 +8,6 @@ package org.elasticsearch.xpack.searchablesnapshots.store.input; import org.apache.lucene.store.IndexInput; -import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.blobcache.shared.SharedBlobCacheService; import org.elasticsearch.blobcache.shared.SharedBytes; diff --git a/x-pack/plugin/snapshot-based-recoveries/src/test/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerServiceTests.java b/x-pack/plugin/snapshot-based-recoveries/src/test/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerServiceTests.java index a83053a189ca9..f0e824397de32 100644 --- a/x-pack/plugin/snapshot-based-recoveries/src/test/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerServiceTests.java +++ b/x-pack/plugin/snapshot-based-recoveries/src/test/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerServiceTests.java @@ -217,11 +217,8 @@ public void testLogicallyEquivalentSnapshotIsUsedEvenIfFilesAreDifferent() throw // If snapshotVersion is not present, // then lucene version must be < RecoverySettings.SEQ_NO_SNAPSHOT_RECOVERIES_SUPPORTED_VERSION if (snapshotVersion == null) { - luceneVersion = randomVersionBetween( - random(), - Version.V_7_0_0, - RecoverySettings.SNAPSHOT_RECOVERIES_SUPPORTED_VERSION - ).luceneVersion(); + luceneVersion = randomVersionBetween(random(), Version.V_7_0_0, RecoverySettings.SNAPSHOT_RECOVERIES_SUPPORTED_VERSION) + .luceneVersion(); } else { luceneVersion = randomCompatibleVersion(random(), Version.CURRENT).luceneVersion(); } From a27bbf1b3b1f98b462b8fdca292030ada46b8074 Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Fri, 31 Mar 2023 14:03:37 +0100 Subject: [PATCH 07/20] Only use ES version to determine index compatibility --- .../gradle/internal/BwcVersions.java | 69 +++++++------------ ...stractDistributionDownloadPluginTests.java | 19 +++-- ...ternalDistributionDownloadPluginTests.java | 8 +-- 3 files changed, 38 insertions(+), 58 deletions(-) diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BwcVersions.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BwcVersions.java index 738b328d50650..75cb5767bc28f 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BwcVersions.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BwcVersions.java @@ -65,20 +65,20 @@ public class BwcVersions { private static final Pattern LINE_PATTERN = Pattern.compile( - "\\W+public static final Version V_(\\d+)_(\\d+)_(\\d+)(_alpha\\d+|_beta\\d+|_rc\\d+)? .*?LUCENE_(\\d+)_(\\d+)_(\\d+)\\);" + "\\W+public static final Version V_(\\d+)_(\\d+)_(\\d+)(_alpha\\d+|_beta\\d+|_rc\\d+)? .*;" ); private static final Version MINIMUM_WIRE_COMPATIBLE_VERSION = Version.fromString("7.17.0"); private static final String GLIBC_VERSION_ENV_VAR = "GLIBC_VERSION"; - private final VersionPair currentVersion; - private final List versions; + private final Version currentVersion; + private final List versions; private final Map unreleased; public BwcVersions(List versionLines) { this(versionLines, Version.fromString(VersionProperties.getElasticsearch())); } - public BwcVersions(Version currentVersionProperty, List allVersions) { + public BwcVersions(Version currentVersionProperty, List allVersions) { if (allVersions.isEmpty()) { throw new IllegalArgumentException("Could not parse any versions"); } @@ -95,27 +95,22 @@ public BwcVersions(Version currentVersionProperty, List allVersions this(currentVersionProperty, parseVersionLines(versionLines)); } - private static List parseVersionLines(List versionLines) { + private static List parseVersionLines(List versionLines) { return versionLines.stream() .map(LINE_PATTERN::matcher) .filter(Matcher::matches) - .map( - match -> new VersionPair( - new Version(Integer.parseInt(match.group(1)), Integer.parseInt(match.group(2)), Integer.parseInt(match.group(3))), - new Version(Integer.parseInt(match.group(5)), Integer.parseInt(match.group(6)), Integer.parseInt(match.group(7))) - ) - ) + .map(match -> new Version(Integer.parseInt(match.group(1)), Integer.parseInt(match.group(2)), Integer.parseInt(match.group(3)))) .sorted() .toList(); } private void assertCurrentVersionMatchesParsed(Version currentVersionProperty) { - if (currentVersionProperty.equals(currentVersion.elasticsearch) == false) { + if (currentVersionProperty.equals(currentVersion) == false) { throw new IllegalStateException( "Parsed versions latest version does not match the one configured in build properties. " + "Parsed latest version is " - + currentVersion.elasticsearch + + currentVersion + " but the build has " + currentVersionProperty ); @@ -131,12 +126,12 @@ public UnreleasedVersionInfo unreleasedInfo(Version version) { public void forPreviousUnreleased(Consumer consumer) { filterSupportedVersions( - getUnreleased().stream().filter(version -> version.equals(currentVersion.elasticsearch) == false).collect(Collectors.toList()) + getUnreleased().stream().filter(version -> version.equals(currentVersion) == false).collect(Collectors.toList()) ).stream().map(unreleased::get).forEach(consumer); } private String getBranchFor(Version version) { - if (version.equals(currentVersion.elasticsearch)) { + if (version.equals(currentVersion)) { // Just assume the current branch is 'main'. It's actually not important, we never check out the current branch. return "main"; } else { @@ -145,31 +140,30 @@ private String getBranchFor(Version version) { } private Map computeUnreleased() { - Set unreleased = new TreeSet<>(); + Set unreleased = new TreeSet<>(); // The current version is being worked, is always unreleased unreleased.add(currentVersion); // Recurse for all unreleased versions starting from the current version addUnreleased(unreleased, currentVersion, 0); // Grab the latest version from the previous major if necessary as well, this is going to be a maintenance release - VersionPair maintenance = versions.stream() - .filter(v -> v.elasticsearch.getMajor() == currentVersion.elasticsearch.getMajor() - 1) - .sorted(Comparator.reverseOrder()) - .findFirst() + Version maintenance = versions.stream() + .filter(v -> v.getMajor() == currentVersion.getMajor() - 1) + .min(Comparator.reverseOrder()) .orElseThrow(); // This is considered the maintenance release only if we haven't yet encountered it boolean hasMaintenanceRelease = unreleased.add(maintenance); - List unreleasedList = unreleased.stream().sorted(Comparator.reverseOrder()).toList(); + List unreleasedList = unreleased.stream().sorted(Comparator.reverseOrder()).toList(); Map result = new TreeMap<>(); for (int i = 0; i < unreleasedList.size(); i++) { - Version esVersion = unreleasedList.get(i).elasticsearch; + Version esVersion = unreleasedList.get(i); // This is either a new minor or staged release - if (currentVersion.elasticsearch.equals(esVersion)) { + if (currentVersion.equals(esVersion)) { result.put(esVersion, new UnreleasedVersionInfo(esVersion, getBranchFor(esVersion), ":distribution")); } else if (esVersion.getRevision() == 0) { // If there are two upcoming unreleased minors then this one is the new minor - if (unreleasedList.get(i + 1).elasticsearch.getRevision() == 0) { + if (unreleasedList.get(i + 1).getRevision() == 0) { result.put(esVersion, new UnreleasedVersionInfo(esVersion, getBranchFor(esVersion), ":distribution:bwc:minor")); } else { result.put(esVersion, new UnreleasedVersionInfo(esVersion, getBranchFor(esVersion), ":distribution:bwc:staged")); @@ -191,10 +185,10 @@ public List getUnreleased() { return unreleased.keySet().stream().sorted().toList(); } - private void addUnreleased(Set unreleased, VersionPair current, int index) { - if (current.elasticsearch.getRevision() == 0) { + private void addUnreleased(Set unreleased, Version current, int index) { + if (current.getRevision() == 0) { // If the current version is a new minor, the next version is also unreleased - VersionPair next = versions.get(versions.size() - (index + 2)); + Version next = versions.get(versions.size() - (index + 2)); unreleased.add(next); // Keep looking through versions until we find the end of unreleased versions @@ -229,7 +223,7 @@ public void compareToAuthoritative(List authoritativeReleasedVersions) } private List getReleased() { - return versions.stream().map(v -> v.elasticsearch).filter(v -> unreleased.containsKey(v) == false).toList(); + return versions.stream().filter(v -> unreleased.containsKey(v) == false).toList(); } /** @@ -243,10 +237,8 @@ public List getIndexCompatible() { * Return all versions of Elasticsearch which are index compatible with the current version. */ public List getAllIndexCompatible() { - return versions.stream() - .filter(v -> v.lucene.getMajor() >= (currentVersion.lucene.getMajor() - 1)) - .map(v -> v.elasticsearch) - .toList(); + int minVersion = currentVersion.getMajor() - 1; + return versions.stream().filter(v -> v.getMajor() >= minVersion).toList(); } public void withIndexCompatible(BiConsumer versionAction) { @@ -258,9 +250,7 @@ public void withIndexCompatible(Predicate filter, BiConsumer getWireCompatible() { - return filterSupportedVersions( - versions.stream().map(v -> v.elasticsearch).filter(v -> v.compareTo(MINIMUM_WIRE_COMPATIBLE_VERSION) >= 0).toList() - ); + return filterSupportedVersions(versions.stream().filter(v -> v.compareTo(MINIMUM_WIRE_COMPATIBLE_VERSION) >= 0).toList()); } public void withWireCompatible(BiConsumer versionAction) { @@ -303,15 +293,6 @@ public Version getMinimumWireCompatibleVersion() { public record UnreleasedVersionInfo(Version version, String branch, String gradleProjectPath) {} - public record VersionPair(Version elasticsearch, Version lucene) implements Comparable { - - @Override - public int compareTo(VersionPair o) { - // For ordering purposes, sort by Elasticsearch version - return this.elasticsearch.compareTo(o.elasticsearch); - } - } - /** * Determine whether the given version of Elasticsearch is compatible with ML features on the host system. * diff --git a/build-tools-internal/src/test/java/org/elasticsearch/gradle/AbstractDistributionDownloadPluginTests.java b/build-tools-internal/src/test/java/org/elasticsearch/gradle/AbstractDistributionDownloadPluginTests.java index d93d78cd24533..8b5cae2825441 100644 --- a/build-tools-internal/src/test/java/org/elasticsearch/gradle/AbstractDistributionDownloadPluginTests.java +++ b/build-tools-internal/src/test/java/org/elasticsearch/gradle/AbstractDistributionDownloadPluginTests.java @@ -9,7 +9,6 @@ package org.elasticsearch.gradle; import org.elasticsearch.gradle.internal.BwcVersions; -import org.elasticsearch.gradle.internal.BwcVersions.VersionPair; import org.gradle.api.NamedDomainObjectContainer; import org.gradle.api.Project; import org.gradle.testfixtures.ProjectBuilder; @@ -23,26 +22,26 @@ public class AbstractDistributionDownloadPluginTests { protected static Project packagesProject; protected static Project bwcProject; - protected static final VersionPair BWC_MAJOR_VERSION = new VersionPair(Version.fromString("2.0.0"), Version.fromString("3.0.0")); - protected static final VersionPair BWC_MINOR_VERSION = new VersionPair(Version.fromString("1.1.0"), Version.fromString("2.1.0")); - protected static final VersionPair BWC_STAGED_VERSION = new VersionPair(Version.fromString("1.0.0"), Version.fromString("2.0.0")); - protected static final VersionPair BWC_BUGFIX_VERSION = new VersionPair(Version.fromString("1.0.1"), Version.fromString("2.0.0")); - protected static final VersionPair BWC_MAINTENANCE_VERSION = new VersionPair(Version.fromString("0.90.1"), Version.fromString("1.1.3")); + protected static final Version BWC_MAJOR_VERSION = Version.fromString("2.0.0"); + protected static final Version BWC_MINOR_VERSION = Version.fromString("1.1.0"); + protected static final Version BWC_STAGED_VERSION = Version.fromString("1.0.0"); + protected static final Version BWC_BUGFIX_VERSION = Version.fromString("1.0.1"); + protected static final Version BWC_MAINTENANCE_VERSION = Version.fromString("0.90.1"); protected static final BwcVersions BWC_MINOR = new BwcVersions( - BWC_MAJOR_VERSION.elasticsearch(), + BWC_MAJOR_VERSION, Arrays.asList(BWC_BUGFIX_VERSION, BWC_MINOR_VERSION, BWC_MAJOR_VERSION) ); protected static final BwcVersions BWC_STAGED = new BwcVersions( - BWC_MAJOR_VERSION.elasticsearch(), + BWC_MAJOR_VERSION, Arrays.asList(BWC_MAINTENANCE_VERSION, BWC_STAGED_VERSION, BWC_MINOR_VERSION, BWC_MAJOR_VERSION) ); protected static final BwcVersions BWC_BUGFIX = new BwcVersions( - BWC_MAJOR_VERSION.elasticsearch(), + BWC_MAJOR_VERSION, Arrays.asList(BWC_BUGFIX_VERSION, BWC_MINOR_VERSION, BWC_MAJOR_VERSION) ); protected static final BwcVersions BWC_MAINTENANCE = new BwcVersions( - BWC_MINOR_VERSION.elasticsearch(), + BWC_MINOR_VERSION, Arrays.asList(BWC_MAINTENANCE_VERSION, BWC_BUGFIX_VERSION, BWC_MINOR_VERSION) ); diff --git a/build-tools-internal/src/test/java/org/elasticsearch/gradle/internal/InternalDistributionDownloadPluginTests.java b/build-tools-internal/src/test/java/org/elasticsearch/gradle/internal/InternalDistributionDownloadPluginTests.java index e51890802ffae..de896b459bda5 100644 --- a/build-tools-internal/src/test/java/org/elasticsearch/gradle/internal/InternalDistributionDownloadPluginTests.java +++ b/build-tools-internal/src/test/java/org/elasticsearch/gradle/internal/InternalDistributionDownloadPluginTests.java @@ -41,10 +41,10 @@ public void testLocalBwcPackages() { for (ElasticsearchDistributionType packageType : types) { // note: no non bundled jdk for bwc String configName = projectName(packageType.toString(), true); - checkBwc("minor", configName, BWC_MINOR_VERSION.elasticsearch(), packageType, null, BWC_MINOR); - checkBwc("staged", configName, BWC_STAGED_VERSION.elasticsearch(), packageType, null, BWC_STAGED); - checkBwc("bugfix", configName, BWC_BUGFIX_VERSION.elasticsearch(), packageType, null, BWC_BUGFIX); - checkBwc("maintenance", configName, BWC_MAINTENANCE_VERSION.elasticsearch(), packageType, null, BWC_MAINTENANCE); + checkBwc("minor", configName, BWC_MINOR_VERSION, packageType, null, BWC_MINOR); + checkBwc("staged", configName, BWC_STAGED_VERSION, packageType, null, BWC_STAGED); + checkBwc("bugfix", configName, BWC_BUGFIX_VERSION, packageType, null, BWC_BUGFIX); + checkBwc("maintenance", configName, BWC_MAINTENANCE_VERSION, packageType, null, BWC_MAINTENANCE); } } } From fa3ef89bd2976f1f827a6303d4c9a3faf5cc2c1a Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Fri, 31 Mar 2023 14:07:52 +0100 Subject: [PATCH 08/20] Add new index version --- server/src/main/java/org/elasticsearch/index/IndexVersion.java | 1 + 1 file changed, 1 insertion(+) diff --git a/server/src/main/java/org/elasticsearch/index/IndexVersion.java b/server/src/main/java/org/elasticsearch/index/IndexVersion.java index 2bb4ad756ca5a..453d5e1bdd6d4 100644 --- a/server/src/main/java/org/elasticsearch/index/IndexVersion.java +++ b/server/src/main/java/org/elasticsearch/index/IndexVersion.java @@ -122,6 +122,7 @@ public final class IndexVersion implements Comparable { public static final IndexVersion V_8_6_2 = new IndexVersion(8_06_02_99, Version.LUCENE_9_4_2, "e1e73b88-d188-4d82-b5e1-dee261418783"); public static final IndexVersion V_8_6_3 = new IndexVersion(8_06_03_99, Version.LUCENE_9_4_2, "b3d4a28b-4e0c-47dc-b1e9-5640c0749937"); public static final IndexVersion V_8_7_0 = new IndexVersion(8_07_00_99, Version.LUCENE_9_5_0, "f9227941-d6f4-462b-957f-2bcd36c28382"); + public static final IndexVersion V_8_7_1 = new IndexVersion(8_07_01_99, Version.LUCENE_9_5_0, "758780b8-4b0c-44c6-af5d-fdac10b6093a"); public static final IndexVersion V_8_8_0 = new IndexVersion(8_08_00_99, Version.LUCENE_9_6_0, "d6ffc8d7-f6bd-469b-8495-01688c310000"); public static final IndexVersion CURRENT = V_8_8_0; From 5d20069e25c7550a938586cc8ca55da352b1e923 Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Fri, 31 Mar 2023 14:17:16 +0100 Subject: [PATCH 09/20] Fix class constructor --- .../src/main/java/org/elasticsearch/index/IndexVersion.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/index/IndexVersion.java b/server/src/main/java/org/elasticsearch/index/IndexVersion.java index 453d5e1bdd6d4..297eee26590ad 100644 --- a/server/src/main/java/org/elasticsearch/index/IndexVersion.java +++ b/server/src/main/java/org/elasticsearch/index/IndexVersion.java @@ -9,7 +9,6 @@ package org.elasticsearch.index; import org.apache.lucene.util.Version; -import org.elasticsearch.TransportVersion; import org.elasticsearch.common.Strings; import java.lang.reflect.Field; @@ -120,7 +119,6 @@ public final class IndexVersion implements Comparable { public static final IndexVersion V_8_6_0 = new IndexVersion(8_06_00_99, Version.LUCENE_9_4_2, "5e78c76c-74aa-464e-9383-89bdffb74db9"); public static final IndexVersion V_8_6_1 = new IndexVersion(8_06_01_99, Version.LUCENE_9_4_2, "8dc502be-ef27-43b3-a27b-1cb925cbef7d"); public static final IndexVersion V_8_6_2 = new IndexVersion(8_06_02_99, Version.LUCENE_9_4_2, "e1e73b88-d188-4d82-b5e1-dee261418783"); - public static final IndexVersion V_8_6_3 = new IndexVersion(8_06_03_99, Version.LUCENE_9_4_2, "b3d4a28b-4e0c-47dc-b1e9-5640c0749937"); public static final IndexVersion V_8_7_0 = new IndexVersion(8_07_00_99, Version.LUCENE_9_5_0, "f9227941-d6f4-462b-957f-2bcd36c28382"); public static final IndexVersion V_8_7_1 = new IndexVersion(8_07_01_99, Version.LUCENE_9_5_0, "758780b8-4b0c-44c6-af5d-fdac10b6093a"); public static final IndexVersion V_8_8_0 = new IndexVersion(8_08_00_99, Version.LUCENE_9_6_0, "d6ffc8d7-f6bd-469b-8495-01688c310000"); @@ -135,7 +133,7 @@ static NavigableMap getAllVersionIds(Class cls) { Set ignore = Set.of("ZERO", "CURRENT", "MINIMUM_COMPATIBLE"); for (Field declaredField : cls.getFields()) { - if (declaredField.getType().equals(TransportVersion.class)) { + if (declaredField.getType().equals(IndexVersion.class)) { String fieldName = declaredField.getName(); if (ignore.contains(fieldName)) { continue; From a482e9fbbe53510da192bb09790642e5eff56035 Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Wed, 19 Apr 2023 09:10:29 +0100 Subject: [PATCH 10/20] Use natural order comparator --- .../java/org/elasticsearch/gradle/internal/BwcVersions.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BwcVersions.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BwcVersions.java index 5c02d9781a0c0..2a2d297165e30 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BwcVersions.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BwcVersions.java @@ -148,7 +148,7 @@ private Map computeUnreleased() { // Grab the latest version from the previous major if necessary as well, this is going to be a maintenance release Version maintenance = versions.stream() .filter(v -> v.getMajor() == currentVersion.getMajor() - 1) - .min(Comparator.reverseOrder()) + .max(Comparator.naturalOrder()) .orElseThrow(); // This is considered the maintenance release only if we haven't yet encountered it boolean hasMaintenanceRelease = unreleased.add(maintenance); From 204a892297be38bb7bb2329d7bb8f84de954e888 Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Thu, 4 May 2023 10:57:54 +0100 Subject: [PATCH 11/20] exclude IndexVersion from spotless --- server/build.gradle | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server/build.gradle b/server/build.gradle index 1a58732a9b9da..a3215797eb99b 100644 --- a/server/build.gradle +++ b/server/build.gradle @@ -81,6 +81,12 @@ dependencies { } +spotless { + java { + targetExclude "src/main/java/org/elasticsearch/index/IndexVersion.java" + } +} + tasks.named("forbiddenPatterns").configure { exclude '**/*.json' exclude '**/*.jmx' From 32fcb3cd1f7a175830db4f888b05b50c119947de Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Thu, 4 May 2023 10:59:37 +0100 Subject: [PATCH 12/20] Add deprecation notices on Version members --- server/src/main/java/org/elasticsearch/Version.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/src/main/java/org/elasticsearch/Version.java b/server/src/main/java/org/elasticsearch/Version.java index e4eb25656e5ab..c669f7b52371d 100644 --- a/server/src/main/java/org/elasticsearch/Version.java +++ b/server/src/main/java/org/elasticsearch/Version.java @@ -290,6 +290,7 @@ private static Version fromStringSlow(String version) { public final byte minor; public final byte revision; public final byte build; + @Deprecated(forRemoval = true) public final IndexVersion indexVersion; private final String toString; private final int previousMajorId; @@ -331,6 +332,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws return builder.value(toString()); } + @Deprecated(forRemoval = true) public org.apache.lucene.util.Version luceneVersion() { return indexVersion.luceneVersion; } From efaf40a1ab7c3561c6ed6343f3e9c9af29049bb8 Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Fri, 5 May 2023 11:35:47 +0100 Subject: [PATCH 13/20] Convert IndexVersion to a record --- .../upgrades/FullClusterRestartIT.java | 2 +- .../plan/ShardSnapshotsServiceIT.java | 2 +- .../main/java/org/elasticsearch/Version.java | 2 +- .../bootstrap/Elasticsearch.java | 4 +- .../cluster/metadata/IndexMetadata.java | 2 +- .../org/elasticsearch/index/IndexVersion.java | 300 +++++++++++------- .../elasticsearch/index/shard/IndexShard.java | 2 +- .../org/elasticsearch/index/store/Store.java | 2 +- .../HumanReadableIndexSettingsTests.java | 2 +- .../gateway/ReplicaShardAllocatorTests.java | 2 +- .../index/engine/InternalEngineTests.java | 2 +- .../snapshots/blobstore/FileInfoTests.java | 2 +- .../elasticsearch/index/store/StoreTests.java | 2 +- .../indices/recovery/RecoveryStatusTests.java | 2 +- .../ShardSnapshotTaskRunnerTests.java | 2 +- .../org/elasticsearch/test/ESTestCase.java | 2 +- ...SearchableSnapshotDirectoryStatsTests.java | 2 +- .../SearchableSnapshotDirectoryTests.java | 2 +- .../CachedBlobContainerIndexInputTests.java | 4 +- .../store/input/FrozenIndexInputTests.java | 2 +- .../plan/SnapshotsRecoveryPlannerService.java | 4 +- .../SnapshotsRecoveryPlannerServiceTests.java | 4 +- 22 files changed, 204 insertions(+), 146 deletions(-) diff --git a/qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/upgrades/FullClusterRestartIT.java b/qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/upgrades/FullClusterRestartIT.java index f7ab21f141b7d..6736e8d8c1fcc 100644 --- a/qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/upgrades/FullClusterRestartIT.java +++ b/qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/upgrades/FullClusterRestartIT.java @@ -959,7 +959,7 @@ public void testRecovery() throws Exception { 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 currentLuceneVersion = IndexVersion.CURRENT.luceneVersion().toString(); String bwcLuceneVersion = getOldClusterVersion().luceneVersion().toString(); String minCompatibleBWCVersion = Version.CURRENT.minimumCompatibilityVersion().luceneVersion().toString(); if (shouldHaveTranslog && false == currentLuceneVersion.equals(bwcLuceneVersion)) { diff --git a/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/plan/ShardSnapshotsServiceIT.java b/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/plan/ShardSnapshotsServiceIT.java index 842a83589b625..3ffd81d1ed96f 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/plan/ShardSnapshotsServiceIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/plan/ShardSnapshotsServiceIT.java @@ -193,7 +193,7 @@ public void testOnlyFetchesSnapshotFromEnabledRepositories() throws Exception { assertThat(commitVersion, is(equalTo(Version.CURRENT))); final org.apache.lucene.util.Version commitLuceneVersion = shardSnapshotData.getCommitLuceneVersion(); assertThat(commitLuceneVersion, is(notNullValue())); - assertThat(commitLuceneVersion, is(equalTo(IndexVersion.CURRENT.luceneVersion))); + assertThat(commitLuceneVersion, is(equalTo(IndexVersion.CURRENT.luceneVersion()))); assertThat(shardSnapshotInfo.getShardId(), is(equalTo(shardId))); assertThat(shardSnapshotInfo.getSnapshot().getSnapshotId().getName(), is(equalTo(snapshotName))); diff --git a/server/src/main/java/org/elasticsearch/Version.java b/server/src/main/java/org/elasticsearch/Version.java index c669f7b52371d..ce6db2104b8b1 100644 --- a/server/src/main/java/org/elasticsearch/Version.java +++ b/server/src/main/java/org/elasticsearch/Version.java @@ -334,7 +334,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws @Deprecated(forRemoval = true) public org.apache.lucene.util.Version luceneVersion() { - return indexVersion.luceneVersion; + return indexVersion.luceneVersion(); } /* diff --git a/server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java b/server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java index d5d6471444f9e..e42c7b06edb43 100644 --- a/server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java +++ b/server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java @@ -323,10 +323,10 @@ static void initializeProbes() { } static void checkLucene() { - if (IndexVersion.CURRENT.luceneVersion.equals(org.apache.lucene.util.Version.LATEST) == false) { + if (IndexVersion.CURRENT.luceneVersion().equals(org.apache.lucene.util.Version.LATEST) == false) { throw new AssertionError( "Lucene version mismatch this version of Elasticsearch requires lucene version [" - + IndexVersion.CURRENT.luceneVersion + + IndexVersion.CURRENT.luceneVersion() + "] but the current lucene version is [" + org.apache.lucene.util.Version.LATEST + "]" diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java index e1f2c416f204f..910b4fea35895 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java @@ -340,7 +340,7 @@ public static APIBlock readFrom(StreamInput input) throws IOException { public static final Setting SETTING_INDEX_VERSION_CREATED = new Setting<>( SETTING_VERSION_CREATED, - Integer.toString(IndexVersion.ZERO.id), + Integer.toString(IndexVersion.ZERO.id()), s -> IndexVersion.fromId(Integer.parseInt(s)), Property.IndexScope, Property.PrivateIndex diff --git a/server/src/main/java/org/elasticsearch/index/IndexVersion.java b/server/src/main/java/org/elasticsearch/index/IndexVersion.java index 126b8722dd3af..a16298689226c 100644 --- a/server/src/main/java/org/elasticsearch/index/IndexVersion.java +++ b/server/src/main/java/org/elasticsearch/index/IndexVersion.java @@ -10,6 +10,7 @@ import org.apache.lucene.util.Version; import org.elasticsearch.common.Strings; +import org.elasticsearch.core.Assertions; import java.lang.reflect.Field; import java.util.Collection; @@ -17,7 +18,6 @@ import java.util.HashMap; import java.util.Map; import java.util.NavigableMap; -import java.util.Objects; import java.util.Set; import java.util.TreeMap; @@ -26,133 +26,201 @@ *

* Prior to 8.8.0, the node {@link Version} was used everywhere. This class separates the index format version * from the running node version. + *

+ * Each index version constant has an id number, which for versions prior to 8.9.0 is the same as the release version + * for backwards compatibility. In 8.9.0 this is changed to an incrementing number, disconnected from the release version. + *

+ * Each version constant has a unique id string. This is not actually stored in the index, but is there to ensure + * each index version is only added to the source file once. This string needs to be unique (normally a UUID, + * but can be any other unique nonempty string). + * If two concurrent PRs add the same index version, the different unique ids cause a git conflict, ensuring the second PR to be merged + * must be updated with the next free version first. Without the unique id string, git will happily merge the two versions together, + * resulting in the same index version being used across multiple commits, + * causing problems when you try to upgrade between those two merged commits. + *

Version compatibility

+ * The earliest compatible version is hardcoded in the {@link #MINIMUM_COMPATIBLE} field. Previously, this was dynamically calculated + * from the major/minor versions of {@link Version}, but {@code IndexVersion} does not have separate major/minor version numbers. + * So the minimum compatible version is hard-coded as the index version used by the first version of the previous major release. + * {@link #MINIMUM_COMPATIBLE} should be updated appropriately whenever a major release happens. + *

Adding a new version

+ * A new index version should be added every time a change is made to the serialization protocol of one or more classes. + * Each index version should only be used in a single merged commit (apart from BwC versions copied from {@link Version}). + *

+ * To add a new index version, add a new constant at the bottom of the list that is one greater than the current highest version, + * ensure it has a unique id, and update the {@link #CURRENT} constant to point to the new version. + *

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. */ -@SuppressWarnings("checkstyle:linelength") -public final class IndexVersion implements Comparable { - public static final IndexVersion ZERO = new IndexVersion(0, Version.LATEST, "00000000-0000-0000-0000-000000000000"); - public static final IndexVersion V_7_0_0 = new IndexVersion(7_00_00_99, Version.LUCENE_8_0_0, "b32be92d-c403-4858-a4a3-20d699a47ae6"); - public static final IndexVersion V_7_0_1 = new IndexVersion(7_00_01_99, Version.LUCENE_8_0_0, "a03ed728-eac8-4e50-bcce-864806bb10e0"); - public static final IndexVersion V_7_1_0 = new IndexVersion(7_01_00_99, Version.LUCENE_8_0_0, "f9964d87-9f20-4b26-af32-be1f979216ec"); - public static final IndexVersion V_7_1_1 = new IndexVersion(7_01_01_99, Version.LUCENE_8_0_0, "29a3fb69-55d0-4389-aea9-96c98ce23830"); - public static final IndexVersion V_7_2_0 = new IndexVersion(7_02_00_99, Version.LUCENE_8_0_0, "dba49448-87d4-45bb-ba19-f7b4eb85c757"); - public static final IndexVersion V_7_2_1 = new IndexVersion(7_02_01_99, Version.LUCENE_8_0_0, "58874b45-f9f8-4c04-92a9-67548a8b21c3"); - public static final IndexVersion V_7_3_0 = new IndexVersion(7_03_00_99, Version.LUCENE_8_1_0, "3d8a21df-58a4-4d7a-ba5d-438c92c16a7b"); - public static final IndexVersion V_7_3_1 = new IndexVersion(7_03_01_99, Version.LUCENE_8_1_0, "5687797f-448b-490d-94d4-d7e8cfac0c98"); - public static final IndexVersion V_7_3_2 = new IndexVersion(7_03_02_99, Version.LUCENE_8_1_0, "5a3462e5-d2fe-4b7b-9a7e-c0234412271f"); - public static final IndexVersion V_7_4_0 = new IndexVersion(7_04_00_99, Version.LUCENE_8_2_0, "c1fe73ba-0173-476c-aba2-855c2b31ac18"); - public static final IndexVersion V_7_4_1 = new IndexVersion(7_04_01_99, Version.LUCENE_8_2_0, "8a917374-bd4f-45e3-9052-575c4cf741cd"); - public static final IndexVersion V_7_4_2 = new IndexVersion(7_04_02_99, Version.LUCENE_8_2_0, "f073a867-cba2-41e4-8150-a2f2a96f1e0b"); - public static final IndexVersion V_7_5_0 = new IndexVersion(7_05_00_99, Version.LUCENE_8_3_0, "ab08ae25-ede2-4e57-a43f-89d96aa989e4"); - public static final IndexVersion V_7_5_1 = new IndexVersion(7_05_01_99, Version.LUCENE_8_3_0, "a386d62e-cb85-4a37-b5f9-c9468bbfc457"); - public static final IndexVersion V_7_5_2 = new IndexVersion(7_05_02_99, Version.LUCENE_8_3_0, "706715ca-3b91-40d2-8c2e-c34c459b5d0d"); - public static final IndexVersion V_7_6_0 = new IndexVersion(7_06_00_99, Version.LUCENE_8_4_0, "63acbdb9-51c8-4976-bb3d-e55052a4fbd4"); - public static final IndexVersion V_7_6_1 = new IndexVersion(7_06_01_99, Version.LUCENE_8_4_0, "1acc33d3-28dc-448d-953a-664dad3bf1f5"); - public static final IndexVersion V_7_6_2 = new IndexVersion(7_06_02_99, Version.LUCENE_8_4_0, "3aa17069-fa04-4bf9-96af-fe8b903faa75"); - public static final IndexVersion V_7_7_0 = new IndexVersion(7_07_00_99, Version.LUCENE_8_5_1, "6fff8238-e6ce-4fb2-85de-196492026e49"); - public static final IndexVersion V_7_7_1 = new IndexVersion(7_07_01_99, Version.LUCENE_8_5_1, "4ce6641d-157b-4c59-8261-7997ac0f6e40"); - public static final IndexVersion V_7_8_0 = new IndexVersion(7_08_00_99, Version.LUCENE_8_5_1, "81d7d459-f386-4c20-8235-f8fce8af7f0e"); - public static final IndexVersion V_7_8_1 = new IndexVersion(7_08_01_99, Version.LUCENE_8_5_1, "a1b015bc-d020-453f-85a6-9413e169304a"); - public static final IndexVersion V_7_9_0 = new IndexVersion(7_09_00_99, Version.LUCENE_8_6_0, "0fa951a2-43ce-4f76-91bf-066c1ecf8a93"); - public static final IndexVersion V_7_9_1 = new IndexVersion(7_09_01_99, Version.LUCENE_8_6_2, "5fc4aabc-080e-4840-af4f-a724deba98b1"); - public static final IndexVersion V_7_9_2 = new IndexVersion(7_09_02_99, Version.LUCENE_8_6_2, "ef824617-332e-4b63-969e-ebb73a868462"); - public static final IndexVersion V_7_9_3 = new IndexVersion(7_09_03_99, Version.LUCENE_8_6_2, "499c810a-0f37-4dfd-92ad-55e4936f3578"); - public static final IndexVersion V_7_10_0 = new IndexVersion(7_10_00_99, Version.LUCENE_8_7_0, "92ccd91c-0251-4263-8873-9f1abfac3c10"); - public static final IndexVersion V_7_10_1 = new IndexVersion(7_10_01_99, Version.LUCENE_8_7_0, "8ce37467-964f-43eb-ad2d-a51a50116868"); - public static final IndexVersion V_7_10_2 = new IndexVersion(7_10_02_99, Version.LUCENE_8_7_0, "cb277ccb-3081-4238-be2c-c3167316a435"); - public static final IndexVersion V_7_11_0 = new IndexVersion(7_11_00_99, Version.LUCENE_8_7_0, "e6d65f96-26d5-4669-ac5a-2964b9b1699f"); - public static final IndexVersion V_7_11_1 = new IndexVersion(7_11_01_99, Version.LUCENE_8_7_0, "e3655b78-14f7-4432-aa28-34cd1ef2d229"); - public static final IndexVersion V_7_11_2 = new IndexVersion(7_11_02_99, Version.LUCENE_8_7_0, "1ecfd0ee-4868-4384-b2a0-af6ecb01e496"); - public static final IndexVersion V_7_12_0 = new IndexVersion(7_12_00_99, Version.LUCENE_8_8_0, "39e2989a-a9a4-4f1a-b185-2e6015f74b1c"); - public static final IndexVersion V_7_12_1 = new IndexVersion(7_12_01_99, Version.LUCENE_8_8_0, "a8307f67-8295-4567-a7eb-2a6e69046282"); - public static final IndexVersion V_7_13_0 = new IndexVersion(7_13_00_99, Version.LUCENE_8_8_2, "28b21fe0-4d1f-4c04-95cc-74df494ae0cf"); - public static final IndexVersion V_7_13_1 = new IndexVersion(7_13_01_99, Version.LUCENE_8_8_2, "4952d7a7-d9f5-443b-b362-8c5ebdc57f81"); - public static final IndexVersion V_7_13_2 = new IndexVersion(7_13_02_99, Version.LUCENE_8_8_2, "d77c4245-9d26-4da3-aa61-78ab34c3c792"); - public static final IndexVersion V_7_13_3 = new IndexVersion(7_13_03_99, Version.LUCENE_8_8_2, "a263a47e-4075-4c68-8a42-15a37455c30f"); - public static final IndexVersion V_7_13_4 = new IndexVersion(7_13_04_99, Version.LUCENE_8_8_2, "d17644c8-3144-495d-8f6c-42cd36698e98"); - public static final IndexVersion V_7_14_0 = new IndexVersion(7_14_00_99, Version.LUCENE_8_9_0, "b45bb223-bb73-4379-a46f-7dc74d38aaca"); - public static final IndexVersion V_7_14_1 = new IndexVersion(7_14_01_99, Version.LUCENE_8_9_0, "ee4a6d62-9e05-490b-93dd-b316f9a62d71"); - public static final IndexVersion V_7_14_2 = new IndexVersion(7_14_02_99, Version.LUCENE_8_9_0, "285d3293-2896-431c-97dd-180890840947"); - public static final IndexVersion V_7_15_0 = new IndexVersion(7_15_00_99, Version.LUCENE_8_9_0, "ab666b02-b866-4b64-9ba3-d511e86c55b5"); - public static final IndexVersion V_7_15_1 = new IndexVersion(7_15_01_99, Version.LUCENE_8_9_0, "5643957d-9b68-414a-8917-ea75cf549f67"); - public static final IndexVersion V_7_15_2 = new IndexVersion(7_15_02_99, Version.LUCENE_8_9_0, "1a618039-d665-47ce-b6ca-886e88c64051"); - public static final IndexVersion V_7_16_0 = new IndexVersion(7_16_00_99, Version.LUCENE_8_10_1, "a582e900-2d92-474c-9be3-2e08fa88be4b"); - public static final IndexVersion V_7_16_1 = new IndexVersion(7_16_01_99, Version.LUCENE_8_10_1, "bf666306-9b0d-468b-99dc-f2706dae9c11"); - public static final IndexVersion V_7_16_2 = new IndexVersion(7_16_02_99, Version.LUCENE_8_10_1, "167c6d69-cae2-4281-8f37-984231620ee9"); - public static final IndexVersion V_7_16_3 = new IndexVersion(7_16_03_99, Version.LUCENE_8_10_1, "5d25a795-2be6-4663-93dc-10d88efb7e3d"); - public static final IndexVersion V_7_17_0 = new IndexVersion(7_17_00_99, Version.LUCENE_8_11_1, "18766ab8-4691-40a2-94f1-526f3b71420c"); - public static final IndexVersion V_7_17_1 = new IndexVersion(7_17_01_99, Version.LUCENE_8_11_1, "8ad49144-4a1c-4322-b33d-614a569fba9b"); - public static final IndexVersion V_7_17_2 = new IndexVersion(7_17_02_99, Version.LUCENE_8_11_1, "50033cde-c905-4923-83d6-8139f3f110e1"); - public static final IndexVersion V_7_17_3 = new IndexVersion(7_17_03_99, Version.LUCENE_8_11_1, "460b91d1-4f3d-4f56-8dca-8d9e15f5b862"); - public static final IndexVersion V_7_17_4 = new IndexVersion(7_17_04_99, Version.LUCENE_8_11_1, "26e40d6f-ac7c-43a3-bd0c-1ec6c3093f66"); - public static final IndexVersion V_7_17_5 = new IndexVersion(7_17_05_99, Version.LUCENE_8_11_1, "d80bc13c-7139-4ff9-979d-42701d480e33"); - public static final IndexVersion V_7_17_6 = new IndexVersion(7_17_06_99, Version.LUCENE_8_11_1, "0b47328e-341a-4f97-927d-c49f5050778d"); - public static final IndexVersion V_7_17_7 = new IndexVersion(7_17_07_99, Version.LUCENE_8_11_1, "b672ff6b-8078-4f6e-b426-6fcf7f8687b4"); - public static final IndexVersion V_7_17_8 = new IndexVersion(7_17_08_99, Version.LUCENE_8_11_1, "0faffa1b-5fb3-4439-9367-f154fb25395f"); - public static final IndexVersion V_7_17_9 = new IndexVersion(7_17_09_99, Version.LUCENE_8_11_1, "8044989f-77ef-4d6d-9dd8-1bdd805cef74"); - public static final IndexVersion V_7_17_10 = new IndexVersion(7_17_10_99, Version.LUCENE_8_11_1, "66b743fb-8be6-443f-8920-d8c5ed561857"); - public static final IndexVersion V_7_17_11 = new IndexVersion(7_17_11_99, Version.LUCENE_8_11_1, "f1935acc-1af9-44b0-97e9-67112d333753"); - public static final IndexVersion V_8_0_0 = new IndexVersion(8_00_00_99, Version.LUCENE_9_0_0, "ff18a13c-1fa7-4cf7-a3b1-4fdcd9461d5b"); - public static final IndexVersion V_8_0_1 = new IndexVersion(8_00_01_99, Version.LUCENE_9_0_0, "4bd5650f-3eff-418f-a7a6-ad46b2a9c941"); - public static final IndexVersion V_8_1_0 = new IndexVersion(8_01_00_99, Version.LUCENE_9_0_0, "b4742461-ee43-4fd0-a260-29f8388b82ec"); - public static final IndexVersion V_8_1_1 = new IndexVersion(8_01_01_99, Version.LUCENE_9_0_0, "3883e088-9a1c-4494-8d71-768820485f33"); - public static final IndexVersion V_8_1_2 = new IndexVersion(8_01_02_99, Version.LUCENE_9_0_0, "859a745a-81d3-463e-af58-615179a22d4f"); - public static final IndexVersion V_8_1_3 = new IndexVersion(8_01_03_99, Version.LUCENE_9_0_0, "27a49f3f-d3ac-4b0e-8bba-1be24daf4a56"); - public static final IndexVersion V_8_2_0 = new IndexVersion(8_02_00_99, Version.LUCENE_9_1_0, "af0ed990-2f32-42b5-aaf3-59d21a3dca7a"); - public static final IndexVersion V_8_2_1 = new IndexVersion(8_02_01_99, Version.LUCENE_9_1_0, "6e2a3812-062a-4d08-8c35-ddc930e8e246"); - public static final IndexVersion V_8_2_2 = new IndexVersion(8_02_02_99, Version.LUCENE_9_1_0, "93d1434c-3956-408b-8204-93be8ab78856"); - public static final IndexVersion V_8_2_3 = new IndexVersion(8_02_03_99, Version.LUCENE_9_1_0, "026f6904-2a04-4476-8097-02a75e37e0f7"); - public static final IndexVersion V_8_3_0 = new IndexVersion(8_03_00_99, Version.LUCENE_9_2_0, "eca8e8a3-0724-4247-a58d-e4eafcec4b3f"); - public static final IndexVersion V_8_3_1 = new IndexVersion(8_03_01_99, Version.LUCENE_9_2_0, "dac08798-c0b5-46c9-bf27-d82c617ce41f"); - public static final IndexVersion V_8_3_2 = new IndexVersion(8_03_02_99, Version.LUCENE_9_2_0, "2a0c5fb9-e8a5-4788-89f8-f5723bd68cee"); - public static final IndexVersion V_8_3_3 = new IndexVersion(8_03_03_99, Version.LUCENE_9_2_0, "440a5f5c-767a-49f7-8593-dc7627b30397"); - public static final IndexVersion V_8_4_0 = new IndexVersion(8_04_00_99, Version.LUCENE_9_3_0, "d27324da-b36c-452a-93a8-9b69a6c302a1"); - public static final IndexVersion V_8_4_1 = new IndexVersion(8_04_01_99, Version.LUCENE_9_3_0, "44108ecd-839b-423e-9ef1-9d457f244fff"); - public static final IndexVersion V_8_4_2 = new IndexVersion(8_04_02_99, Version.LUCENE_9_3_0, "9c20ed39-8c32-4cf0-9f06-42735cbf604e"); - public static final IndexVersion V_8_4_3 = new IndexVersion(8_04_03_99, Version.LUCENE_9_3_0, "e7d17607-47c0-4662-b308-beeb9a8ec552"); - public static final IndexVersion V_8_5_0 = new IndexVersion(8_05_00_99, Version.LUCENE_9_4_1, "c5284b51-7fee-4f34-a837-241bb57a7aa6"); - public static final IndexVersion V_8_5_1 = new IndexVersion(8_05_01_99, Version.LUCENE_9_4_1, "b23a983c-9630-4a2b-8352-0f52b55ff87e"); - public static final IndexVersion V_8_5_2 = new IndexVersion(8_05_02_99, Version.LUCENE_9_4_1, "cfc80b6f-cb5c-4a4c-b3af-5fa1000508a8"); - public static final IndexVersion V_8_5_3 = new IndexVersion(8_05_03_99, Version.LUCENE_9_4_2, "f8ac8061-1b17-4cab-b2f6-94df31f7552e"); - public static final IndexVersion V_8_6_0 = new IndexVersion(8_06_00_99, Version.LUCENE_9_4_2, "5e78c76c-74aa-464e-9383-89bdffb74db9"); - public static final IndexVersion V_8_6_1 = new IndexVersion(8_06_01_99, Version.LUCENE_9_4_2, "8dc502be-ef27-43b3-a27b-1cb925cbef7d"); - public static final IndexVersion V_8_6_2 = new IndexVersion(8_06_02_99, Version.LUCENE_9_4_2, "e1e73b88-d188-4d82-b5e1-dee261418783"); - public static final IndexVersion V_8_7_0 = new IndexVersion(8_07_00_99, Version.LUCENE_9_5_0, "f9227941-d6f4-462b-957f-2bcd36c28382"); - public static final IndexVersion V_8_7_1 = new IndexVersion(8_07_01_99, Version.LUCENE_9_5_0, "758780b8-4b0c-44c6-af5d-fdac10b6093a"); - public static final IndexVersion V_8_7_2 = new IndexVersion(8_07_02_99, Version.LUCENE_9_5_0, "d896de80-420f-4616-9d74-7e7219446bbd"); - public static final IndexVersion V_8_8_0 = new IndexVersion(8_08_00_99, Version.LUCENE_9_6_0, "d6ffc8d7-f6bd-469b-8495-01688c310000"); - public static final IndexVersion V_8_9_0 = new IndexVersion(8_09_00_99, Version.LUCENE_9_6_0, "32f6dbab-cc24-4f5b-87b5-015a848480d9"); +@SuppressWarnings({"checkstyle:linelength", "deprecation"}) +public record IndexVersion(int id, Version luceneVersion) implements Comparable { + + /* + * 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. + */ + private static Map IDS = new HashMap<>(); + + private static IndexVersion registerIndexVersion(int id, Version luceneVersion, String uniqueId) { + if (IDS == null) throw new IllegalStateException("The IDS map needs to be present to call this method"); + + Strings.requireNonEmpty(uniqueId, "Each IndexVersion needs a unique string id"); + Integer existing = IDS.put(uniqueId, id); + if (existing != null) { + throw new IllegalArgumentException("Versions " + id + " and " + existing + " have the same unique id"); + } + return new IndexVersion(id, luceneVersion); + } + + public static final IndexVersion ZERO = registerIndexVersion(0, Version.LATEST, "00000000-0000-0000-0000-000000000000"); + public static final IndexVersion V_7_0_0 = registerIndexVersion(7_00_00_99, Version.LUCENE_8_0_0, "b32be92d-c403-4858-a4a3-20d699a47ae6"); + public static final IndexVersion V_7_0_1 = registerIndexVersion(7_00_01_99, Version.LUCENE_8_0_0, "a03ed728-eac8-4e50-bcce-864806bb10e0"); + public static final IndexVersion V_7_1_0 = registerIndexVersion(7_01_00_99, Version.LUCENE_8_0_0, "f9964d87-9f20-4b26-af32-be1f979216ec"); + public static final IndexVersion V_7_1_1 = registerIndexVersion(7_01_01_99, Version.LUCENE_8_0_0, "29a3fb69-55d0-4389-aea9-96c98ce23830"); + public static final IndexVersion V_7_2_0 = registerIndexVersion(7_02_00_99, Version.LUCENE_8_0_0, "dba49448-87d4-45bb-ba19-f7b4eb85c757"); + public static final IndexVersion V_7_2_1 = registerIndexVersion(7_02_01_99, Version.LUCENE_8_0_0, "58874b45-f9f8-4c04-92a9-67548a8b21c3"); + public static final IndexVersion V_7_3_0 = registerIndexVersion(7_03_00_99, Version.LUCENE_8_1_0, "3d8a21df-58a4-4d7a-ba5d-438c92c16a7b"); + public static final IndexVersion V_7_3_1 = registerIndexVersion(7_03_01_99, Version.LUCENE_8_1_0, "5687797f-448b-490d-94d4-d7e8cfac0c98"); + public static final IndexVersion V_7_3_2 = registerIndexVersion(7_03_02_99, Version.LUCENE_8_1_0, "5a3462e5-d2fe-4b7b-9a7e-c0234412271f"); + public static final IndexVersion V_7_4_0 = registerIndexVersion(7_04_00_99, Version.LUCENE_8_2_0, "c1fe73ba-0173-476c-aba2-855c2b31ac18"); + public static final IndexVersion V_7_4_1 = registerIndexVersion(7_04_01_99, Version.LUCENE_8_2_0, "8a917374-bd4f-45e3-9052-575c4cf741cd"); + public static final IndexVersion V_7_4_2 = registerIndexVersion(7_04_02_99, Version.LUCENE_8_2_0, "f073a867-cba2-41e4-8150-a2f2a96f1e0b"); + public static final IndexVersion V_7_5_0 = registerIndexVersion(7_05_00_99, Version.LUCENE_8_3_0, "ab08ae25-ede2-4e57-a43f-89d96aa989e4"); + public static final IndexVersion V_7_5_1 = registerIndexVersion(7_05_01_99, Version.LUCENE_8_3_0, "a386d62e-cb85-4a37-b5f9-c9468bbfc457"); + public static final IndexVersion V_7_5_2 = registerIndexVersion(7_05_02_99, Version.LUCENE_8_3_0, "706715ca-3b91-40d2-8c2e-c34c459b5d0d"); + public static final IndexVersion V_7_6_0 = registerIndexVersion(7_06_00_99, Version.LUCENE_8_4_0, "63acbdb9-51c8-4976-bb3d-e55052a4fbd4"); + public static final IndexVersion V_7_6_1 = registerIndexVersion(7_06_01_99, Version.LUCENE_8_4_0, "1acc33d3-28dc-448d-953a-664dad3bf1f5"); + public static final IndexVersion V_7_6_2 = registerIndexVersion(7_06_02_99, Version.LUCENE_8_4_0, "3aa17069-fa04-4bf9-96af-fe8b903faa75"); + public static final IndexVersion V_7_7_0 = registerIndexVersion(7_07_00_99, Version.LUCENE_8_5_1, "6fff8238-e6ce-4fb2-85de-196492026e49"); + public static final IndexVersion V_7_7_1 = registerIndexVersion(7_07_01_99, Version.LUCENE_8_5_1, "4ce6641d-157b-4c59-8261-7997ac0f6e40"); + public static final IndexVersion V_7_8_0 = registerIndexVersion(7_08_00_99, Version.LUCENE_8_5_1, "81d7d459-f386-4c20-8235-f8fce8af7f0e"); + public static final IndexVersion V_7_8_1 = registerIndexVersion(7_08_01_99, Version.LUCENE_8_5_1, "a1b015bc-d020-453f-85a6-9413e169304a"); + public static final IndexVersion V_7_9_0 = registerIndexVersion(7_09_00_99, Version.LUCENE_8_6_0, "0fa951a2-43ce-4f76-91bf-066c1ecf8a93"); + public static final IndexVersion V_7_9_1 = registerIndexVersion(7_09_01_99, Version.LUCENE_8_6_2, "5fc4aabc-080e-4840-af4f-a724deba98b1"); + public static final IndexVersion V_7_9_2 = registerIndexVersion(7_09_02_99, Version.LUCENE_8_6_2, "ef824617-332e-4b63-969e-ebb73a868462"); + public static final IndexVersion V_7_9_3 = registerIndexVersion(7_09_03_99, Version.LUCENE_8_6_2, "499c810a-0f37-4dfd-92ad-55e4936f3578"); + public static final IndexVersion V_7_10_0 = registerIndexVersion(7_10_00_99, Version.LUCENE_8_7_0, "92ccd91c-0251-4263-8873-9f1abfac3c10"); + public static final IndexVersion V_7_10_1 = registerIndexVersion(7_10_01_99, Version.LUCENE_8_7_0, "8ce37467-964f-43eb-ad2d-a51a50116868"); + public static final IndexVersion V_7_10_2 = registerIndexVersion(7_10_02_99, Version.LUCENE_8_7_0, "cb277ccb-3081-4238-be2c-c3167316a435"); + public static final IndexVersion V_7_11_0 = registerIndexVersion(7_11_00_99, Version.LUCENE_8_7_0, "e6d65f96-26d5-4669-ac5a-2964b9b1699f"); + public static final IndexVersion V_7_11_1 = registerIndexVersion(7_11_01_99, Version.LUCENE_8_7_0, "e3655b78-14f7-4432-aa28-34cd1ef2d229"); + public static final IndexVersion V_7_11_2 = registerIndexVersion(7_11_02_99, Version.LUCENE_8_7_0, "1ecfd0ee-4868-4384-b2a0-af6ecb01e496"); + public static final IndexVersion V_7_12_0 = registerIndexVersion(7_12_00_99, Version.LUCENE_8_8_0, "39e2989a-a9a4-4f1a-b185-2e6015f74b1c"); + public static final IndexVersion V_7_12_1 = registerIndexVersion(7_12_01_99, Version.LUCENE_8_8_0, "a8307f67-8295-4567-a7eb-2a6e69046282"); + public static final IndexVersion V_7_13_0 = registerIndexVersion(7_13_00_99, Version.LUCENE_8_8_2, "28b21fe0-4d1f-4c04-95cc-74df494ae0cf"); + public static final IndexVersion V_7_13_1 = registerIndexVersion(7_13_01_99, Version.LUCENE_8_8_2, "4952d7a7-d9f5-443b-b362-8c5ebdc57f81"); + public static final IndexVersion V_7_13_2 = registerIndexVersion(7_13_02_99, Version.LUCENE_8_8_2, "d77c4245-9d26-4da3-aa61-78ab34c3c792"); + public static final IndexVersion V_7_13_3 = registerIndexVersion(7_13_03_99, Version.LUCENE_8_8_2, "a263a47e-4075-4c68-8a42-15a37455c30f"); + public static final IndexVersion V_7_13_4 = registerIndexVersion(7_13_04_99, Version.LUCENE_8_8_2, "d17644c8-3144-495d-8f6c-42cd36698e98"); + public static final IndexVersion V_7_14_0 = registerIndexVersion(7_14_00_99, Version.LUCENE_8_9_0, "b45bb223-bb73-4379-a46f-7dc74d38aaca"); + public static final IndexVersion V_7_14_1 = registerIndexVersion(7_14_01_99, Version.LUCENE_8_9_0, "ee4a6d62-9e05-490b-93dd-b316f9a62d71"); + public static final IndexVersion V_7_14_2 = registerIndexVersion(7_14_02_99, Version.LUCENE_8_9_0, "285d3293-2896-431c-97dd-180890840947"); + public static final IndexVersion V_7_15_0 = registerIndexVersion(7_15_00_99, Version.LUCENE_8_9_0, "ab666b02-b866-4b64-9ba3-d511e86c55b5"); + public static final IndexVersion V_7_15_1 = registerIndexVersion(7_15_01_99, Version.LUCENE_8_9_0, "5643957d-9b68-414a-8917-ea75cf549f67"); + public static final IndexVersion V_7_15_2 = registerIndexVersion(7_15_02_99, Version.LUCENE_8_9_0, "1a618039-d665-47ce-b6ca-886e88c64051"); + public static final IndexVersion V_7_16_0 = registerIndexVersion(7_16_00_99, Version.LUCENE_8_10_1, "a582e900-2d92-474c-9be3-2e08fa88be4b"); + public static final IndexVersion V_7_16_1 = registerIndexVersion(7_16_01_99, Version.LUCENE_8_10_1, "bf666306-9b0d-468b-99dc-f2706dae9c11"); + public static final IndexVersion V_7_16_2 = registerIndexVersion(7_16_02_99, Version.LUCENE_8_10_1, "167c6d69-cae2-4281-8f37-984231620ee9"); + public static final IndexVersion V_7_16_3 = registerIndexVersion(7_16_03_99, Version.LUCENE_8_10_1, "5d25a795-2be6-4663-93dc-10d88efb7e3d"); + public static final IndexVersion V_7_17_0 = registerIndexVersion(7_17_00_99, Version.LUCENE_8_11_1, "18766ab8-4691-40a2-94f1-526f3b71420c"); + public static final IndexVersion V_7_17_1 = registerIndexVersion(7_17_01_99, Version.LUCENE_8_11_1, "8ad49144-4a1c-4322-b33d-614a569fba9b"); + public static final IndexVersion V_7_17_2 = registerIndexVersion(7_17_02_99, Version.LUCENE_8_11_1, "50033cde-c905-4923-83d6-8139f3f110e1"); + public static final IndexVersion V_7_17_3 = registerIndexVersion(7_17_03_99, Version.LUCENE_8_11_1, "460b91d1-4f3d-4f56-8dca-8d9e15f5b862"); + public static final IndexVersion V_7_17_4 = registerIndexVersion(7_17_04_99, Version.LUCENE_8_11_1, "26e40d6f-ac7c-43a3-bd0c-1ec6c3093f66"); + public static final IndexVersion V_7_17_5 = registerIndexVersion(7_17_05_99, Version.LUCENE_8_11_1, "d80bc13c-7139-4ff9-979d-42701d480e33"); + public static final IndexVersion V_7_17_6 = registerIndexVersion(7_17_06_99, Version.LUCENE_8_11_1, "0b47328e-341a-4f97-927d-c49f5050778d"); + public static final IndexVersion V_7_17_7 = registerIndexVersion(7_17_07_99, Version.LUCENE_8_11_1, "b672ff6b-8078-4f6e-b426-6fcf7f8687b4"); + public static final IndexVersion V_7_17_8 = registerIndexVersion(7_17_08_99, Version.LUCENE_8_11_1, "0faffa1b-5fb3-4439-9367-f154fb25395f"); + public static final IndexVersion V_7_17_9 = registerIndexVersion(7_17_09_99, Version.LUCENE_8_11_1, "8044989f-77ef-4d6d-9dd8-1bdd805cef74"); + public static final IndexVersion V_7_17_10 = registerIndexVersion(7_17_10_99, Version.LUCENE_8_11_1, "66b743fb-8be6-443f-8920-d8c5ed561857"); + public static final IndexVersion V_7_17_11 = registerIndexVersion(7_17_11_99, Version.LUCENE_8_11_1, "f1935acc-1af9-44b0-97e9-67112d333753"); + public static final IndexVersion V_8_0_0 = registerIndexVersion(8_00_00_99, Version.LUCENE_9_0_0, "ff18a13c-1fa7-4cf7-a3b1-4fdcd9461d5b"); + public static final IndexVersion V_8_0_1 = registerIndexVersion(8_00_01_99, Version.LUCENE_9_0_0, "4bd5650f-3eff-418f-a7a6-ad46b2a9c941"); + public static final IndexVersion V_8_1_0 = registerIndexVersion(8_01_00_99, Version.LUCENE_9_0_0, "b4742461-ee43-4fd0-a260-29f8388b82ec"); + public static final IndexVersion V_8_1_1 = registerIndexVersion(8_01_01_99, Version.LUCENE_9_0_0, "3883e088-9a1c-4494-8d71-768820485f33"); + public static final IndexVersion V_8_1_2 = registerIndexVersion(8_01_02_99, Version.LUCENE_9_0_0, "859a745a-81d3-463e-af58-615179a22d4f"); + public static final IndexVersion V_8_1_3 = registerIndexVersion(8_01_03_99, Version.LUCENE_9_0_0, "27a49f3f-d3ac-4b0e-8bba-1be24daf4a56"); + public static final IndexVersion V_8_2_0 = registerIndexVersion(8_02_00_99, Version.LUCENE_9_1_0, "af0ed990-2f32-42b5-aaf3-59d21a3dca7a"); + public static final IndexVersion V_8_2_1 = registerIndexVersion(8_02_01_99, Version.LUCENE_9_1_0, "6e2a3812-062a-4d08-8c35-ddc930e8e246"); + public static final IndexVersion V_8_2_2 = registerIndexVersion(8_02_02_99, Version.LUCENE_9_1_0, "93d1434c-3956-408b-8204-93be8ab78856"); + public static final IndexVersion V_8_2_3 = registerIndexVersion(8_02_03_99, Version.LUCENE_9_1_0, "026f6904-2a04-4476-8097-02a75e37e0f7"); + public static final IndexVersion V_8_3_0 = registerIndexVersion(8_03_00_99, Version.LUCENE_9_2_0, "eca8e8a3-0724-4247-a58d-e4eafcec4b3f"); + public static final IndexVersion V_8_3_1 = registerIndexVersion(8_03_01_99, Version.LUCENE_9_2_0, "dac08798-c0b5-46c9-bf27-d82c617ce41f"); + public static final IndexVersion V_8_3_2 = registerIndexVersion(8_03_02_99, Version.LUCENE_9_2_0, "2a0c5fb9-e8a5-4788-89f8-f5723bd68cee"); + public static final IndexVersion V_8_3_3 = registerIndexVersion(8_03_03_99, Version.LUCENE_9_2_0, "440a5f5c-767a-49f7-8593-dc7627b30397"); + public static final IndexVersion V_8_4_0 = registerIndexVersion(8_04_00_99, Version.LUCENE_9_3_0, "d27324da-b36c-452a-93a8-9b69a6c302a1"); + public static final IndexVersion V_8_4_1 = registerIndexVersion(8_04_01_99, Version.LUCENE_9_3_0, "44108ecd-839b-423e-9ef1-9d457f244fff"); + public static final IndexVersion V_8_4_2 = registerIndexVersion(8_04_02_99, Version.LUCENE_9_3_0, "9c20ed39-8c32-4cf0-9f06-42735cbf604e"); + public static final IndexVersion V_8_4_3 = registerIndexVersion(8_04_03_99, Version.LUCENE_9_3_0, "e7d17607-47c0-4662-b308-beeb9a8ec552"); + public static final IndexVersion V_8_5_0 = registerIndexVersion(8_05_00_99, Version.LUCENE_9_4_1, "c5284b51-7fee-4f34-a837-241bb57a7aa6"); + public static final IndexVersion V_8_5_1 = registerIndexVersion(8_05_01_99, Version.LUCENE_9_4_1, "b23a983c-9630-4a2b-8352-0f52b55ff87e"); + public static final IndexVersion V_8_5_2 = registerIndexVersion(8_05_02_99, Version.LUCENE_9_4_1, "cfc80b6f-cb5c-4a4c-b3af-5fa1000508a8"); + public static final IndexVersion V_8_5_3 = registerIndexVersion(8_05_03_99, Version.LUCENE_9_4_2, "f8ac8061-1b17-4cab-b2f6-94df31f7552e"); + public static final IndexVersion V_8_6_0 = registerIndexVersion(8_06_00_99, Version.LUCENE_9_4_2, "5e78c76c-74aa-464e-9383-89bdffb74db9"); + public static final IndexVersion V_8_6_1 = registerIndexVersion(8_06_01_99, Version.LUCENE_9_4_2, "8dc502be-ef27-43b3-a27b-1cb925cbef7d"); + public static final IndexVersion V_8_6_2 = registerIndexVersion(8_06_02_99, Version.LUCENE_9_4_2, "e1e73b88-d188-4d82-b5e1-dee261418783"); + public static final IndexVersion V_8_7_0 = registerIndexVersion(8_07_00_99, Version.LUCENE_9_5_0, "f9227941-d6f4-462b-957f-2bcd36c28382"); + public static final IndexVersion V_8_7_1 = registerIndexVersion(8_07_01_99, Version.LUCENE_9_5_0, "758780b8-4b0c-44c6-af5d-fdac10b6093a"); + public static final IndexVersion V_8_7_2 = registerIndexVersion(8_07_02_99, Version.LUCENE_9_5_0, "d896de80-420f-4616-9d74-7e7219446bbd"); + public static final IndexVersion V_8_8_0 = registerIndexVersion(8_08_00_99, Version.LUCENE_9_6_0, "d6ffc8d7-f6bd-469b-8495-01688c310000"); + public static final IndexVersion V_8_9_0 = registerIndexVersion(8_09_00_99, Version.LUCENE_9_6_0, "32f6dbab-cc24-4f5b-87b5-015a848480d9"); + /* + * READ THE JAVADOC ABOVE BEFORE ADDING NEW INDEX VERSIONS + * Detached index versions added below here. + */ + static { + // see comment on IDS field + // now we're registered the index versions, we can clear the map + IDS = null; + } + + /** + * Reference to the most recent index version. + * This should be the index version with the highest id. + */ public static final IndexVersion CURRENT = V_8_9_0; + /** + * Reference to the earliest compatible index version to this version of the codebase. + * This should be the index version used by the previous major version. + */ public static final IndexVersion MINIMUM_COMPATIBLE = V_7_0_0; static NavigableMap getAllVersionIds(Class cls) { + Map versionIdFields = new HashMap<>(); NavigableMap builder = new TreeMap<>(); - Map uniqueIds = new HashMap<>(); Set ignore = Set.of("ZERO", "CURRENT", "MINIMUM_COMPATIBLE"); + for (Field declaredField : cls.getFields()) { if (declaredField.getType().equals(IndexVersion.class)) { String fieldName = declaredField.getName(); if (ignore.contains(fieldName)) { continue; } + + IndexVersion version; try { - IndexVersion version = (IndexVersion) declaredField.get(null); - - IndexVersion maybePrevious = builder.put(version.id, version); - assert maybePrevious == null - : "expected [" + version.id + "] to be uniquely mapped but saw [" + maybePrevious + "] and [" + version + "]"; - - IndexVersion sameUniqueId = uniqueIds.put(version.uniqueId, version); - assert sameUniqueId == null - : "Versions " - + version - + " and " - + sameUniqueId - + " have the same unique id. Each IndexVersion should have a different unique id"; + version = (IndexVersion) declaredField.get(null); } catch (IllegalAccessException e) { - assert false : "IndexVersion field [" + fieldName + "] should be public"; + // should not happen, checked above + throw new AssertionError(e); + } + builder.put(version.id, version); + + if (Assertions.ENABLED) { + // check the version number is unique + var sameVersionNumber = versionIdFields.put(version.id, fieldName); + assert sameVersionNumber == null + : "Versions [" + + sameVersionNumber + + "] and [" + + fieldName + + "] have the same version number [" + + version.id + + "]. Each IndexVersion should have a different version number"; } } } @@ -177,16 +245,6 @@ static Collection getAllVersions() { return VERSION_IDS.values(); } - public final int id; - public final Version luceneVersion; - private final String uniqueId; - - IndexVersion(int id, Version luceneVersion, String uniqueId) { - this.id = id; - this.luceneVersion = Objects.requireNonNull(luceneVersion); - this.uniqueId = Strings.requireNonEmpty(uniqueId, "Each IndexVersion needs a unique string id"); - } - public static IndexVersion fromId(int id) { IndexVersion known = VERSION_IDS.get(id); if (known != null) { @@ -203,7 +261,7 @@ public static IndexVersion fromId(int id) { ? prev.getValue().luceneVersion : Version.fromBits(VERSION_IDS.firstEntry().getValue().luceneVersion.major - 1, 0, 0); - return new IndexVersion(id, luceneVersion, ""); + return new IndexVersion(id, luceneVersion); } @Deprecated(forRemoval = true) diff --git a/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java b/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java index d603ae35a112f..82d6981ed84fc 100644 --- a/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java +++ b/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java @@ -1989,7 +1989,7 @@ private boolean assertSequenceNumbersInCommit() throws IOException { : "opening index which was created post 5.5.0 but " + Engine.MAX_UNSAFE_AUTO_ID_TIMESTAMP_COMMIT_ID + " is not found in commit"; final org.apache.lucene.util.Version commitLuceneVersion = segmentCommitInfos.getCommitLuceneVersion(); // This relies in the previous minor having another lucene version - assert commitLuceneVersion.onOrAfter(RecoverySettings.SEQ_NO_SNAPSHOT_RECOVERIES_SUPPORTED_VERSION.luceneVersion) == false + assert commitLuceneVersion.onOrAfter(RecoverySettings.SEQ_NO_SNAPSHOT_RECOVERIES_SUPPORTED_VERSION.luceneVersion()) == false || userData.containsKey(Engine.ES_VERSION) && Version.fromString(userData.get(Engine.ES_VERSION)).onOrBefore(Version.CURRENT) : "commit point has an invalid ES_VERSION value. commit point lucene version [" + commitLuceneVersion diff --git a/server/src/main/java/org/elasticsearch/index/store/Store.java b/server/src/main/java/org/elasticsearch/index/store/Store.java index d944d71cfb38b..b70683ee1f775 100644 --- a/server/src/main/java/org/elasticsearch/index/store/Store.java +++ b/server/src/main/java/org/elasticsearch/index/store/Store.java @@ -818,7 +818,7 @@ static MetadataSnapshot loadFromIndexCommit(IndexCommit commit, Directory direct } } if (maxVersion == null) { - maxVersion = IndexVersion.MINIMUM_COMPATIBLE.luceneVersion; + maxVersion = IndexVersion.MINIMUM_COMPATIBLE.luceneVersion(); } final String segmentsFile = segmentCommitInfos.getSegmentsFileName(); checksumFromLuceneFile( diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/HumanReadableIndexSettingsTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/HumanReadableIndexSettingsTests.java index 14ef7a17ce31d..cc65b404a17fe 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/HumanReadableIndexSettingsTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/HumanReadableIndexSettingsTests.java @@ -24,7 +24,7 @@ public void testHumanReadableSettings() { IndexVersion versionCreated = randomVersion(random()).indexVersion; long created = System.currentTimeMillis(); Settings testSettings = Settings.builder() - .put(IndexMetadata.SETTING_VERSION_CREATED, versionCreated.id) + .put(IndexMetadata.SETTING_VERSION_CREATED, versionCreated.id()) .put(IndexMetadata.SETTING_CREATION_DATE, created) .build(); diff --git a/server/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java b/server/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java index 93ccd57aed943..a83f238ba32a4 100644 --- a/server/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java +++ b/server/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java @@ -66,7 +66,7 @@ import static org.hamcrest.Matchers.hasSize; public class ReplicaShardAllocatorTests extends ESAllocationTestCase { - private static final String MIN_SUPPORTED_LUCENE_VERSION = IndexVersion.MINIMUM_COMPATIBLE.luceneVersion.toString(); + private static final String MIN_SUPPORTED_LUCENE_VERSION = IndexVersion.MINIMUM_COMPATIBLE.luceneVersion().toString(); private final ShardId shardId = new ShardId("test", "_na_", 0); private final DiscoveryNode node1 = newNode("node1"); diff --git a/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java b/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java index 21a39b2df90ed..6bfc5f9b19a43 100644 --- a/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java +++ b/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java @@ -6689,7 +6689,7 @@ public long softUpdateDocuments(Term term, Iterable userData = new HashMap<>(store.readLastCommittedSegmentsInfo().userData); userData.remove(Engine.MIN_RETAINED_SEQNO); IndexWriterConfig indexWriterConfig = new IndexWriterConfig(null).setOpenMode(IndexWriterConfig.OpenMode.APPEND) - .setIndexCreatedVersionMajor(IndexVersion.CURRENT.luceneVersion.major) + .setIndexCreatedVersionMajor(IndexVersion.CURRENT.luceneVersion().major) .setSoftDeletesField(Lucene.SOFT_DELETES_FIELD) .setCommitOnClose(false) .setMergePolicy(NoMergePolicy.INSTANCE); diff --git a/server/src/test/java/org/elasticsearch/index/snapshots/blobstore/FileInfoTests.java b/server/src/test/java/org/elasticsearch/index/snapshots/blobstore/FileInfoTests.java index 5ba754143503c..c4456ccd551e0 100644 --- a/server/src/test/java/org/elasticsearch/index/snapshots/blobstore/FileInfoTests.java +++ b/server/src/test/java/org/elasticsearch/index/snapshots/blobstore/FileInfoTests.java @@ -32,7 +32,7 @@ import static org.hamcrest.Matchers.is; public class FileInfoTests extends ESTestCase { - private static final org.apache.lucene.util.Version MIN_SUPPORTED_LUCENE_VERSION = IndexVersion.MINIMUM_COMPATIBLE.luceneVersion; + private static final org.apache.lucene.util.Version MIN_SUPPORTED_LUCENE_VERSION = IndexVersion.MINIMUM_COMPATIBLE.luceneVersion(); public void testToFromXContent() throws IOException { final int iters = scaledRandomIntBetween(1, 10); diff --git a/server/src/test/java/org/elasticsearch/index/store/StoreTests.java b/server/src/test/java/org/elasticsearch/index/store/StoreTests.java index 2615abbfccdc4..25f4c4fce869c 100644 --- a/server/src/test/java/org/elasticsearch/index/store/StoreTests.java +++ b/server/src/test/java/org/elasticsearch/index/store/StoreTests.java @@ -106,7 +106,7 @@ public class StoreTests extends ESTestCase { "index", Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, org.elasticsearch.Version.CURRENT).build() ); - private static final Version MIN_SUPPORTED_LUCENE_VERSION = IndexVersion.MINIMUM_COMPATIBLE.luceneVersion; + private static final Version MIN_SUPPORTED_LUCENE_VERSION = IndexVersion.MINIMUM_COMPATIBLE.luceneVersion(); public void testRefCount() { final ShardId shardId = new ShardId("index", "_na_", 1); diff --git a/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryStatusTests.java b/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryStatusTests.java index c04988b8ac92b..e8bed42b682d1 100644 --- a/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryStatusTests.java +++ b/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryStatusTests.java @@ -22,7 +22,7 @@ import java.util.regex.Pattern; public class RecoveryStatusTests extends ESSingleNodeTestCase { - private static final org.apache.lucene.util.Version MIN_SUPPORTED_LUCENE_VERSION = IndexVersion.MINIMUM_COMPATIBLE.luceneVersion; + private static final org.apache.lucene.util.Version MIN_SUPPORTED_LUCENE_VERSION = IndexVersion.MINIMUM_COMPATIBLE.luceneVersion(); public void testRenameTempFiles() throws IOException { IndexService service = createIndex("foo"); diff --git a/server/src/test/java/org/elasticsearch/repositories/blobstore/ShardSnapshotTaskRunnerTests.java b/server/src/test/java/org/elasticsearch/repositories/blobstore/ShardSnapshotTaskRunnerTests.java index 4d551ca698d0c..d042fc2fa0a9f 100644 --- a/server/src/test/java/org/elasticsearch/repositories/blobstore/ShardSnapshotTaskRunnerTests.java +++ b/server/src/test/java/org/elasticsearch/repositories/blobstore/ShardSnapshotTaskRunnerTests.java @@ -101,7 +101,7 @@ public int finishedShardSnapshotTasks() { public static BlobStoreIndexShardSnapshot.FileInfo dummyFileInfo() { String filename = randomAlphaOfLength(10); - StoreFileMetadata metadata = new StoreFileMetadata(filename, 10, "CHECKSUM", IndexVersion.CURRENT.luceneVersion.toString()); + StoreFileMetadata metadata = new StoreFileMetadata(filename, 10, "CHECKSUM", IndexVersion.CURRENT.luceneVersion().toString()); return new BlobStoreIndexShardSnapshot.FileInfo(filename, metadata, null); } diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java index 22abeab6f6a31..768cbaeda7d06 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java @@ -1884,7 +1884,7 @@ public String toString() { * @param message an additional message or link with information on the fix */ protected void skipTestWaitingForLuceneFix(org.apache.lucene.util.Version luceneVersionWithFix, String message) { - final boolean currentVersionHasFix = IndexVersion.CURRENT.luceneVersion.onOrAfter(luceneVersionWithFix); + final boolean currentVersionHasFix = IndexVersion.CURRENT.luceneVersion().onOrAfter(luceneVersionWithFix); assumeTrue("Skipping test as it is waiting on a Lucene fix: " + message, currentVersionHasFix); fail("Remove call of skipTestWaitingForLuceneFix in " + RandomizedTest.getContext().getTargetMethod()); } diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryStatsTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryStatsTests.java index 2ff8f6ffa446e..d352c59f235ef 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryStatsTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryStatsTests.java @@ -642,7 +642,7 @@ private void executeTestCase( fileName, fileContent.length, fileChecksum, - IndexVersion.CURRENT.luceneVersion.toString() + IndexVersion.CURRENT.luceneVersion().toString() ); final List files = List.of(new FileInfo(blobName, metadata, ByteSizeValue.ofBytes(fileContent.length))); final BlobStoreIndexShardSnapshot snapshot = new BlobStoreIndexShardSnapshot(snapshotId.getName(), 0L, files, 0L, 0L, 0, 0L); diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryTests.java index 8c427c6ff86e7..e343d75b4e592 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryTests.java @@ -734,7 +734,7 @@ public void testClearCache() throws Exception { randomFiles.add( new BlobStoreIndexShardSnapshot.FileInfo( blobName, - new StoreFileMetadata(fileName, input.length, checksum, IndexVersion.CURRENT.luceneVersion.toString()), + new StoreFileMetadata(fileName, input.length, checksum, IndexVersion.CURRENT.luceneVersion().toString()), ByteSizeValue.ofBytes(input.length) ) ); diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/CachedBlobContainerIndexInputTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/CachedBlobContainerIndexInputTests.java index 0ef2c73bdc89c..58e5f7f24f10c 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/CachedBlobContainerIndexInputTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/CachedBlobContainerIndexInputTests.java @@ -75,7 +75,7 @@ public void testRandomReads() throws Exception { fileName, input.length, checksum, - IndexVersion.CURRENT.luceneVersion.toString() + IndexVersion.CURRENT.luceneVersion().toString() ); final int partSize = randomBoolean() ? input.length : randomIntBetween(1, input.length); @@ -195,7 +195,7 @@ public void testThrowsEOFException() throws Exception { fileName, input.length, checksum, - IndexVersion.CURRENT.luceneVersion.toString() + IndexVersion.CURRENT.luceneVersion().toString() ); final BlobStoreIndexShardSnapshot snapshot = new BlobStoreIndexShardSnapshot( diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/FrozenIndexInputTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/FrozenIndexInputTests.java index 1ea66db8cdb4e..12cef4ad8db8f 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/FrozenIndexInputTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/FrozenIndexInputTests.java @@ -55,7 +55,7 @@ public void testRandomReads() throws IOException { final FileInfo fileInfo = new FileInfo( randomAlphaOfLength(10), - new StoreFileMetadata(fileName, fileData.length, checksum, IndexVersion.CURRENT.luceneVersion.toString()), + new StoreFileMetadata(fileName, fileData.length, checksum, IndexVersion.CURRENT.luceneVersion().toString()), ByteSizeValue.ofBytes(fileData.length) ); diff --git a/x-pack/plugin/snapshot-based-recoveries/src/main/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerService.java b/x-pack/plugin/snapshot-based-recoveries/src/main/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerService.java index edc434e86f1c2..a488a491c6d03 100644 --- a/x-pack/plugin/snapshot-based-recoveries/src/main/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerService.java +++ b/x-pack/plugin/snapshot-based-recoveries/src/main/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerService.java @@ -188,8 +188,8 @@ private boolean isSnapshotVersionCompatible(ShardSnapshot snapshot) { // NodeVersionAllocationDecider ensures that we only recover to a node that has newer or // same version. if (commitVersion == null) { - assert SEQ_NO_SNAPSHOT_RECOVERIES_SUPPORTED_VERSION.luceneVersion.onOrAfter(snapshot.getCommitLuceneVersion()); - return IndexVersion.CURRENT.luceneVersion.onOrAfter(snapshot.getCommitLuceneVersion()); + assert SEQ_NO_SNAPSHOT_RECOVERIES_SUPPORTED_VERSION.luceneVersion().onOrAfter(snapshot.getCommitLuceneVersion()); + return IndexVersion.CURRENT.luceneVersion().onOrAfter(snapshot.getCommitLuceneVersion()); } return commitVersion.onOrBefore(Version.CURRENT); } diff --git a/x-pack/plugin/snapshot-based-recoveries/src/test/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerServiceTests.java b/x-pack/plugin/snapshot-based-recoveries/src/test/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerServiceTests.java index f0e824397de32..3fad20366c272 100644 --- a/x-pack/plugin/snapshot-based-recoveries/src/test/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerServiceTests.java +++ b/x-pack/plugin/snapshot-based-recoveries/src/test/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerServiceTests.java @@ -601,7 +601,7 @@ private void writeRandomDocs(Store store, int numDocs) throws IOException { } private ShardSnapshot createShardSnapshotThatDoNotShareSegmentFiles(String repoName) { - return createShardSnapshotThatDoNotShareSegmentFiles(repoName, Version.CURRENT, IndexVersion.CURRENT.luceneVersion); + return createShardSnapshotThatDoNotShareSegmentFiles(repoName, Version.CURRENT, IndexVersion.CURRENT.luceneVersion()); } private ShardSnapshot createShardSnapshotThatDoNotShareSegmentFiles( @@ -630,7 +630,7 @@ private ShardSnapshot createShardSnapshotThatSharesSegmentFiles(Store store, Str ); snapshotFiles.add(fileInfo); } - return createShardSnapshot(repository, snapshotFiles, Version.CURRENT, IndexVersion.CURRENT.luceneVersion); + return createShardSnapshot(repository, snapshotFiles, Version.CURRENT, IndexVersion.CURRENT.luceneVersion()); } private ShardSnapshot createShardSnapshot( From 04593d6653c72cf7ca2591edf1f87cde29e35320 Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Tue, 9 May 2023 14:50:47 +0100 Subject: [PATCH 14/20] Add tests for IndexVersion methods --- .../org/elasticsearch/index/IndexVersion.java | 14 ++ .../index/IndexVersionTests.java | 180 ++++++++++++++++++ .../index/KnownIndexVersions.java | 21 ++ .../test/index/IndexVersionUtils.java | 115 +++++++++++ 4 files changed, 330 insertions(+) create mode 100644 server/src/test/java/org/elasticsearch/index/IndexVersionTests.java create mode 100644 test/framework/src/main/java/org/elasticsearch/index/KnownIndexVersions.java create mode 100644 test/framework/src/main/java/org/elasticsearch/test/index/IndexVersionUtils.java diff --git a/server/src/main/java/org/elasticsearch/index/IndexVersion.java b/server/src/main/java/org/elasticsearch/index/IndexVersion.java index a16298689226c..d29871991d597 100644 --- a/server/src/main/java/org/elasticsearch/index/IndexVersion.java +++ b/server/src/main/java/org/elasticsearch/index/IndexVersion.java @@ -269,6 +269,20 @@ public org.elasticsearch.Version toVersion() { return org.elasticsearch.Version.fromId(id); } + /** + * Returns the minimum version of {@code version1} and {@code version2} + */ + public static IndexVersion min(IndexVersion version1, IndexVersion version2) { + return version1.id < version2.id ? version1 : version2; + } + + /** + * Returns the maximum version of {@code version1} and {@code version2} + */ + public static IndexVersion max(IndexVersion version1, IndexVersion version2) { + return version1.id > version2.id ? version1 : version2; + } + public boolean after(IndexVersion version) { return version.id < id; } diff --git a/server/src/test/java/org/elasticsearch/index/IndexVersionTests.java b/server/src/test/java/org/elasticsearch/index/IndexVersionTests.java new file mode 100644 index 0000000000000..f26edc803ac41 --- /dev/null +++ b/server/src/test/java/org/elasticsearch/index/IndexVersionTests.java @@ -0,0 +1,180 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +package org.elasticsearch.index; + +import org.apache.lucene.util.Version; +import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.index.IndexVersionUtils; + +import java.lang.reflect.Modifier; +import java.util.Collections; +import java.util.Map; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.lessThan; +import static org.hamcrest.Matchers.sameInstance; + +public class IndexVersionTests extends ESTestCase { + + public void testVersionComparison() { + IndexVersion V_7_2_0 = IndexVersion.V_7_2_0; + IndexVersion V_8_0_0 = IndexVersion.V_8_0_0; + assertThat(V_7_2_0.before(V_8_0_0), is(true)); + assertThat(V_7_2_0.before(V_7_2_0), is(false)); + assertThat(V_8_0_0.before(V_7_2_0), is(false)); + + assertThat(V_7_2_0.onOrBefore(V_8_0_0), is(true)); + assertThat(V_7_2_0.onOrBefore(V_7_2_0), is(true)); + assertThat(V_8_0_0.onOrBefore(V_7_2_0), is(false)); + + assertThat(V_7_2_0.after(V_8_0_0), is(false)); + assertThat(V_7_2_0.after(V_7_2_0), is(false)); + assertThat(V_8_0_0.after(V_7_2_0), is(true)); + + assertThat(V_7_2_0.onOrAfter(V_8_0_0), is(false)); + assertThat(V_7_2_0.onOrAfter(V_7_2_0), is(true)); + assertThat(V_8_0_0.onOrAfter(V_7_2_0), is(true)); + + assertThat(V_7_2_0, is(lessThan(V_8_0_0))); + assertThat(V_7_2_0.compareTo(V_7_2_0), is(0)); + assertThat(V_8_0_0, is(greaterThan(V_7_2_0))); + } + + public static class CorrectFakeVersion { + public static final IndexVersion V_0_00_01 = new IndexVersion(199, Version.LATEST); + public static final IndexVersion V_0_000_002 = new IndexVersion(2, Version.LATEST); + public static final IndexVersion V_0_000_003 = new IndexVersion(3, Version.LATEST); + public static final IndexVersion V_0_000_004 = new IndexVersion(4, Version.LATEST); + } + + public static class DuplicatedIdFakeVersion { + public static final IndexVersion V_0_000_001 = new IndexVersion(1, Version.LATEST); + public static final IndexVersion V_0_000_002 = new IndexVersion(2, Version.LATEST); + public static final IndexVersion V_0_000_003 = new IndexVersion(2, Version.LATEST); + } + + public void testStaticIndexVersionChecks() { + assertThat( + IndexVersion.getAllVersionIds(IndexVersionTests.CorrectFakeVersion.class), + equalTo( + Map.of( + 199, + IndexVersionTests.CorrectFakeVersion.V_0_00_01, + 2, + IndexVersionTests.CorrectFakeVersion.V_0_000_002, + 3, + IndexVersionTests.CorrectFakeVersion.V_0_000_003, + 4, + IndexVersionTests.CorrectFakeVersion.V_0_000_004 + ) + ) + ); + AssertionError e = expectThrows(AssertionError.class, () -> IndexVersion.getAllVersionIds(DuplicatedIdFakeVersion.class)); + assertThat(e.getMessage(), containsString("have the same version number")); + } + + private static String padNumber(String number) { + return number.length() == 1 ? "0" + number : number; + } + + public void testDefinedConstants() throws IllegalAccessException { + Pattern historicalVersion = Pattern.compile("^V_(\\d{1,2})_(\\d{1,2})_(\\d{1,2})$"); + Pattern IndexVersion = Pattern.compile("^V_(\\d+)_(\\d{3})_(\\d{3})$"); + Set ignore = Set.of("ZERO", "CURRENT", "MINIMUM_COMPATIBLE"); + + for (java.lang.reflect.Field field : IndexVersion.class.getFields()) { + if (field.getType() == IndexVersion.class && ignore.contains(field.getName()) == false) { + + // check the field modifiers + assertEquals( + "Field " + field.getName() + " should be public static final", + Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL, + field.getModifiers() + ); + + Matcher historical = historicalVersion.matcher(field.getName()); + Matcher transport; + if (historical.matches()) { + // old-style version constant + String idString = historical.group(1) + padNumber(historical.group(2)) + padNumber(historical.group(3)) + "99"; + assertEquals( + "Field " + field.getName() + " does not have expected id " + idString, + idString, + field.get(null).toString() + ); + } else if ((transport = IndexVersion.matcher(field.getName())).matches()) { + String idString = transport.group(1) + transport.group(2) + transport.group(3); + assertEquals( + "Field " + field.getName() + " does not have expected id " + idString, + idString, + field.get(null).toString() + ); + } else { + fail("Field " + field.getName() + " does not have expected format"); + } + } + } + } + + public void testMin() { + assertEquals( + IndexVersionUtils.getPreviousVersion(), + IndexVersion.min(IndexVersion.CURRENT, IndexVersionUtils.getPreviousVersion()) + ); + assertEquals(IndexVersion.fromId(1_01_01_99), IndexVersion.min(IndexVersion.fromId(1_01_01_99), IndexVersion.CURRENT)); + IndexVersion version = IndexVersionUtils.randomVersion(); + IndexVersion version1 = IndexVersionUtils.randomVersion(); + if (version.id() <= version1.id()) { + assertEquals(version, IndexVersion.min(version1, version)); + } else { + assertEquals(version1, IndexVersion.min(version1, version)); + } + } + + public void testMax() { + assertEquals(IndexVersion.CURRENT, IndexVersion.max(IndexVersion.CURRENT, IndexVersionUtils.getPreviousVersion())); + assertEquals(IndexVersion.CURRENT, IndexVersion.max(IndexVersion.fromId(1_01_01_99), IndexVersion.CURRENT)); + IndexVersion version = IndexVersionUtils.randomVersion(); + IndexVersion version1 = IndexVersionUtils.randomVersion(); + if (version.id() >= version1.id()) { + assertEquals(version, IndexVersion.max(version1, version)); + } else { + assertEquals(version1, IndexVersion.max(version1, version)); + } + } + + public void testVersionConstantPresent() { + Set ignore = Set.of(IndexVersion.ZERO, IndexVersion.CURRENT, IndexVersion.MINIMUM_COMPATIBLE); + assertThat(IndexVersion.CURRENT, sameInstance(IndexVersion.fromId(IndexVersion.CURRENT.id()))); + final int iters = scaledRandomIntBetween(20, 100); + for (int i = 0; i < iters; i++) { + IndexVersion version = IndexVersionUtils.randomVersion(ignore); + + assertThat(version, sameInstance(IndexVersion.fromId(version.id()))); + } + } + + public void testCURRENTIsLatest() { + assertThat(Collections.max(IndexVersion.getAllVersions()), is(IndexVersion.CURRENT)); + } + + public void testToString() { + assertEquals("5000099", IndexVersion.fromId(5_00_00_99).toString()); + assertEquals("2030099", IndexVersion.fromId(2_03_00_99).toString()); + assertEquals("1000099", IndexVersion.fromId(1_00_00_99).toString()); + assertEquals("2000099", IndexVersion.fromId(2_00_00_99).toString()); + assertEquals("5000099", IndexVersion.fromId(5_00_00_99).toString()); + } +} diff --git a/test/framework/src/main/java/org/elasticsearch/index/KnownIndexVersions.java b/test/framework/src/main/java/org/elasticsearch/index/KnownIndexVersions.java new file mode 100644 index 0000000000000..e51116898a7ea --- /dev/null +++ b/test/framework/src/main/java/org/elasticsearch/index/KnownIndexVersions.java @@ -0,0 +1,21 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +package org.elasticsearch.index; + +import java.util.List; + +/** + * Provides access to all known index versions + */ +public class KnownIndexVersions { + /** + * A sorted list of all known transport versions + */ + public static final List ALL_VERSIONS = List.copyOf(IndexVersion.getAllVersions()); +} diff --git a/test/framework/src/main/java/org/elasticsearch/test/index/IndexVersionUtils.java b/test/framework/src/main/java/org/elasticsearch/test/index/IndexVersionUtils.java new file mode 100644 index 0000000000000..e57f2f4d6b3fb --- /dev/null +++ b/test/framework/src/main/java/org/elasticsearch/test/index/IndexVersionUtils.java @@ -0,0 +1,115 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +package org.elasticsearch.test.index; + +import org.elasticsearch.core.Nullable; +import org.elasticsearch.index.IndexVersion; +import org.elasticsearch.index.KnownIndexVersions; +import org.elasticsearch.test.ESTestCase; + +import java.util.Collections; +import java.util.List; +import java.util.Random; +import java.util.Set; +import java.util.stream.Collectors; + +public class IndexVersionUtils { + + private static final List ALL_VERSIONS = KnownIndexVersions.ALL_VERSIONS; + + /** Returns all released versions */ + public static List allReleasedVersions() { + return ALL_VERSIONS; + } + + /** Returns the oldest known {@link IndexVersion} */ + public static IndexVersion getFirstVersion() { + return ALL_VERSIONS.get(0); + } + + /** Returns a random {@link IndexVersion} from all available versions. */ + public static IndexVersion randomVersion() { + return ESTestCase.randomFrom(ALL_VERSIONS); + } + + /** Returns a random {@link IndexVersion} from all available versions without the ignore set */ + public static IndexVersion randomVersion(Set ignore) { + return ESTestCase.randomFrom(ALL_VERSIONS.stream().filter(v -> ignore.contains(v) == false).collect(Collectors.toList())); + } + + /** Returns a random {@link IndexVersion} from all available versions. */ + public static IndexVersion randomVersion(Random random) { + return ALL_VERSIONS.get(random.nextInt(ALL_VERSIONS.size())); + } + + /** Returns a random {@link IndexVersion} between minVersion and maxVersion (inclusive). */ + public static IndexVersion randomVersionBetween(Random random, @Nullable IndexVersion minVersion, @Nullable IndexVersion maxVersion) { + if (minVersion != null && maxVersion != null && maxVersion.before(minVersion)) { + throw new IllegalArgumentException("maxVersion [" + maxVersion + "] cannot be less than minVersion [" + minVersion + "]"); + } + + int minVersionIndex = 0; + if (minVersion != null) { + minVersionIndex = Collections.binarySearch(ALL_VERSIONS, minVersion); + } + int maxVersionIndex = ALL_VERSIONS.size() - 1; + if (maxVersion != null) { + maxVersionIndex = Collections.binarySearch(ALL_VERSIONS, maxVersion); + } + if (minVersionIndex < 0) { + throw new IllegalArgumentException("minVersion [" + minVersion + "] does not exist."); + } else if (maxVersionIndex < 0) { + throw new IllegalArgumentException("maxVersion [" + maxVersion + "] does not exist."); + } else { + // minVersionIndex is inclusive so need to add 1 to this index + int range = maxVersionIndex + 1 - minVersionIndex; + return ALL_VERSIONS.get(minVersionIndex + random.nextInt(range)); + } + } + + public static IndexVersion getPreviousVersion() { + IndexVersion version = getPreviousVersion(IndexVersion.CURRENT); + assert version.before(IndexVersion.CURRENT); + return version; + } + + public static IndexVersion getPreviousVersion(IndexVersion version) { + int place = Collections.binarySearch(ALL_VERSIONS, version); + if (place < 0) { + // version does not exist - need the item before the index this version should be inserted + place = -(place + 1); + } + + if (place < 1) { + throw new IllegalArgumentException("couldn't find any released versions before [" + version + "]"); + } + return ALL_VERSIONS.get(place - 1); + } + + public static IndexVersion getNextVersion(IndexVersion version) { + int place = Collections.binarySearch(ALL_VERSIONS, version); + if (place < 0) { + // version does not exist - need the item at the index this version should be inserted + place = -(place + 1); + } else { + // need the *next* version + place++; + } + + if (place < 0 || place >= ALL_VERSIONS.size()) { + throw new IllegalArgumentException("couldn't find any released versions after [" + version + "]"); + } + return ALL_VERSIONS.get(place); + } + + /** Returns a random {@code IndexVersion} that is compatible with {@link IndexVersion#CURRENT} */ + public static IndexVersion randomCompatibleVersion(Random random) { + return randomVersionBetween(random, IndexVersion.MINIMUM_COMPATIBLE, IndexVersion.CURRENT); + } +} From 3031ffa73b3794cc9ba8aab27230d9fd738b43d2 Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Fri, 12 May 2023 10:02:52 +0100 Subject: [PATCH 15/20] Copy across updates between Index/TransportVersion --- .../java/org/elasticsearch/TransportVersion.java | 1 - .../org/elasticsearch/index/IndexVersion.java | 15 +++++++-------- .../org/elasticsearch/TransportVersionTests.java | 11 +++++------ .../elasticsearch/index/IndexVersionTests.java | 11 +++++------ 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/TransportVersion.java b/server/src/main/java/org/elasticsearch/TransportVersion.java index 76a1a4056bdc2..1cf17f978fd62 100644 --- a/server/src/main/java/org/elasticsearch/TransportVersion.java +++ b/server/src/main/java/org/elasticsearch/TransportVersion.java @@ -163,7 +163,6 @@ static NavigableMap getAllVersionIds(Class cls) { try { version = (TransportVersion) declaredField.get(null); } catch (IllegalAccessException e) { - // should not happen, checked above throw new AssertionError(e); } builder.put(version.id, version); diff --git a/server/src/main/java/org/elasticsearch/index/IndexVersion.java b/server/src/main/java/org/elasticsearch/index/IndexVersion.java index d29871991d597..31a66fa69c37e 100644 --- a/server/src/main/java/org/elasticsearch/index/IndexVersion.java +++ b/server/src/main/java/org/elasticsearch/index/IndexVersion.java @@ -170,12 +170,6 @@ private static IndexVersion registerIndexVersion(int id, Version luceneVersion, * Detached index versions added below here. */ - static { - // see comment on IDS field - // now we're registered the index versions, we can clear the map - IDS = null; - } - /** * Reference to the most recent index version. * This should be the index version with the highest id. @@ -184,10 +178,16 @@ private static IndexVersion registerIndexVersion(int id, Version luceneVersion, /** * Reference to the earliest compatible index version to this version of the codebase. - * This should be the index version used by the previous major version. + * This should be the index version used by the first release of the previous major version. */ public static final IndexVersion MINIMUM_COMPATIBLE = V_7_0_0; + static { + // see comment on IDS field + // now we're registered the index versions, we can clear the map + IDS = null; + } + static NavigableMap getAllVersionIds(Class cls) { Map versionIdFields = new HashMap<>(); NavigableMap builder = new TreeMap<>(); @@ -205,7 +205,6 @@ static NavigableMap getAllVersionIds(Class cls) { try { version = (IndexVersion) declaredField.get(null); } catch (IllegalAccessException e) { - // should not happen, checked above throw new AssertionError(e); } builder.put(version.id, version); diff --git a/server/src/test/java/org/elasticsearch/TransportVersionTests.java b/server/src/test/java/org/elasticsearch/TransportVersionTests.java index a2b38b542259c..704ec211261ef 100644 --- a/server/src/test/java/org/elasticsearch/TransportVersionTests.java +++ b/server/src/test/java/org/elasticsearch/TransportVersionTests.java @@ -103,18 +103,17 @@ public void testDefinedConstants() throws IllegalAccessException { field.getModifiers() ); - Matcher historical = historicalVersion.matcher(field.getName()); - Matcher transport; - if (historical.matches()) { + Matcher matcher = historicalVersion.matcher(field.getName()); + if (matcher.matches()) { // old-style version constant - String idString = historical.group(1) + padNumber(historical.group(2)) + padNumber(historical.group(3)) + "99"; + String idString = matcher.group(1) + padNumber(matcher.group(2)) + padNumber(matcher.group(3)) + "99"; assertEquals( "Field " + field.getName() + " does not have expected id " + idString, idString, field.get(null).toString() ); - } else if ((transport = transportVersion.matcher(field.getName())).matches()) { - String idString = transport.group(1) + transport.group(2) + transport.group(3); + } else if ((matcher = transportVersion.matcher(field.getName())).matches()) { + String idString = matcher.group(1) + matcher.group(2) + matcher.group(3); assertEquals( "Field " + field.getName() + " does not have expected id " + idString, idString, diff --git a/server/src/test/java/org/elasticsearch/index/IndexVersionTests.java b/server/src/test/java/org/elasticsearch/index/IndexVersionTests.java index f26edc803ac41..bee5f7761e82c 100644 --- a/server/src/test/java/org/elasticsearch/index/IndexVersionTests.java +++ b/server/src/test/java/org/elasticsearch/index/IndexVersionTests.java @@ -104,18 +104,17 @@ public void testDefinedConstants() throws IllegalAccessException { field.getModifiers() ); - Matcher historical = historicalVersion.matcher(field.getName()); - Matcher transport; - if (historical.matches()) { + Matcher matcher = historicalVersion.matcher(field.getName()); + if (matcher.matches()) { // old-style version constant - String idString = historical.group(1) + padNumber(historical.group(2)) + padNumber(historical.group(3)) + "99"; + String idString = matcher.group(1) + padNumber(matcher.group(2)) + padNumber(matcher.group(3)) + "99"; assertEquals( "Field " + field.getName() + " does not have expected id " + idString, idString, field.get(null).toString() ); - } else if ((transport = IndexVersion.matcher(field.getName())).matches()) { - String idString = transport.group(1) + transport.group(2) + transport.group(3); + } else if ((matcher = IndexVersion.matcher(field.getName())).matches()) { + String idString = matcher.group(1) + matcher.group(2) + matcher.group(3); assertEquals( "Field " + field.getName() + " does not have expected id " + idString, idString, From 7f2e657d7fd07810a7629fb13cd94184a5239757 Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Fri, 12 May 2023 10:37:21 +0100 Subject: [PATCH 16/20] Rename method to match class --- .../java/org/elasticsearch/gradle/internal/BwcVersions.java | 3 +-- .../java/org/elasticsearch/cluster/metadata/IndexMetadata.java | 2 +- server/src/main/java/org/elasticsearch/index/IndexVersion.java | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BwcVersions.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BwcVersions.java index 2a2d297165e30..41bfddb01e665 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BwcVersions.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BwcVersions.java @@ -236,8 +236,7 @@ public List getIndexCompatible() { * Return all versions of Elasticsearch which are index compatible with the current version. */ public List getAllIndexCompatible() { - int minVersion = currentVersion.getMajor() - 1; - return versions.stream().filter(v -> v.getMajor() >= minVersion).toList(); + return versions.stream().filter(v -> v.getMajor() >= (currentVersion.getMajor() - 1)).toList(); } public void withIndexCompatible(BiConsumer versionAction) { diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java index ae8903b42bdfa..b2ef477281e56 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java @@ -2510,7 +2510,7 @@ public static IndexMetadata legacyFromXContent(XContentParser parser) throws IOE } else if (token == XContentParser.Token.START_OBJECT) { if ("settings".equals(currentFieldName)) { Settings settings = Settings.fromXContent(parser); - if (SETTING_INDEX_VERSION_COMPATIBILITY.get(settings).isLegacyIndexFormatVersion() == false) { + if (SETTING_INDEX_VERSION_COMPATIBILITY.get(settings).isLegacyIndexVersion() == false) { throw new IllegalStateException( "this method should only be used to parse older incompatible index metadata versions " + "but got " diff --git a/server/src/main/java/org/elasticsearch/index/IndexVersion.java b/server/src/main/java/org/elasticsearch/index/IndexVersion.java index 31a66fa69c37e..3db3af944157c 100644 --- a/server/src/main/java/org/elasticsearch/index/IndexVersion.java +++ b/server/src/main/java/org/elasticsearch/index/IndexVersion.java @@ -298,7 +298,7 @@ public boolean onOrBefore(IndexVersion version) { return version.id >= id; } - public boolean isLegacyIndexFormatVersion() { + public boolean isLegacyIndexVersion() { return before(MINIMUM_COMPATIBLE); } From 75c3cbde2c4a72dd7b2b09e29930aa0651cba6ec Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Mon, 22 May 2023 15:55:20 +0100 Subject: [PATCH 17/20] We don't need all these changes now --- .../org/elasticsearch/upgrades/FullClusterRestartIT.java | 3 +-- .../indices/recovery/plan/ShardSnapshotsServiceIT.java | 3 +-- .../java/org/elasticsearch/bootstrap/Elasticsearch.java | 5 ++--- .../src/main/java/org/elasticsearch/index/store/Store.java | 3 +-- .../elasticsearch/gateway/ReplicaShardAllocatorTests.java | 5 +++-- .../org/elasticsearch/index/engine/InternalEngineTests.java | 3 +-- .../index/snapshots/blobstore/FileInfoTests.java | 4 ++-- .../test/java/org/elasticsearch/index/store/StoreTests.java | 4 ++-- .../elasticsearch/indices/recovery/RecoveryStatusTests.java | 5 +++-- .../blobstore/ShardSnapshotTaskRunnerTests.java | 3 +-- .../src/main/java/org/elasticsearch/test/ESTestCase.java | 3 +-- .../store/SearchableSnapshotDirectoryStatsTests.java | 3 +-- .../store/SearchableSnapshotDirectoryTests.java | 3 +-- .../store/input/CachedBlobContainerIndexInputTests.java | 6 +++--- .../store/input/FrozenIndexInputTests.java | 4 ++-- .../recovery/plan/SnapshotsRecoveryPlannerService.java | 3 +-- .../recovery/plan/SnapshotsRecoveryPlannerServiceTests.java | 5 ++--- 17 files changed, 28 insertions(+), 37 deletions(-) diff --git a/qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/upgrades/FullClusterRestartIT.java b/qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/upgrades/FullClusterRestartIT.java index 6736e8d8c1fcc..ce602a6c7af7e 100644 --- a/qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/upgrades/FullClusterRestartIT.java +++ b/qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/upgrades/FullClusterRestartIT.java @@ -26,7 +26,6 @@ import org.elasticsearch.core.Booleans; import org.elasticsearch.core.CheckedFunction; import org.elasticsearch.index.IndexSettings; -import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.mapper.DateFieldMapper; import org.elasticsearch.rest.action.admin.indices.RestPutIndexTemplateAction; import org.elasticsearch.test.NotEqualMessageBuilder; @@ -959,7 +958,7 @@ public void testRecovery() throws Exception { 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 currentLuceneVersion = Version.CURRENT.luceneVersion().toString(); String bwcLuceneVersion = getOldClusterVersion().luceneVersion().toString(); String minCompatibleBWCVersion = Version.CURRENT.minimumCompatibilityVersion().luceneVersion().toString(); if (shouldHaveTranslog && false == currentLuceneVersion.equals(bwcLuceneVersion)) { diff --git a/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/plan/ShardSnapshotsServiceIT.java b/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/plan/ShardSnapshotsServiceIT.java index 3ffd81d1ed96f..2a4322784e98e 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/plan/ShardSnapshotsServiceIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/plan/ShardSnapshotsServiceIT.java @@ -20,7 +20,6 @@ import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.core.Tuple; import org.elasticsearch.env.Environment; -import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot; import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshots; @@ -193,7 +192,7 @@ public void testOnlyFetchesSnapshotFromEnabledRepositories() throws Exception { assertThat(commitVersion, is(equalTo(Version.CURRENT))); final org.apache.lucene.util.Version commitLuceneVersion = shardSnapshotData.getCommitLuceneVersion(); assertThat(commitLuceneVersion, is(notNullValue())); - assertThat(commitLuceneVersion, is(equalTo(IndexVersion.CURRENT.luceneVersion()))); + assertThat(commitLuceneVersion, is(equalTo(Version.CURRENT.luceneVersion()))); assertThat(shardSnapshotInfo.getShardId(), is(equalTo(shardId))); assertThat(shardSnapshotInfo.getSnapshot().getSnapshotId().getName(), is(equalTo(snapshotName))); diff --git a/server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java b/server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java index 1025f29553ac8..1b8bd19f5c846 100644 --- a/server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java +++ b/server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java @@ -27,7 +27,6 @@ import org.elasticsearch.core.IOUtils; import org.elasticsearch.core.SuppressForbidden; import org.elasticsearch.env.Environment; -import org.elasticsearch.index.IndexVersion; import org.elasticsearch.jdk.JarHell; import org.elasticsearch.monitor.jvm.HotThreads; import org.elasticsearch.monitor.jvm.JvmInfo; @@ -323,10 +322,10 @@ static void initializeProbes() { } static void checkLucene() { - if (IndexVersion.CURRENT.luceneVersion().equals(org.apache.lucene.util.Version.LATEST) == false) { + if (Version.CURRENT.luceneVersion().equals(org.apache.lucene.util.Version.LATEST) == false) { throw new AssertionError( "Lucene version mismatch this version of Elasticsearch requires lucene version [" - + IndexVersion.CURRENT.luceneVersion() + + Version.CURRENT.luceneVersion() + "] but the current lucene version is [" + org.apache.lucene.util.Version.LATEST + "]" diff --git a/server/src/main/java/org/elasticsearch/index/store/Store.java b/server/src/main/java/org/elasticsearch/index/store/Store.java index b70683ee1f775..b948431bb5040 100644 --- a/server/src/main/java/org/elasticsearch/index/store/Store.java +++ b/server/src/main/java/org/elasticsearch/index/store/Store.java @@ -61,7 +61,6 @@ import org.elasticsearch.env.ShardLock; import org.elasticsearch.env.ShardLockObtainFailedException; import org.elasticsearch.index.IndexSettings; -import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.engine.CombinedDeletionPolicy; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.seqno.SequenceNumbers; @@ -818,7 +817,7 @@ static MetadataSnapshot loadFromIndexCommit(IndexCommit commit, Directory direct } } if (maxVersion == null) { - maxVersion = IndexVersion.MINIMUM_COMPATIBLE.luceneVersion(); + maxVersion = org.elasticsearch.Version.CURRENT.minimumIndexCompatibilityVersion().luceneVersion(); } final String segmentsFile = segmentCommitInfos.getSegmentsFileName(); checksumFromLuceneFile( diff --git a/server/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java b/server/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java index 9b710ddf2df4b..10005247d6e55 100644 --- a/server/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java +++ b/server/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java @@ -37,7 +37,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.core.TimeValue; -import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.seqno.ReplicationTracker; import org.elasticsearch.index.seqno.RetentionLease; @@ -67,7 +66,9 @@ import static org.hamcrest.Matchers.hasSize; public class ReplicaShardAllocatorTests extends ESAllocationTestCase { - private static final String MIN_SUPPORTED_LUCENE_VERSION = IndexVersion.MINIMUM_COMPATIBLE.luceneVersion().toString(); + private static final String MIN_SUPPORTED_LUCENE_VERSION = Version.CURRENT.minimumIndexCompatibilityVersion() + .luceneVersion() + .toString(); private final ShardId shardId = new ShardId("test", "_na_", 0); private final DiscoveryNode node1 = newNode("node1"); diff --git a/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java b/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java index ff115b2e3e4b7..1e3f7794dd72c 100644 --- a/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java +++ b/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java @@ -99,7 +99,6 @@ import org.elasticsearch.core.Tuple; import org.elasticsearch.index.IndexModule; import org.elasticsearch.index.IndexSettings; -import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.VersionType; import org.elasticsearch.index.codec.CodecService; import org.elasticsearch.index.fieldvisitor.FieldsVisitor; @@ -6726,7 +6725,7 @@ public long softUpdateDocuments(Term term, Iterable userData = new HashMap<>(store.readLastCommittedSegmentsInfo().userData); userData.remove(Engine.MIN_RETAINED_SEQNO); IndexWriterConfig indexWriterConfig = new IndexWriterConfig(null).setOpenMode(IndexWriterConfig.OpenMode.APPEND) - .setIndexCreatedVersionMajor(IndexVersion.CURRENT.luceneVersion().major) + .setIndexCreatedVersionMajor(Version.CURRENT.luceneVersion().major) .setSoftDeletesField(Lucene.SOFT_DELETES_FIELD) .setCommitOnClose(false) .setMergePolicy(NoMergePolicy.INSTANCE); diff --git a/server/src/test/java/org/elasticsearch/index/snapshots/blobstore/FileInfoTests.java b/server/src/test/java/org/elasticsearch/index/snapshots/blobstore/FileInfoTests.java index c4456ccd551e0..0447f7394beac 100644 --- a/server/src/test/java/org/elasticsearch/index/snapshots/blobstore/FileInfoTests.java +++ b/server/src/test/java/org/elasticsearch/index/snapshots/blobstore/FileInfoTests.java @@ -12,7 +12,6 @@ import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.unit.ByteSizeValue; -import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot.FileInfo; import org.elasticsearch.index.store.StoreFileMetadata; import org.elasticsearch.test.ESTestCase; @@ -32,7 +31,8 @@ import static org.hamcrest.Matchers.is; public class FileInfoTests extends ESTestCase { - private static final org.apache.lucene.util.Version MIN_SUPPORTED_LUCENE_VERSION = IndexVersion.MINIMUM_COMPATIBLE.luceneVersion(); + private static final Version MIN_SUPPORTED_LUCENE_VERSION = org.elasticsearch.Version.CURRENT.minimumIndexCompatibilityVersion() + .luceneVersion(); public void testToFromXContent() throws IOException { final int iters = scaledRandomIntBetween(1, 10); diff --git a/server/src/test/java/org/elasticsearch/index/store/StoreTests.java b/server/src/test/java/org/elasticsearch/index/store/StoreTests.java index 25f4c4fce869c..f0e94ff2a1a83 100644 --- a/server/src/test/java/org/elasticsearch/index/store/StoreTests.java +++ b/server/src/test/java/org/elasticsearch/index/store/StoreTests.java @@ -54,7 +54,6 @@ import org.elasticsearch.env.ShardLock; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexSettings; -import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.seqno.ReplicationTracker; import org.elasticsearch.index.seqno.RetentionLease; @@ -106,7 +105,8 @@ public class StoreTests extends ESTestCase { "index", Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, org.elasticsearch.Version.CURRENT).build() ); - private static final Version MIN_SUPPORTED_LUCENE_VERSION = IndexVersion.MINIMUM_COMPATIBLE.luceneVersion(); + private static final Version MIN_SUPPORTED_LUCENE_VERSION = org.elasticsearch.Version.CURRENT.minimumIndexCompatibilityVersion() + .luceneVersion(); public void testRefCount() { final ShardId shardId = new ShardId("index", "_na_", 1); diff --git a/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryStatusTests.java b/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryStatusTests.java index e8bed42b682d1..9d117e5595591 100644 --- a/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryStatusTests.java +++ b/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryStatusTests.java @@ -10,9 +10,9 @@ import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil; import org.apache.lucene.codecs.CodecUtil; import org.apache.lucene.store.IndexOutput; +import org.apache.lucene.util.Version; import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.index.IndexService; -import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.shard.IndexShard; import org.elasticsearch.index.store.StoreFileMetadata; import org.elasticsearch.test.ESSingleNodeTestCase; @@ -22,7 +22,8 @@ import java.util.regex.Pattern; public class RecoveryStatusTests extends ESSingleNodeTestCase { - private static final org.apache.lucene.util.Version MIN_SUPPORTED_LUCENE_VERSION = IndexVersion.MINIMUM_COMPATIBLE.luceneVersion(); + private static final Version MIN_SUPPORTED_LUCENE_VERSION = org.elasticsearch.Version.CURRENT.minimumIndexCompatibilityVersion() + .luceneVersion(); public void testRenameTempFiles() throws IOException { IndexService service = createIndex("foo"); diff --git a/server/src/test/java/org/elasticsearch/repositories/blobstore/ShardSnapshotTaskRunnerTests.java b/server/src/test/java/org/elasticsearch/repositories/blobstore/ShardSnapshotTaskRunnerTests.java index d042fc2fa0a9f..7ca505fc3ef9d 100644 --- a/server/src/test/java/org/elasticsearch/repositories/blobstore/ShardSnapshotTaskRunnerTests.java +++ b/server/src/test/java/org/elasticsearch/repositories/blobstore/ShardSnapshotTaskRunnerTests.java @@ -16,7 +16,6 @@ import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.IndexSettings; -import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.snapshots.IndexShardSnapshotStatus; @@ -101,7 +100,7 @@ public int finishedShardSnapshotTasks() { public static BlobStoreIndexShardSnapshot.FileInfo dummyFileInfo() { String filename = randomAlphaOfLength(10); - StoreFileMetadata metadata = new StoreFileMetadata(filename, 10, "CHECKSUM", IndexVersion.CURRENT.luceneVersion().toString()); + StoreFileMetadata metadata = new StoreFileMetadata(filename, 10, "CHECKSUM", Version.CURRENT.luceneVersion().toString()); return new BlobStoreIndexShardSnapshot.FileInfo(filename, metadata, null); } diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java index 3f1880cb3dd8c..4cd9a54c86381 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java @@ -84,7 +84,6 @@ import org.elasticsearch.env.TestEnvironment; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexSettings; -import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.analysis.AnalysisRegistry; import org.elasticsearch.index.analysis.CharFilterFactory; import org.elasticsearch.index.analysis.IndexAnalyzers; @@ -1897,7 +1896,7 @@ public String toString() { * @param message an additional message or link with information on the fix */ protected void skipTestWaitingForLuceneFix(org.apache.lucene.util.Version luceneVersionWithFix, String message) { - final boolean currentVersionHasFix = IndexVersion.CURRENT.luceneVersion().onOrAfter(luceneVersionWithFix); + final boolean currentVersionHasFix = Version.CURRENT.luceneVersion().onOrAfter(luceneVersionWithFix); assumeTrue("Skipping test as it is waiting on a Lucene fix: " + message, currentVersionHasFix); fail("Remove call of skipTestWaitingForLuceneFix in " + RandomizedTest.getContext().getTargetMethod()); } diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryStatsTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryStatsTests.java index 3ec20c652a3de..9b72cd22e7ac6 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryStatsTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryStatsTests.java @@ -28,7 +28,6 @@ import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.core.TimeValue; -import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardPath; import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot; @@ -642,7 +641,7 @@ private void executeTestCase( fileName, fileContent.length, fileChecksum, - IndexVersion.CURRENT.luceneVersion().toString() + Version.CURRENT.luceneVersion().toString() ); final List files = List.of(new FileInfo(blobName, metadata, ByteSizeValue.ofBytes(fileContent.length))); final BlobStoreIndexShardSnapshot snapshot = new BlobStoreIndexShardSnapshot(snapshotId.getName(), 0L, files, 0L, 0L, 0, 0L); diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryTests.java index 35f06b34517f9..c8a8e9c805ebe 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryTests.java @@ -69,7 +69,6 @@ import org.elasticsearch.env.Environment; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexSettings; -import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.seqno.SequenceNumbers; import org.elasticsearch.index.shard.ShardId; @@ -734,7 +733,7 @@ public void testClearCache() throws Exception { randomFiles.add( new BlobStoreIndexShardSnapshot.FileInfo( blobName, - new StoreFileMetadata(fileName, input.length, checksum, IndexVersion.CURRENT.luceneVersion().toString()), + new StoreFileMetadata(fileName, input.length, checksum, Version.CURRENT.luceneVersion().toString()), ByteSizeValue.ofBytes(input.length) ) ); diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/CachedBlobContainerIndexInputTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/CachedBlobContainerIndexInputTests.java index 8655ba91907d6..461cf90d0b37c 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/CachedBlobContainerIndexInputTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/CachedBlobContainerIndexInputTests.java @@ -8,6 +8,7 @@ import org.apache.lucene.store.IndexInput; import org.elasticsearch.ExceptionsHelper; +import org.elasticsearch.Version; import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.blobcache.BlobCacheTestUtils; import org.elasticsearch.blobcache.shared.SharedBlobCacheService; @@ -16,7 +17,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.core.Tuple; -import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardPath; import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot; @@ -75,7 +75,7 @@ public void testRandomReads() throws Exception { fileName, input.length, checksum, - IndexVersion.CURRENT.luceneVersion().toString() + Version.CURRENT.luceneVersion().toString() ); final int partSize = randomBoolean() ? input.length : randomIntBetween(1, input.length); @@ -195,7 +195,7 @@ public void testThrowsEOFException() throws Exception { fileName, input.length, checksum, - IndexVersion.CURRENT.luceneVersion().toString() + Version.CURRENT.luceneVersion().toString() ); final BlobStoreIndexShardSnapshot snapshot = new BlobStoreIndexShardSnapshot( diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/FrozenIndexInputTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/FrozenIndexInputTests.java index 864940e465dd5..c833bf72f9d7c 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/FrozenIndexInputTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/FrozenIndexInputTests.java @@ -8,6 +8,7 @@ package org.elasticsearch.xpack.searchablesnapshots.store.input; import org.apache.lucene.store.IndexInput; +import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.blobcache.shared.SharedBlobCacheService; import org.elasticsearch.blobcache.shared.SharedBytes; @@ -18,7 +19,6 @@ import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.env.TestEnvironment; import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardPath; import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot; @@ -55,7 +55,7 @@ public void testRandomReads() throws IOException { final FileInfo fileInfo = new FileInfo( randomAlphaOfLength(10), - new StoreFileMetadata(fileName, fileData.length, checksum, IndexVersion.CURRENT.luceneVersion().toString()), + new StoreFileMetadata(fileName, fileData.length, checksum, Version.CURRENT.luceneVersion().toString()), ByteSizeValue.ofBytes(fileData.length) ); diff --git a/x-pack/plugin/snapshot-based-recoveries/src/main/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerService.java b/x-pack/plugin/snapshot-based-recoveries/src/main/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerService.java index a488a491c6d03..e8cabc6b5b7c1 100644 --- a/x-pack/plugin/snapshot-based-recoveries/src/main/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerService.java +++ b/x-pack/plugin/snapshot-based-recoveries/src/main/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerService.java @@ -13,7 +13,6 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.common.Strings; import org.elasticsearch.core.Nullable; -import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot; import org.elasticsearch.index.store.Store; @@ -189,7 +188,7 @@ private boolean isSnapshotVersionCompatible(ShardSnapshot snapshot) { // same version. if (commitVersion == null) { assert SEQ_NO_SNAPSHOT_RECOVERIES_SUPPORTED_VERSION.luceneVersion().onOrAfter(snapshot.getCommitLuceneVersion()); - return IndexVersion.CURRENT.luceneVersion().onOrAfter(snapshot.getCommitLuceneVersion()); + return Version.CURRENT.luceneVersion().onOrAfter(snapshot.getCommitLuceneVersion()); } return commitVersion.onOrBefore(Version.CURRENT); } diff --git a/x-pack/plugin/snapshot-based-recoveries/src/test/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerServiceTests.java b/x-pack/plugin/snapshot-based-recoveries/src/test/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerServiceTests.java index 3fad20366c272..677ce4e25eefb 100644 --- a/x-pack/plugin/snapshot-based-recoveries/src/test/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerServiceTests.java +++ b/x-pack/plugin/snapshot-based-recoveries/src/test/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerServiceTests.java @@ -27,7 +27,6 @@ import org.elasticsearch.core.CheckedConsumer; import org.elasticsearch.core.IOUtils; import org.elasticsearch.index.IndexSettings; -import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot; import org.elasticsearch.index.store.Store; @@ -601,7 +600,7 @@ private void writeRandomDocs(Store store, int numDocs) throws IOException { } private ShardSnapshot createShardSnapshotThatDoNotShareSegmentFiles(String repoName) { - return createShardSnapshotThatDoNotShareSegmentFiles(repoName, Version.CURRENT, IndexVersion.CURRENT.luceneVersion()); + return createShardSnapshotThatDoNotShareSegmentFiles(repoName, Version.CURRENT, Version.CURRENT.luceneVersion()); } private ShardSnapshot createShardSnapshotThatDoNotShareSegmentFiles( @@ -630,7 +629,7 @@ private ShardSnapshot createShardSnapshotThatSharesSegmentFiles(Store store, Str ); snapshotFiles.add(fileInfo); } - return createShardSnapshot(repository, snapshotFiles, Version.CURRENT, IndexVersion.CURRENT.luceneVersion()); + return createShardSnapshot(repository, snapshotFiles, Version.CURRENT, Version.CURRENT.luceneVersion()); } private ShardSnapshot createShardSnapshot( From b65f71d11de102fb79c4b908ed1aec47dca496d2 Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Mon, 22 May 2023 16:23:31 +0100 Subject: [PATCH 18/20] Add between method --- .../src/main/java/org/elasticsearch/index/IndexVersion.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/src/main/java/org/elasticsearch/index/IndexVersion.java b/server/src/main/java/org/elasticsearch/index/IndexVersion.java index 3db3af944157c..ceb2ffb8f4522 100644 --- a/server/src/main/java/org/elasticsearch/index/IndexVersion.java +++ b/server/src/main/java/org/elasticsearch/index/IndexVersion.java @@ -298,6 +298,11 @@ public boolean onOrBefore(IndexVersion version) { return version.id >= id; } + public boolean between(IndexVersion lowerInclusive, IndexVersion upperExclusive) { + if (upperExclusive.onOrBefore(lowerInclusive)) throw new IllegalArgumentException(); + return onOrAfter(lowerInclusive) && before(upperExclusive); + } + public boolean isLegacyIndexVersion() { return before(MINIMUM_COMPATIBLE); } From e2b58622066db1379babad85d789897815c69d83 Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Tue, 23 May 2023 16:44:58 +0100 Subject: [PATCH 19/20] Migrate some uses of Version.luceneVersion to IndexVersion --- .../org/elasticsearch/upgrades/FullClusterRestartIT.java | 3 ++- .../indices/recovery/plan/ShardSnapshotsServiceIT.java | 3 ++- .../java/org/elasticsearch/bootstrap/Elasticsearch.java | 5 +++-- .../src/main/java/org/elasticsearch/index/store/Store.java | 3 ++- .../elasticsearch/gateway/ReplicaShardAllocatorTests.java | 5 ++--- .../org/elasticsearch/index/engine/InternalEngineTests.java | 3 ++- .../index/snapshots/blobstore/FileInfoTests.java | 4 ++-- .../test/java/org/elasticsearch/index/store/StoreTests.java | 4 ++-- .../elasticsearch/indices/recovery/RecoveryStatusTests.java | 5 ++--- .../blobstore/ShardSnapshotTaskRunnerTests.java | 3 ++- .../src/main/java/org/elasticsearch/test/ESTestCase.java | 3 ++- .../store/SearchableSnapshotDirectoryStatsTests.java | 3 ++- .../store/SearchableSnapshotDirectoryTests.java | 3 ++- .../store/input/CachedBlobContainerIndexInputTests.java | 6 +++--- .../store/input/FrozenIndexInputTests.java | 4 ++-- .../recovery/plan/SnapshotsRecoveryPlannerService.java | 3 ++- .../recovery/plan/SnapshotsRecoveryPlannerServiceTests.java | 5 +++-- 17 files changed, 37 insertions(+), 28 deletions(-) diff --git a/qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/upgrades/FullClusterRestartIT.java b/qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/upgrades/FullClusterRestartIT.java index ce602a6c7af7e..6736e8d8c1fcc 100644 --- a/qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/upgrades/FullClusterRestartIT.java +++ b/qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/upgrades/FullClusterRestartIT.java @@ -26,6 +26,7 @@ import org.elasticsearch.core.Booleans; import org.elasticsearch.core.CheckedFunction; import org.elasticsearch.index.IndexSettings; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.mapper.DateFieldMapper; import org.elasticsearch.rest.action.admin.indices.RestPutIndexTemplateAction; import org.elasticsearch.test.NotEqualMessageBuilder; @@ -958,7 +959,7 @@ public void testRecovery() throws Exception { 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 = Version.CURRENT.luceneVersion().toString(); + String currentLuceneVersion = IndexVersion.CURRENT.luceneVersion().toString(); String bwcLuceneVersion = getOldClusterVersion().luceneVersion().toString(); String minCompatibleBWCVersion = Version.CURRENT.minimumCompatibilityVersion().luceneVersion().toString(); if (shouldHaveTranslog && false == currentLuceneVersion.equals(bwcLuceneVersion)) { diff --git a/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/plan/ShardSnapshotsServiceIT.java b/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/plan/ShardSnapshotsServiceIT.java index 2a4322784e98e..3ffd81d1ed96f 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/plan/ShardSnapshotsServiceIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/plan/ShardSnapshotsServiceIT.java @@ -20,6 +20,7 @@ import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.core.Tuple; import org.elasticsearch.env.Environment; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot; import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshots; @@ -192,7 +193,7 @@ public void testOnlyFetchesSnapshotFromEnabledRepositories() throws Exception { assertThat(commitVersion, is(equalTo(Version.CURRENT))); final org.apache.lucene.util.Version commitLuceneVersion = shardSnapshotData.getCommitLuceneVersion(); assertThat(commitLuceneVersion, is(notNullValue())); - assertThat(commitLuceneVersion, is(equalTo(Version.CURRENT.luceneVersion()))); + assertThat(commitLuceneVersion, is(equalTo(IndexVersion.CURRENT.luceneVersion()))); assertThat(shardSnapshotInfo.getShardId(), is(equalTo(shardId))); assertThat(shardSnapshotInfo.getSnapshot().getSnapshotId().getName(), is(equalTo(snapshotName))); diff --git a/server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java b/server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java index 1b8bd19f5c846..1025f29553ac8 100644 --- a/server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java +++ b/server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java @@ -27,6 +27,7 @@ import org.elasticsearch.core.IOUtils; import org.elasticsearch.core.SuppressForbidden; import org.elasticsearch.env.Environment; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.jdk.JarHell; import org.elasticsearch.monitor.jvm.HotThreads; import org.elasticsearch.monitor.jvm.JvmInfo; @@ -322,10 +323,10 @@ static void initializeProbes() { } static void checkLucene() { - if (Version.CURRENT.luceneVersion().equals(org.apache.lucene.util.Version.LATEST) == false) { + if (IndexVersion.CURRENT.luceneVersion().equals(org.apache.lucene.util.Version.LATEST) == false) { throw new AssertionError( "Lucene version mismatch this version of Elasticsearch requires lucene version [" - + Version.CURRENT.luceneVersion() + + IndexVersion.CURRENT.luceneVersion() + "] but the current lucene version is [" + org.apache.lucene.util.Version.LATEST + "]" diff --git a/server/src/main/java/org/elasticsearch/index/store/Store.java b/server/src/main/java/org/elasticsearch/index/store/Store.java index b948431bb5040..b70683ee1f775 100644 --- a/server/src/main/java/org/elasticsearch/index/store/Store.java +++ b/server/src/main/java/org/elasticsearch/index/store/Store.java @@ -61,6 +61,7 @@ import org.elasticsearch.env.ShardLock; import org.elasticsearch.env.ShardLockObtainFailedException; import org.elasticsearch.index.IndexSettings; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.engine.CombinedDeletionPolicy; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.seqno.SequenceNumbers; @@ -817,7 +818,7 @@ static MetadataSnapshot loadFromIndexCommit(IndexCommit commit, Directory direct } } if (maxVersion == null) { - maxVersion = org.elasticsearch.Version.CURRENT.minimumIndexCompatibilityVersion().luceneVersion(); + maxVersion = IndexVersion.MINIMUM_COMPATIBLE.luceneVersion(); } final String segmentsFile = segmentCommitInfos.getSegmentsFileName(); checksumFromLuceneFile( diff --git a/server/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java b/server/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java index 10005247d6e55..9b710ddf2df4b 100644 --- a/server/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java +++ b/server/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java @@ -37,6 +37,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.core.TimeValue; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.seqno.ReplicationTracker; import org.elasticsearch.index.seqno.RetentionLease; @@ -66,9 +67,7 @@ import static org.hamcrest.Matchers.hasSize; public class ReplicaShardAllocatorTests extends ESAllocationTestCase { - private static final String MIN_SUPPORTED_LUCENE_VERSION = Version.CURRENT.minimumIndexCompatibilityVersion() - .luceneVersion() - .toString(); + private static final String MIN_SUPPORTED_LUCENE_VERSION = IndexVersion.MINIMUM_COMPATIBLE.luceneVersion().toString(); private final ShardId shardId = new ShardId("test", "_na_", 0); private final DiscoveryNode node1 = newNode("node1"); diff --git a/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java b/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java index 1e3f7794dd72c..ff115b2e3e4b7 100644 --- a/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java +++ b/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java @@ -99,6 +99,7 @@ import org.elasticsearch.core.Tuple; import org.elasticsearch.index.IndexModule; import org.elasticsearch.index.IndexSettings; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.VersionType; import org.elasticsearch.index.codec.CodecService; import org.elasticsearch.index.fieldvisitor.FieldsVisitor; @@ -6725,7 +6726,7 @@ public long softUpdateDocuments(Term term, Iterable userData = new HashMap<>(store.readLastCommittedSegmentsInfo().userData); userData.remove(Engine.MIN_RETAINED_SEQNO); IndexWriterConfig indexWriterConfig = new IndexWriterConfig(null).setOpenMode(IndexWriterConfig.OpenMode.APPEND) - .setIndexCreatedVersionMajor(Version.CURRENT.luceneVersion().major) + .setIndexCreatedVersionMajor(IndexVersion.CURRENT.luceneVersion().major) .setSoftDeletesField(Lucene.SOFT_DELETES_FIELD) .setCommitOnClose(false) .setMergePolicy(NoMergePolicy.INSTANCE); diff --git a/server/src/test/java/org/elasticsearch/index/snapshots/blobstore/FileInfoTests.java b/server/src/test/java/org/elasticsearch/index/snapshots/blobstore/FileInfoTests.java index 0447f7394beac..c4456ccd551e0 100644 --- a/server/src/test/java/org/elasticsearch/index/snapshots/blobstore/FileInfoTests.java +++ b/server/src/test/java/org/elasticsearch/index/snapshots/blobstore/FileInfoTests.java @@ -12,6 +12,7 @@ import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.unit.ByteSizeValue; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot.FileInfo; import org.elasticsearch.index.store.StoreFileMetadata; import org.elasticsearch.test.ESTestCase; @@ -31,8 +32,7 @@ import static org.hamcrest.Matchers.is; public class FileInfoTests extends ESTestCase { - private static final Version MIN_SUPPORTED_LUCENE_VERSION = org.elasticsearch.Version.CURRENT.minimumIndexCompatibilityVersion() - .luceneVersion(); + private static final org.apache.lucene.util.Version MIN_SUPPORTED_LUCENE_VERSION = IndexVersion.MINIMUM_COMPATIBLE.luceneVersion(); public void testToFromXContent() throws IOException { final int iters = scaledRandomIntBetween(1, 10); diff --git a/server/src/test/java/org/elasticsearch/index/store/StoreTests.java b/server/src/test/java/org/elasticsearch/index/store/StoreTests.java index f0e94ff2a1a83..25f4c4fce869c 100644 --- a/server/src/test/java/org/elasticsearch/index/store/StoreTests.java +++ b/server/src/test/java/org/elasticsearch/index/store/StoreTests.java @@ -54,6 +54,7 @@ import org.elasticsearch.env.ShardLock; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexSettings; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.seqno.ReplicationTracker; import org.elasticsearch.index.seqno.RetentionLease; @@ -105,8 +106,7 @@ public class StoreTests extends ESTestCase { "index", Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, org.elasticsearch.Version.CURRENT).build() ); - private static final Version MIN_SUPPORTED_LUCENE_VERSION = org.elasticsearch.Version.CURRENT.minimumIndexCompatibilityVersion() - .luceneVersion(); + private static final Version MIN_SUPPORTED_LUCENE_VERSION = IndexVersion.MINIMUM_COMPATIBLE.luceneVersion(); public void testRefCount() { final ShardId shardId = new ShardId("index", "_na_", 1); diff --git a/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryStatusTests.java b/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryStatusTests.java index 9d117e5595591..e8bed42b682d1 100644 --- a/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryStatusTests.java +++ b/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryStatusTests.java @@ -10,9 +10,9 @@ import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil; import org.apache.lucene.codecs.CodecUtil; import org.apache.lucene.store.IndexOutput; -import org.apache.lucene.util.Version; import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.index.IndexService; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.shard.IndexShard; import org.elasticsearch.index.store.StoreFileMetadata; import org.elasticsearch.test.ESSingleNodeTestCase; @@ -22,8 +22,7 @@ import java.util.regex.Pattern; public class RecoveryStatusTests extends ESSingleNodeTestCase { - private static final Version MIN_SUPPORTED_LUCENE_VERSION = org.elasticsearch.Version.CURRENT.minimumIndexCompatibilityVersion() - .luceneVersion(); + private static final org.apache.lucene.util.Version MIN_SUPPORTED_LUCENE_VERSION = IndexVersion.MINIMUM_COMPATIBLE.luceneVersion(); public void testRenameTempFiles() throws IOException { IndexService service = createIndex("foo"); diff --git a/server/src/test/java/org/elasticsearch/repositories/blobstore/ShardSnapshotTaskRunnerTests.java b/server/src/test/java/org/elasticsearch/repositories/blobstore/ShardSnapshotTaskRunnerTests.java index 7ca505fc3ef9d..d042fc2fa0a9f 100644 --- a/server/src/test/java/org/elasticsearch/repositories/blobstore/ShardSnapshotTaskRunnerTests.java +++ b/server/src/test/java/org/elasticsearch/repositories/blobstore/ShardSnapshotTaskRunnerTests.java @@ -16,6 +16,7 @@ import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.IndexSettings; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.snapshots.IndexShardSnapshotStatus; @@ -100,7 +101,7 @@ public int finishedShardSnapshotTasks() { public static BlobStoreIndexShardSnapshot.FileInfo dummyFileInfo() { String filename = randomAlphaOfLength(10); - StoreFileMetadata metadata = new StoreFileMetadata(filename, 10, "CHECKSUM", Version.CURRENT.luceneVersion().toString()); + StoreFileMetadata metadata = new StoreFileMetadata(filename, 10, "CHECKSUM", IndexVersion.CURRENT.luceneVersion().toString()); return new BlobStoreIndexShardSnapshot.FileInfo(filename, metadata, null); } diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java index 4cd9a54c86381..3f1880cb3dd8c 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java @@ -84,6 +84,7 @@ import org.elasticsearch.env.TestEnvironment; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexSettings; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.analysis.AnalysisRegistry; import org.elasticsearch.index.analysis.CharFilterFactory; import org.elasticsearch.index.analysis.IndexAnalyzers; @@ -1896,7 +1897,7 @@ public String toString() { * @param message an additional message or link with information on the fix */ protected void skipTestWaitingForLuceneFix(org.apache.lucene.util.Version luceneVersionWithFix, String message) { - final boolean currentVersionHasFix = Version.CURRENT.luceneVersion().onOrAfter(luceneVersionWithFix); + final boolean currentVersionHasFix = IndexVersion.CURRENT.luceneVersion().onOrAfter(luceneVersionWithFix); assumeTrue("Skipping test as it is waiting on a Lucene fix: " + message, currentVersionHasFix); fail("Remove call of skipTestWaitingForLuceneFix in " + RandomizedTest.getContext().getTargetMethod()); } diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryStatsTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryStatsTests.java index 9b72cd22e7ac6..3ec20c652a3de 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryStatsTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryStatsTests.java @@ -28,6 +28,7 @@ import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.core.TimeValue; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardPath; import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot; @@ -641,7 +642,7 @@ private void executeTestCase( fileName, fileContent.length, fileChecksum, - Version.CURRENT.luceneVersion().toString() + IndexVersion.CURRENT.luceneVersion().toString() ); final List files = List.of(new FileInfo(blobName, metadata, ByteSizeValue.ofBytes(fileContent.length))); final BlobStoreIndexShardSnapshot snapshot = new BlobStoreIndexShardSnapshot(snapshotId.getName(), 0L, files, 0L, 0L, 0, 0L); diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryTests.java index c8a8e9c805ebe..35f06b34517f9 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryTests.java @@ -69,6 +69,7 @@ import org.elasticsearch.env.Environment; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexSettings; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.seqno.SequenceNumbers; import org.elasticsearch.index.shard.ShardId; @@ -733,7 +734,7 @@ public void testClearCache() throws Exception { randomFiles.add( new BlobStoreIndexShardSnapshot.FileInfo( blobName, - new StoreFileMetadata(fileName, input.length, checksum, Version.CURRENT.luceneVersion().toString()), + new StoreFileMetadata(fileName, input.length, checksum, IndexVersion.CURRENT.luceneVersion().toString()), ByteSizeValue.ofBytes(input.length) ) ); diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/CachedBlobContainerIndexInputTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/CachedBlobContainerIndexInputTests.java index 461cf90d0b37c..8655ba91907d6 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/CachedBlobContainerIndexInputTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/CachedBlobContainerIndexInputTests.java @@ -8,7 +8,6 @@ import org.apache.lucene.store.IndexInput; import org.elasticsearch.ExceptionsHelper; -import org.elasticsearch.Version; import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.blobcache.BlobCacheTestUtils; import org.elasticsearch.blobcache.shared.SharedBlobCacheService; @@ -17,6 +16,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.core.Tuple; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardPath; import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot; @@ -75,7 +75,7 @@ public void testRandomReads() throws Exception { fileName, input.length, checksum, - Version.CURRENT.luceneVersion().toString() + IndexVersion.CURRENT.luceneVersion().toString() ); final int partSize = randomBoolean() ? input.length : randomIntBetween(1, input.length); @@ -195,7 +195,7 @@ public void testThrowsEOFException() throws Exception { fileName, input.length, checksum, - Version.CURRENT.luceneVersion().toString() + IndexVersion.CURRENT.luceneVersion().toString() ); final BlobStoreIndexShardSnapshot snapshot = new BlobStoreIndexShardSnapshot( diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/FrozenIndexInputTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/FrozenIndexInputTests.java index c833bf72f9d7c..864940e465dd5 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/FrozenIndexInputTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/input/FrozenIndexInputTests.java @@ -8,7 +8,6 @@ package org.elasticsearch.xpack.searchablesnapshots.store.input; import org.apache.lucene.store.IndexInput; -import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.blobcache.shared.SharedBlobCacheService; import org.elasticsearch.blobcache.shared.SharedBytes; @@ -19,6 +18,7 @@ import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.env.TestEnvironment; import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardPath; import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot; @@ -55,7 +55,7 @@ public void testRandomReads() throws IOException { final FileInfo fileInfo = new FileInfo( randomAlphaOfLength(10), - new StoreFileMetadata(fileName, fileData.length, checksum, Version.CURRENT.luceneVersion().toString()), + new StoreFileMetadata(fileName, fileData.length, checksum, IndexVersion.CURRENT.luceneVersion().toString()), ByteSizeValue.ofBytes(fileData.length) ); diff --git a/x-pack/plugin/snapshot-based-recoveries/src/main/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerService.java b/x-pack/plugin/snapshot-based-recoveries/src/main/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerService.java index e8cabc6b5b7c1..a488a491c6d03 100644 --- a/x-pack/plugin/snapshot-based-recoveries/src/main/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerService.java +++ b/x-pack/plugin/snapshot-based-recoveries/src/main/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerService.java @@ -13,6 +13,7 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.common.Strings; import org.elasticsearch.core.Nullable; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot; import org.elasticsearch.index.store.Store; @@ -188,7 +189,7 @@ private boolean isSnapshotVersionCompatible(ShardSnapshot snapshot) { // same version. if (commitVersion == null) { assert SEQ_NO_SNAPSHOT_RECOVERIES_SUPPORTED_VERSION.luceneVersion().onOrAfter(snapshot.getCommitLuceneVersion()); - return Version.CURRENT.luceneVersion().onOrAfter(snapshot.getCommitLuceneVersion()); + return IndexVersion.CURRENT.luceneVersion().onOrAfter(snapshot.getCommitLuceneVersion()); } return commitVersion.onOrBefore(Version.CURRENT); } diff --git a/x-pack/plugin/snapshot-based-recoveries/src/test/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerServiceTests.java b/x-pack/plugin/snapshot-based-recoveries/src/test/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerServiceTests.java index 677ce4e25eefb..3fad20366c272 100644 --- a/x-pack/plugin/snapshot-based-recoveries/src/test/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerServiceTests.java +++ b/x-pack/plugin/snapshot-based-recoveries/src/test/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/plan/SnapshotsRecoveryPlannerServiceTests.java @@ -27,6 +27,7 @@ import org.elasticsearch.core.CheckedConsumer; import org.elasticsearch.core.IOUtils; import org.elasticsearch.index.IndexSettings; +import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot; import org.elasticsearch.index.store.Store; @@ -600,7 +601,7 @@ private void writeRandomDocs(Store store, int numDocs) throws IOException { } private ShardSnapshot createShardSnapshotThatDoNotShareSegmentFiles(String repoName) { - return createShardSnapshotThatDoNotShareSegmentFiles(repoName, Version.CURRENT, Version.CURRENT.luceneVersion()); + return createShardSnapshotThatDoNotShareSegmentFiles(repoName, Version.CURRENT, IndexVersion.CURRENT.luceneVersion()); } private ShardSnapshot createShardSnapshotThatDoNotShareSegmentFiles( @@ -629,7 +630,7 @@ private ShardSnapshot createShardSnapshotThatSharesSegmentFiles(Store store, Str ); snapshotFiles.add(fileInfo); } - return createShardSnapshot(repository, snapshotFiles, Version.CURRENT, Version.CURRENT.luceneVersion()); + return createShardSnapshot(repository, snapshotFiles, Version.CURRENT, IndexVersion.CURRENT.luceneVersion()); } private ShardSnapshot createShardSnapshot( From 4d67687575818ea1c14b3ab098142626335579c4 Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Thu, 8 Jun 2023 15:28:37 +0100 Subject: [PATCH 20/20] Remove superfluous full names --- .../elasticsearch/index/snapshots/blobstore/FileInfoTests.java | 2 +- .../elasticsearch/indices/recovery/RecoveryStatusTests.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/index/snapshots/blobstore/FileInfoTests.java b/server/src/test/java/org/elasticsearch/index/snapshots/blobstore/FileInfoTests.java index f638c69f8df27..1f72c7df8a9aa 100644 --- a/server/src/test/java/org/elasticsearch/index/snapshots/blobstore/FileInfoTests.java +++ b/server/src/test/java/org/elasticsearch/index/snapshots/blobstore/FileInfoTests.java @@ -32,7 +32,7 @@ import static org.hamcrest.Matchers.is; public class FileInfoTests extends ESTestCase { - private static final org.apache.lucene.util.Version MIN_SUPPORTED_LUCENE_VERSION = IndexVersion.MINIMUM_COMPATIBLE.luceneVersion(); + private static final Version MIN_SUPPORTED_LUCENE_VERSION = IndexVersion.MINIMUM_COMPATIBLE.luceneVersion(); public void testToFromXContent() throws IOException { final int iters = scaledRandomIntBetween(1, 10); diff --git a/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryStatusTests.java b/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryStatusTests.java index e8bed42b682d1..998497f991ed5 100644 --- a/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryStatusTests.java +++ b/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryStatusTests.java @@ -10,6 +10,7 @@ import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil; import org.apache.lucene.codecs.CodecUtil; import org.apache.lucene.store.IndexOutput; +import org.apache.lucene.util.Version; import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.IndexVersion; @@ -22,7 +23,7 @@ import java.util.regex.Pattern; public class RecoveryStatusTests extends ESSingleNodeTestCase { - private static final org.apache.lucene.util.Version MIN_SUPPORTED_LUCENE_VERSION = IndexVersion.MINIMUM_COMPATIBLE.luceneVersion(); + private static final Version MIN_SUPPORTED_LUCENE_VERSION = IndexVersion.MINIMUM_COMPATIBLE.luceneVersion(); public void testRenameTempFiles() throws IOException { IndexService service = createIndex("foo");