diff --git a/docs/changelog/107828.yaml b/docs/changelog/107828.yaml new file mode 100644 index 0000000000000..ba0d44029203d --- /dev/null +++ b/docs/changelog/107828.yaml @@ -0,0 +1,6 @@ +pr: 107828 +summary: Update several references to `IndexVersion.toString` to use `toReleaseVersion` +area: Infra/Core +type: bug +issues: + - 107821 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 e94638bb17791..1a86947acab95 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 @@ -48,7 +48,6 @@ import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.xcontent.json.JsonXContent; -import org.hamcrest.Matchers; import org.junit.Before; import org.junit.ClassRule; import org.junit.rules.RuleChain; @@ -81,8 +80,8 @@ import static org.elasticsearch.test.MapMatcher.matchesMap; import static org.elasticsearch.transport.RemoteClusterService.REMOTE_CLUSTER_COMPRESS; import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder; +import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.either; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.greaterThanOrEqualTo; @@ -1289,7 +1288,11 @@ private void checkSnapshot(String snapshotName, int count, String tookOnVersion, // the format can change depending on the ES node version running & this test code running assertThat( XContentMapValues.extractValue("snapshots.version", snapResponse), - either(Matchers.equalTo(List.of(tookOnVersion))).or(equalTo(List.of(tookOnIndexVersion.toString()))) + anyOf( + equalTo(List.of(tookOnVersion)), + equalTo(List.of(tookOnIndexVersion.toString())), + equalTo(List.of(tookOnIndexVersion.toReleaseVersion())) + ) ); // Remove the routing setting and template so we can test restoring them. diff --git a/qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/FeatureUpgradeIT.java b/qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/FeatureUpgradeIT.java index 47be0e5efff62..4fe45c05b157b 100644 --- a/qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/FeatureUpgradeIT.java +++ b/qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/FeatureUpgradeIT.java @@ -99,7 +99,7 @@ public void testGetFeatureUpgradeStatus() throws Exception { .orElse(Collections.emptyMap()); assertThat(feature, aMapWithSize(4)); - assertThat(feature.get("minimum_index_version"), equalTo(getOldClusterIndexVersion().toString())); + assertThat(feature.get("minimum_index_version"), equalTo(getOldClusterIndexVersion().toReleaseVersion())); // Feature migration happens only across major versions; also, we usually begin to require migrations once we start testing // for the next major version upgrade (see e.g. #93666). Trying to express this with features may be problematic, so we diff --git a/qa/system-indices/src/javaRestTest/java/org/elasticsearch/system/indices/FeatureUpgradeApiIT.java b/qa/system-indices/src/javaRestTest/java/org/elasticsearch/system/indices/FeatureUpgradeApiIT.java index 48f987d0359f0..8c790fe1cde49 100644 --- a/qa/system-indices/src/javaRestTest/java/org/elasticsearch/system/indices/FeatureUpgradeApiIT.java +++ b/qa/system-indices/src/javaRestTest/java/org/elasticsearch/system/indices/FeatureUpgradeApiIT.java @@ -61,7 +61,7 @@ public void testGetFeatureUpgradedStatuses() throws Exception { .orElse(Collections.emptyMap()); assertThat(testFeature.size(), equalTo(4)); - assertThat(testFeature.get("minimum_index_version"), equalTo(IndexVersion.current().toString())); + assertThat(testFeature.get("minimum_index_version"), equalTo(IndexVersion.current().toReleaseVersion())); assertThat(testFeature.get("migration_status"), equalTo("NO_MIGRATION_NEEDED")); assertThat(testFeature.get("indices"), instanceOf(List.class)); diff --git a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/RestoreSnapshotIT.java b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/RestoreSnapshotIT.java index 6c452103cc014..5f9ad28b561f8 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/RestoreSnapshotIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/RestoreSnapshotIT.java @@ -890,9 +890,9 @@ public void testFailOnAncientVersion() throws Exception { snapshotRestoreException.getMessage(), containsString( "the snapshot was created with Elasticsearch version [" - + oldVersion + + oldVersion.toReleaseVersion() + "] which is below the current versions minimum index compatibility version [" - + IndexVersions.MINIMUM_COMPATIBLE + + IndexVersions.MINIMUM_COMPATIBLE.toReleaseVersion() + "]" ) ); diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/migration/GetFeatureUpgradeStatusResponse.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/migration/GetFeatureUpgradeStatusResponse.java index 29846fab10977..ffbd6b70e9ed9 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/migration/GetFeatureUpgradeStatusResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/migration/GetFeatureUpgradeStatusResponse.java @@ -185,7 +185,7 @@ public void writeTo(StreamOutput out) throws IOException { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); builder.field("feature_name", this.featureName); - builder.field("minimum_index_version", this.minimumIndexVersion.toString()); + builder.field("minimum_index_version", this.minimumIndexVersion.toReleaseVersion()); builder.field("migration_status", this.upgradeStatus); builder.startArray("indices"); for (IndexInfo version : this.indexInfos) { @@ -300,7 +300,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws builder.startObject(); builder.field("index", this.indexName); - builder.field("version", this.version.toString()); + builder.field("version", this.version.toReleaseVersion()); if (exception != null) { builder.startObject("failure_cause"); { diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/stats/VersionStats.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/stats/VersionStats.java index 703a650489bbd..12fe846a9e68b 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/stats/VersionStats.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/stats/VersionStats.java @@ -168,7 +168,7 @@ static class SingleVersionStats implements ToXContentObject, Writeable, Comparab @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); - builder.field("version", version.toString()); + builder.field("version", version.toReleaseVersion()); builder.field("index_count", indexCount); builder.field("primary_shard_count", primaryShardCount); builder.humanReadableField("total_primary_bytes", "total_primary_size", ByteSizeValue.ofBytes(totalPrimaryByteCount)); diff --git a/server/src/main/java/org/elasticsearch/cluster/coordination/NodeJoinExecutor.java b/server/src/main/java/org/elasticsearch/cluster/coordination/NodeJoinExecutor.java index 573e4375aace7..2c024063e2399 100644 --- a/server/src/main/java/org/elasticsearch/cluster/coordination/NodeJoinExecutor.java +++ b/server/src/main/java/org/elasticsearch/cluster/coordination/NodeJoinExecutor.java @@ -362,9 +362,9 @@ public static void ensureIndexCompatibility(IndexVersion minSupportedVersion, In "index " + idxMetadata.getIndex() + " version not supported: " - + idxMetadata.getCompatibilityVersion() + + idxMetadata.getCompatibilityVersion().toReleaseVersion() + " maximum compatible index version is: " - + maxSupportedVersion + + maxSupportedVersion.toReleaseVersion() ); } if (idxMetadata.getCompatibilityVersion().before(minSupportedVersion)) { @@ -372,9 +372,9 @@ public static void ensureIndexCompatibility(IndexVersion minSupportedVersion, In "index " + idxMetadata.getIndex() + " version not supported: " - + idxMetadata.getCompatibilityVersion() + + idxMetadata.getCompatibilityVersion().toReleaseVersion() + " minimum compatible index version is: " - + minSupportedVersion + + minSupportedVersion.toReleaseVersion() ); } } 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 560c6815d2252..678655252248f 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java @@ -383,11 +383,11 @@ public void validate(final IndexVersion compatibilityVersion, final Map= " + SETTING_VERSION_CREATED + " [" - + createdVersion + + createdVersion.toReleaseVersion() + "]" ); } @@ -2629,7 +2629,7 @@ public static IndexMetadata legacyFromXContent(XContentParser parser) throws IOE throw new IllegalStateException( "this method should only be used to parse older incompatible index metadata versions " + "but got " - + SETTING_INDEX_VERSION_COMPATIBILITY.get(settings) + + SETTING_INDEX_VERSION_COMPATIBILITY.get(settings).toReleaseVersion() ); } builder.settings(settings); diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadataVerifier.java b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadataVerifier.java index 201d4afc0494c..641fc0e76311f 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadataVerifier.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadataVerifier.java @@ -110,9 +110,9 @@ private static void checkSupportedVersion(IndexMetadata indexMetadata, IndexVers "The index " + indexMetadata.getIndex() + " has current compatibility version [" - + indexMetadata.getCompatibilityVersion() + + indexMetadata.getCompatibilityVersion().toReleaseVersion() + "] but the minimum compatible version is [" - + minimumIndexCompatibilityVersion + + minimumIndexCompatibilityVersion.toReleaseVersion() + "]. It should be re-indexed in Elasticsearch " + (Version.CURRENT.major - 1) + ".x before upgrading to " diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/RecoverySource.java b/server/src/main/java/org/elasticsearch/cluster/routing/RecoverySource.java index bb4eef2bd422d..0d288cf331d75 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/RecoverySource.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/RecoverySource.java @@ -261,7 +261,7 @@ public Type getType() { public void addAdditionalFields(XContentBuilder builder, ToXContent.Params params) throws IOException { builder.field("repository", snapshot.getRepository()) .field("snapshot", snapshot.getSnapshotId().getName()) - .field("version", version.toString()) + .field("version", version.toReleaseVersion()) .field("index", index.getName()) .field("restoreUUID", restoreUUID); } diff --git a/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java b/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java index 291e9697def4a..e0948c688a19c 100644 --- a/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java +++ b/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java @@ -528,13 +528,13 @@ static void checkForIndexCompatibility(Logger logger, DataPath... dataPaths) thr String bestDowngradeVersion = getBestDowngradeVersion(metadata.previousNodeVersion().toString()); throw new IllegalStateException( "Cannot start this node because it holds metadata for indices with version [" - + metadata.oldestIndexVersion() + + metadata.oldestIndexVersion().toReleaseVersion() + "] with which this node of version [" + Build.current().version() + "] is incompatible. Revert this node to version [" + bestDowngradeVersion + "] and delete any indices with versions earlier than [" - + IndexVersions.MINIMUM_COMPATIBLE + + IndexVersions.MINIMUM_COMPATIBLE.toReleaseVersion() + "] before upgrading to version [" + Build.current().version() + "]. If all such indices have already been deleted, revert this node to version [" diff --git a/server/src/main/java/org/elasticsearch/index/IndexSettings.java b/server/src/main/java/org/elasticsearch/index/IndexSettings.java index 6decd20e0a41f..aa92025f32428 100644 --- a/server/src/main/java/org/elasticsearch/index/IndexSettings.java +++ b/server/src/main/java/org/elasticsearch/index/IndexSettings.java @@ -1114,16 +1114,21 @@ public synchronized boolean updateIndexMetadata(IndexMetadata indexMetadata) { final Settings newSettings = indexMetadata.getSettings(); IndexVersion newIndexVersion = SETTING_INDEX_VERSION_CREATED.get(newSettings); if (version.equals(newIndexVersion) == false) { - throw new IllegalArgumentException("version mismatch on settings update expected: " + version + " but was: " + newIndexVersion); + throw new IllegalArgumentException( + "version mismatch on settings update expected: " + + version.toReleaseVersion() + + " but was: " + + newIndexVersion.toReleaseVersion() + ); } 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: " - + compatibilityVersion + + compatibilityVersion.toReleaseVersion() + " but was: " - + newCompatibilityVersion + + newCompatibilityVersion.toReleaseVersion() ); } final String newUUID = newSettings.get(IndexMetadata.SETTING_INDEX_UUID, IndexMetadata.INDEX_UUID_NA_VALUE); diff --git a/server/src/main/java/org/elasticsearch/repositories/RepositoriesModule.java b/server/src/main/java/org/elasticsearch/repositories/RepositoriesModule.java index 902dcd6078e7f..2ac804b0597f8 100644 --- a/server/src/main/java/org/elasticsearch/repositories/RepositoriesModule.java +++ b/server/src/main/java/org/elasticsearch/repositories/RepositoriesModule.java @@ -103,9 +103,9 @@ public RepositoriesModule( throw new SnapshotRestoreException( snapshot, "the snapshot was created with Elasticsearch version [" - + version + + version.toReleaseVersion() + "] which is below the current versions minimum index compatibility version [" - + IndexVersions.MINIMUM_COMPATIBLE + + IndexVersions.MINIMUM_COMPATIBLE.toReleaseVersion() + "]" ); } diff --git a/server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java b/server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java index fb10d3e28dab2..222006b18d42f 100644 --- a/server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java +++ b/server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java @@ -2344,7 +2344,7 @@ private void cacheRepositoryData(RepositoryData repositoryData, IndexVersion ver toCache = repositoryData.withoutShardGenerations(); assert repositoryData.indexMetaDataGenerations().equals(IndexMetaDataGenerations.EMPTY) : "repository data should not contain index generations at version [" - + version + + version.toReleaseVersion() + "] but saw [" + repositoryData.indexMetaDataGenerations() + "]"; diff --git a/server/src/main/java/org/elasticsearch/snapshots/SnapshotInfo.java b/server/src/main/java/org/elasticsearch/snapshots/SnapshotInfo.java index 8a1f68c867943..1a022d08d3a24 100644 --- a/server/src/main/java/org/elasticsearch/snapshots/SnapshotInfo.java +++ b/server/src/main/java/org/elasticsearch/snapshots/SnapshotInfo.java @@ -567,7 +567,7 @@ public XContentBuilder toXContentExternal(final XContentBuilder builder, final T if (version != null) { builder.field(VERSION_ID, version.id()); - builder.field(VERSION, version.toString()); + builder.field(VERSION, version.toReleaseVersion()); } if (params.paramAsBoolean(INDEX_NAMES_XCONTENT_PARAM, true)) { diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/IndexMetadataVerifierTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/IndexMetadataVerifierTests.java index eb9e26d08ed9c..388cbc83b7c6f 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/IndexMetadataVerifierTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/IndexMetadataVerifierTests.java @@ -116,10 +116,10 @@ public void testIncompatibleVersion() { "The index [foo/" + metadata.getIndexUUID() + "] has current compatibility version [" - + indexCreated + + indexCreated.toReleaseVersion() + "] " + "but the minimum compatible version is [" - + minCompat + + minCompat.toReleaseVersion() + "]. It should be re-indexed in Elasticsearch " + (Version.CURRENT.major - 1) + ".x before upgrading to " diff --git a/server/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java b/server/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java index ce0597e7169a4..966d7f9b7fcc9 100644 --- a/server/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java +++ b/server/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java @@ -601,7 +601,7 @@ public void testIndexCompatibilityChecks() throws IOException { ex.getMessage(), allOf( containsString("Cannot start this node"), - containsString("it holds metadata for indices with version [" + oldIndexVersion + "]"), + containsString("it holds metadata for indices with version [" + oldIndexVersion.toReleaseVersion() + "]"), containsString( "Revert this node to version [" + (previousNodeVersion.major == Version.V_8_0_0.major ? Version.V_7_17_0 : previousNodeVersion) diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java index 49bdfd58eafd8..3da32c7f5a4c2 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java @@ -38,7 +38,7 @@ static DeprecationIssue oldIndicesCheck(IndexMetadata indexMetadata) { DeprecationIssue.Level.CRITICAL, "Old index with a compatibility version < 7.0", "https://www.elastic.co/guide/en/elasticsearch/reference/master/" + "breaking-changes-8.0.html", - "This index has version: " + currentCompatibilityVersion, + "This index has version: " + currentCompatibilityVersion.toReleaseVersion(), false, null ); diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java index abff1499fceb7..62f89f650dec2 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java @@ -38,7 +38,7 @@ public void testOldIndicesCheck() { DeprecationIssue.Level.CRITICAL, "Old index with a compatibility version < 7.0", "https://www.elastic.co/guide/en/elasticsearch/reference/master/" + "breaking-changes-8.0.html", - "This index has version: " + createdWith, + "This index has version: " + createdWith.toReleaseVersion(), false, null ); diff --git a/x-pack/qa/repository-old-versions/src/test/java/org/elasticsearch/oldrepos/OldRepositoryAccessIT.java b/x-pack/qa/repository-old-versions/src/test/java/org/elasticsearch/oldrepos/OldRepositoryAccessIT.java index cb3100257903b..a332bcb599e90 100644 --- a/x-pack/qa/repository-old-versions/src/test/java/org/elasticsearch/oldrepos/OldRepositoryAccessIT.java +++ b/x-pack/qa/repository-old-versions/src/test/java/org/elasticsearch/oldrepos/OldRepositoryAccessIT.java @@ -215,7 +215,7 @@ private void beforeRestart( assertEquals(numberOfShards, (int) getResp.evaluate("snapshots.0.shards.successful")); assertEquals(numberOfShards, (int) getResp.evaluate("snapshots.0.shards.total")); assertEquals(0, (int) getResp.evaluate("snapshots.0.shards.failed")); - assertEquals(indexVersion.toString(), getResp.evaluate("snapshots.0.version")); + assertEquals(indexVersion.toReleaseVersion(), getResp.evaluate("snapshots.0.version")); // list specific snapshot on new ES getSnaps = new Request("GET", "/_snapshot/" + repoName + "/" + snapshotName); @@ -229,7 +229,7 @@ private void beforeRestart( assertEquals(numberOfShards, (int) getResp.evaluate("snapshots.0.shards.successful")); assertEquals(numberOfShards, (int) getResp.evaluate("snapshots.0.shards.total")); assertEquals(0, (int) getResp.evaluate("snapshots.0.shards.failed")); - assertEquals(indexVersion.toString(), getResp.evaluate("snapshots.0.version")); + assertEquals(indexVersion.toReleaseVersion(), getResp.evaluate("snapshots.0.version")); // list advanced snapshot info on new ES getSnaps = new Request("GET", "/_snapshot/" + repoName + "/" + snapshotName + "/_status");