From 9feddc1b18e853529073cc3a4cfc516872014d21 Mon Sep 17 00:00:00 2001 From: Nick Knize Date: Tue, 11 Oct 2022 12:34:40 -0500 Subject: [PATCH] [Deprecate] RepositoryData.MIN_VERSION for removal in next major release (#4729) This field is only used for old snapshot generations and needs to be removed in the next major version. This commit sets up the removal for backwards compatibility support. Signed-off-by: Nicholas Walter Knize --- CHANGELOG.md | 1 + .../repositories/RepositoryData.java | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 790fc01b19075..224f0c0084329 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -78,6 +78,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Deprecated ### Removed +- Remove RepositoryData.MIN_VERSION support for next major release ([4729](https://github.com/opensearch-project/OpenSearch/pull/4729)) ### Fixed - PR reference to checkout code for changelog verifier ([#4296](https://github.com/opensearch-project/OpenSearch/pull/4296)) diff --git a/server/src/main/java/org/opensearch/repositories/RepositoryData.java b/server/src/main/java/org/opensearch/repositories/RepositoryData.java index e8132801e4238..55a1ca0e97a63 100644 --- a/server/src/main/java/org/opensearch/repositories/RepositoryData.java +++ b/server/src/main/java/org/opensearch/repositories/RepositoryData.java @@ -600,9 +600,11 @@ public XContentBuilder snapshotsToXContent(final XContentBuilder builder, final } builder.endObject(); if (shouldWriteIndexGens) { - builder.field(MIN_VERSION, SnapshotsService.INDEX_GEN_IN_REPO_DATA_VERSION.toString()); + if (repoMetaVersion.before(Version.V_2_4_0)) { + builder.field(MIN_VERSION, SnapshotsService.INDEX_GEN_IN_REPO_DATA_VERSION.toString()); + } builder.field(INDEX_METADATA_IDENTIFIERS, indexMetaDataGenerations.identifiers); - } else if (shouldWriteShardGens) { + } else if (shouldWriteShardGens && repoMetaVersion.before(Version.V_2_4_0)) { // Add min version field to make it impossible for older OpenSearch versions to deserialize this object builder.field(MIN_VERSION, SnapshotsService.SHARD_GEN_IN_REPO_DATA_VERSION.toString()); } @@ -645,10 +647,14 @@ public static RepositoryData snapshotsFromXContent(XContentParser parser, long g XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser); indexMetaIdentifiers = parser.mapStrings(); break; - case MIN_VERSION: - XContentParserUtils.ensureExpectedToken(XContentParser.Token.VALUE_STRING, parser.nextToken(), parser); - final Version version = Version.fromString(parser.text()); - assert SnapshotsService.useShardGenerations(version); + case MIN_VERSION: // todo: remove in 3.0 + if (Version.CURRENT.major < 3) { + XContentParserUtils.ensureExpectedToken(XContentParser.Token.VALUE_STRING, parser.nextToken(), parser); + final Version version = Version.fromString(parser.text()); + assert SnapshotsService.useShardGenerations(version); + } else { + throw new OpenSearchParseException("Field [{}] was removed in version 2.4.0 and no longer supported.", MIN_VERSION); + } break; default: XContentParserUtils.throwUnknownField(field, parser.getTokenLocation());