From a697d5edae192185199d7bbc0c05b52439b97094 Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Wed, 28 Oct 2020 09:03:09 +0100 Subject: [PATCH] Don't Generate an Index Setting History UUID unless it's Supported (#64164) (#64213) In 7.x we can't just by default generate this setting as it might not be supported by data nodes that are assigned shards for an older version in mixed version clusters. Closes #64152 --- .../test/snapshot.restore/10_basic.yml | 4 ---- .../elasticsearch/snapshots/RestoreService.java | 15 +++++++++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/snapshot.restore/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/snapshot.restore/10_basic.yml index ad42d06fb85..4bce99d5d97 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/snapshot.restore/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/snapshot.restore/10_basic.yml @@ -24,10 +24,6 @@ setup: --- "Create a snapshot and then restore it": - - skip: - version: "all" - reason: "AwaitsFix https://github.com/elastic/elasticsearch/issues/64152" - - do: snapshot.create: repository: test_repo_restore_1 diff --git a/server/src/main/java/org/elasticsearch/snapshots/RestoreService.java b/server/src/main/java/org/elasticsearch/snapshots/RestoreService.java index f6575befbdf..c85e4c773b4 100644 --- a/server/src/main/java/org/elasticsearch/snapshots/RestoreService.java +++ b/server/src/main/java/org/elasticsearch/snapshots/RestoreService.java @@ -386,10 +386,17 @@ public class RestoreService implements ClusterStateApplier { aliases.add(alias.value); } } - indexMdBuilder.settings(Settings.builder() - .put(snapshotIndexMetadata.getSettings()) - .put(IndexMetadata.SETTING_INDEX_UUID, currentIndexMetadata.getIndexUUID()) - .put(IndexMetadata.SETTING_HISTORY_UUID, UUIDs.randomBase64UUID())); + final Settings.Builder indexSettingsBuilder = Settings.builder() + .put(snapshotIndexMetadata.getSettings()) + .put(IndexMetadata.SETTING_INDEX_UUID, currentIndexMetadata.getIndexUUID()); + // Only add a restore uuid if either all nodes in the cluster support it (version >= 7.9) or if the + // index itself was created after 7.9 and thus won't be restored to a node that doesn't support the + // setting anyway + if (snapshotIndexMetadata.getCreationVersion().onOrAfter(Version.V_7_9_0) || + currentState.nodes().getMinNodeVersion().onOrAfter(Version.V_7_9_0)) { + indexSettingsBuilder.put(SETTING_HISTORY_UUID, UUIDs.randomBase64UUID()); + } + indexMdBuilder.settings(indexSettingsBuilder); IndexMetadata updatedIndexMetadata = indexMdBuilder.index(renamedIndexName).build(); rtBuilder.addAsRestore(updatedIndexMetadata, recoverySource); blocks.updateBlocks(updatedIndexMetadata);