From d0cf105b94c00dc6721253d6dca11a7bb768b762 Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Tue, 19 May 2020 10:01:52 +0200 Subject: [PATCH 1/5] Add Restore UUID Index Setting Pre-requesite for #50278 to be able to uniquely identify index metadata by its version fields and UUIDs when restoring into closed indices. --- .../snapshots/SharedClusterSnapshotRestoreIT.java | 2 ++ .../org/elasticsearch/cluster/metadata/IndexMetadata.java | 1 + .../common/settings/IndexScopedSettings.java | 1 + .../main/java/org/elasticsearch/index/IndexSettings.java | 5 +++++ .../java/org/elasticsearch/snapshots/RestoreService.java | 8 +++++--- 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java index 08ff0fffc69a9..cf3ddafc76677 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java @@ -3689,6 +3689,7 @@ public void testRestoreIncreasesPrimaryTerms() { final IndexMetadata indexMetadata = client().admin().cluster().prepareState().clear().setIndices(indexName) .setMetadata(true).get().getState().metadata().index(indexName); + assertThat(indexMetadata.getSettings().get(IndexMetadata.SETTING_RESTORE_UUID), nullValue()); final int numPrimaries = getNumShards(indexName).numPrimaries; final Map primaryTerms = IntStream.range(0, numPrimaries) .boxed().collect(Collectors.toMap(shardId -> shardId, indexMetadata::primaryTerm)); @@ -3711,6 +3712,7 @@ public void testRestoreIncreasesPrimaryTerms() { for (int shardId = 0; shardId < numPrimaries; shardId++) { assertThat(restoredIndexMetadata.primaryTerm(shardId), greaterThan(primaryTerms.get(shardId))); } + assertThat(restoredIndexMetadata.getSettings().get(IndexMetadata.SETTING_RESTORE_UUID), notNullValue()); } public void testSnapshotDifferentIndicesBySameName() { 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 c3463920d138c..933e245abb75a 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java @@ -227,6 +227,7 @@ public Iterator> settings() { Setting.intSetting("index.priority", 1, 0, Property.Dynamic, Property.IndexScope); public static final String SETTING_CREATION_DATE_STRING = "index.creation_date_string"; public static final String SETTING_INDEX_UUID = "index.uuid"; + public static final String SETTING_RESTORE_UUID = "restore.uuid"; public static final String SETTING_DATA_PATH = "index.data_path"; public static final Setting INDEX_DATA_PATH_SETTING = new Setting<>(SETTING_DATA_PATH, "", Function.identity(), Property.IndexScope); 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 acfe41f8e9dab..e0d38bdba43c8 100644 --- a/server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java +++ b/server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java @@ -209,6 +209,7 @@ public boolean isPrivateSetting(String key) { switch (key) { case IndexMetadata.SETTING_CREATION_DATE: case IndexMetadata.SETTING_INDEX_UUID: + case IndexMetadata.SETTING_RESTORE_UUID: case IndexMetadata.SETTING_VERSION_UPGRADED: case IndexMetadata.SETTING_INDEX_PROVIDED_NAME: case MergePolicyConfig.INDEX_MERGE_ENABLED: diff --git a/server/src/main/java/org/elasticsearch/index/IndexSettings.java b/server/src/main/java/org/elasticsearch/index/IndexSettings.java index b2e22db4c7cd4..6c1767066f508 100644 --- a/server/src/main/java/org/elasticsearch/index/IndexSettings.java +++ b/server/src/main/java/org/elasticsearch/index/IndexSettings.java @@ -663,6 +663,11 @@ public synchronized boolean updateIndexMetadata(IndexMetadata indexMetadata) { if (newUUID.equals(getUUID()) == false) { throw new IllegalArgumentException("uuid mismatch on settings update expected: " + getUUID() + " but was: " + newUUID); } + final String newRestoreUUID = newSettings.get(IndexMetadata.SETTING_RESTORE_UUID, IndexMetadata.INDEX_UUID_NA_VALUE); + final String restoreUUID = this.settings.get(IndexMetadata.SETTING_RESTORE_UUID, IndexMetadata.INDEX_UUID_NA_VALUE); + if (newRestoreUUID.equals(restoreUUID) == false) { + throw new IllegalArgumentException("uuid mismatch on settings update expected: " + restoreUUID + " but was: " + newRestoreUUID); + } this.indexMetadata = indexMetadata; final Settings newIndexSettings = Settings.builder().put(nodeSettings).put(newSettings).build(); if (same(this.settings, newIndexSettings)) { diff --git a/server/src/main/java/org/elasticsearch/snapshots/RestoreService.java b/server/src/main/java/org/elasticsearch/snapshots/RestoreService.java index c567c4f110518..98473627dbc26 100644 --- a/server/src/main/java/org/elasticsearch/snapshots/RestoreService.java +++ b/server/src/main/java/org/elasticsearch/snapshots/RestoreService.java @@ -91,6 +91,7 @@ import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_INDEX_UUID; import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS; import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SHARDS; +import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_RESTORE_UUID; import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_VERSION_CREATED; import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_VERSION_UPGRADED; import static org.elasticsearch.common.util.set.Sets.newHashSet; @@ -125,7 +126,8 @@ public class RestoreService implements ClusterStateApplier { SETTING_VERSION_CREATED, SETTING_INDEX_UUID, SETTING_CREATION_DATE, - IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey())); + IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), + SETTING_RESTORE_UUID)); // It's OK to change some settings, but we shouldn't allow simply removing them private static final Set UNREMOVABLE_SETTINGS; @@ -334,8 +336,8 @@ public ClusterState execute(ClusterState currentState) { } indexMdBuilder.settings(Settings.builder() .put(snapshotIndexMetadata.getSettings()) - .put(IndexMetadata.SETTING_INDEX_UUID, - currentIndexMetadata.getIndexUUID())); + .put(IndexMetadata.SETTING_INDEX_UUID, currentIndexMetadata.getIndexUUID()) + .put(IndexMetadata.SETTING_RESTORE_UUID, UUIDs.randomBase64UUID())); IndexMetadata updatedIndexMetadata = indexMdBuilder.index(renamedIndexName).build(); rtBuilder.addAsRestore(updatedIndexMetadata, recoverySource); blocks.updateBlocks(updatedIndexMetadata); From 11ca161989e57ba33f4b6ed49b4bed812af31caf Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Tue, 19 May 2020 10:25:21 +0200 Subject: [PATCH 2/5] exclude in ccr --- .../xpack/ccr/action/TransportResumeFollowAction.java | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportResumeFollowAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportResumeFollowAction.java index 1f46faf3bb5e6..6ddb92cdc4b32 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportResumeFollowAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportResumeFollowAction.java @@ -442,6 +442,7 @@ static Settings filter(Settings originalSettings) { settings.remove(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey()); settings.remove(IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey()); settings.remove(IndexMetadata.SETTING_INDEX_UUID); + settings.remove(IndexMetadata.SETTING_RESTORE_UUID); settings.remove(IndexMetadata.SETTING_INDEX_PROVIDED_NAME); settings.remove(IndexMetadata.SETTING_CREATION_DATE); From a762432ed4409e319c0afb9bbbb538f4d48d283f Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Tue, 19 May 2020 23:25:16 +0200 Subject: [PATCH 3/5] rename + remove on resize --- .../snapshots/SharedClusterSnapshotRestoreIT.java | 4 ++-- .../action/admin/indices/shrink/TransportResizeAction.java | 6 ++++-- .../org/elasticsearch/cluster/metadata/IndexMetadata.java | 2 +- .../elasticsearch/common/settings/IndexScopedSettings.java | 2 +- .../main/java/org/elasticsearch/index/IndexSettings.java | 4 ++-- .../java/org/elasticsearch/snapshots/RestoreService.java | 6 +++--- .../xpack/ccr/action/TransportResumeFollowAction.java | 2 +- 7 files changed, 14 insertions(+), 12 deletions(-) diff --git a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java index cf3ddafc76677..f92c06fc64398 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java @@ -3689,7 +3689,7 @@ public void testRestoreIncreasesPrimaryTerms() { final IndexMetadata indexMetadata = client().admin().cluster().prepareState().clear().setIndices(indexName) .setMetadata(true).get().getState().metadata().index(indexName); - assertThat(indexMetadata.getSettings().get(IndexMetadata.SETTING_RESTORE_UUID), nullValue()); + assertThat(indexMetadata.getSettings().get(IndexMetadata.SETTING_HISTORY_UUID), nullValue()); final int numPrimaries = getNumShards(indexName).numPrimaries; final Map primaryTerms = IntStream.range(0, numPrimaries) .boxed().collect(Collectors.toMap(shardId -> shardId, indexMetadata::primaryTerm)); @@ -3712,7 +3712,7 @@ public void testRestoreIncreasesPrimaryTerms() { for (int shardId = 0; shardId < numPrimaries; shardId++) { assertThat(restoredIndexMetadata.primaryTerm(shardId), greaterThan(primaryTerms.get(shardId))); } - assertThat(restoredIndexMetadata.getSettings().get(IndexMetadata.SETTING_RESTORE_UUID), notNullValue()); + assertThat(restoredIndexMetadata.getSettings().get(IndexMetadata.SETTING_HISTORY_UUID), notNullValue()); } public void testSnapshotDifferentIndicesBySameName() { diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/shrink/TransportResizeAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/shrink/TransportResizeAction.java index 2de358478a645..fc41415795c4b 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/shrink/TransportResizeAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/shrink/TransportResizeAction.java @@ -127,8 +127,10 @@ static CreateIndexClusterStateUpdateRequest prepareCreateIndexRequest(final Resi if (metadata == null) { throw new IndexNotFoundException(sourceIndexName); } - final Settings targetIndexSettings = Settings.builder().put(targetIndex.settings()) - .normalizePrefix(IndexMetadata.INDEX_SETTING_PREFIX).build(); + final Settings.Builder targetIndexSettingsBuilder = Settings.builder().put(targetIndex.settings()) + .normalizePrefix(IndexMetadata.INDEX_SETTING_PREFIX); + targetIndexSettingsBuilder.remove(IndexMetadata.SETTING_HISTORY_UUID); + final Settings targetIndexSettings = targetIndexSettingsBuilder.build(); final int numShards; if (IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING.exists(targetIndexSettings)) { numShards = IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING.get(targetIndexSettings); 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 933e245abb75a..1b5af55bedb98 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java @@ -227,7 +227,7 @@ public Iterator> settings() { Setting.intSetting("index.priority", 1, 0, Property.Dynamic, Property.IndexScope); public static final String SETTING_CREATION_DATE_STRING = "index.creation_date_string"; public static final String SETTING_INDEX_UUID = "index.uuid"; - public static final String SETTING_RESTORE_UUID = "restore.uuid"; + public static final String SETTING_HISTORY_UUID = "index.history.uuid"; public static final String SETTING_DATA_PATH = "index.data_path"; public static final Setting INDEX_DATA_PATH_SETTING = new Setting<>(SETTING_DATA_PATH, "", Function.identity(), Property.IndexScope); 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 e0d38bdba43c8..3fee46c38781d 100644 --- a/server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java +++ b/server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java @@ -209,7 +209,7 @@ public boolean isPrivateSetting(String key) { switch (key) { case IndexMetadata.SETTING_CREATION_DATE: case IndexMetadata.SETTING_INDEX_UUID: - case IndexMetadata.SETTING_RESTORE_UUID: + case IndexMetadata.SETTING_HISTORY_UUID: case IndexMetadata.SETTING_VERSION_UPGRADED: case IndexMetadata.SETTING_INDEX_PROVIDED_NAME: case MergePolicyConfig.INDEX_MERGE_ENABLED: diff --git a/server/src/main/java/org/elasticsearch/index/IndexSettings.java b/server/src/main/java/org/elasticsearch/index/IndexSettings.java index 6c1767066f508..5d62a571052fa 100644 --- a/server/src/main/java/org/elasticsearch/index/IndexSettings.java +++ b/server/src/main/java/org/elasticsearch/index/IndexSettings.java @@ -663,8 +663,8 @@ public synchronized boolean updateIndexMetadata(IndexMetadata indexMetadata) { if (newUUID.equals(getUUID()) == false) { throw new IllegalArgumentException("uuid mismatch on settings update expected: " + getUUID() + " but was: " + newUUID); } - final String newRestoreUUID = newSettings.get(IndexMetadata.SETTING_RESTORE_UUID, IndexMetadata.INDEX_UUID_NA_VALUE); - final String restoreUUID = this.settings.get(IndexMetadata.SETTING_RESTORE_UUID, IndexMetadata.INDEX_UUID_NA_VALUE); + final String newRestoreUUID = newSettings.get(IndexMetadata.SETTING_HISTORY_UUID, IndexMetadata.INDEX_UUID_NA_VALUE); + final String restoreUUID = this.settings.get(IndexMetadata.SETTING_HISTORY_UUID, IndexMetadata.INDEX_UUID_NA_VALUE); if (newRestoreUUID.equals(restoreUUID) == false) { throw new IllegalArgumentException("uuid mismatch on settings update expected: " + restoreUUID + " but was: " + newRestoreUUID); } diff --git a/server/src/main/java/org/elasticsearch/snapshots/RestoreService.java b/server/src/main/java/org/elasticsearch/snapshots/RestoreService.java index 98473627dbc26..a3be8c33c47d4 100644 --- a/server/src/main/java/org/elasticsearch/snapshots/RestoreService.java +++ b/server/src/main/java/org/elasticsearch/snapshots/RestoreService.java @@ -91,7 +91,7 @@ import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_INDEX_UUID; import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS; import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SHARDS; -import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_RESTORE_UUID; +import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_HISTORY_UUID; import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_VERSION_CREATED; import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_VERSION_UPGRADED; import static org.elasticsearch.common.util.set.Sets.newHashSet; @@ -127,7 +127,7 @@ public class RestoreService implements ClusterStateApplier { SETTING_INDEX_UUID, SETTING_CREATION_DATE, IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), - SETTING_RESTORE_UUID)); + SETTING_HISTORY_UUID)); // It's OK to change some settings, but we shouldn't allow simply removing them private static final Set UNREMOVABLE_SETTINGS; @@ -337,7 +337,7 @@ public ClusterState execute(ClusterState currentState) { indexMdBuilder.settings(Settings.builder() .put(snapshotIndexMetadata.getSettings()) .put(IndexMetadata.SETTING_INDEX_UUID, currentIndexMetadata.getIndexUUID()) - .put(IndexMetadata.SETTING_RESTORE_UUID, UUIDs.randomBase64UUID())); + .put(IndexMetadata.SETTING_HISTORY_UUID, UUIDs.randomBase64UUID())); IndexMetadata updatedIndexMetadata = indexMdBuilder.index(renamedIndexName).build(); rtBuilder.addAsRestore(updatedIndexMetadata, recoverySource); blocks.updateBlocks(updatedIndexMetadata); diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportResumeFollowAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportResumeFollowAction.java index 6ddb92cdc4b32..d5c818f1ff64f 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportResumeFollowAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportResumeFollowAction.java @@ -442,7 +442,7 @@ static Settings filter(Settings originalSettings) { settings.remove(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey()); settings.remove(IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey()); settings.remove(IndexMetadata.SETTING_INDEX_UUID); - settings.remove(IndexMetadata.SETTING_RESTORE_UUID); + settings.remove(IndexMetadata.SETTING_HISTORY_UUID); settings.remove(IndexMetadata.SETTING_INDEX_PROVIDED_NAME); settings.remove(IndexMetadata.SETTING_CREATION_DATE); From a5519d6a6492c1ddfc78e07831f2a31b83db76e2 Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Wed, 20 May 2020 16:05:54 +0200 Subject: [PATCH 4/5] add history uuid to dangling index import --- .../elasticsearch/indices/recovery/DanglingIndicesIT.java | 4 ++++ .../elasticsearch/gateway/LocalAllocateDangledIndices.java | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/DanglingIndicesIT.java b/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/DanglingIndicesIT.java index b99b419e0c871..74af1162db049 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/DanglingIndicesIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/DanglingIndicesIT.java @@ -19,6 +19,7 @@ package org.elasticsearch.indices.recovery; +import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.test.ESIntegTestCase; @@ -31,6 +32,7 @@ import static org.elasticsearch.gateway.DanglingIndicesState.AUTO_IMPORT_DANGLING_INDICES_SETTING; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.notNullValue; @ClusterScope(numDataNodes = 0, scope = ESIntegTestCase.Scope.TEST) public class DanglingIndicesIT extends ESIntegTestCase { @@ -89,6 +91,8 @@ public Settings onNodeStopped(String nodeName) throws Exception { equalTo("42s")); } ensureGreen(INDEX_NAME); + final IndexMetadata indexMetadata = clusterService().state().metadata().index(INDEX_NAME); + assertThat(indexMetadata.getSettings().get(IndexMetadata.SETTING_HISTORY_UUID), notNullValue()); } /** diff --git a/server/src/main/java/org/elasticsearch/gateway/LocalAllocateDangledIndices.java b/server/src/main/java/org/elasticsearch/gateway/LocalAllocateDangledIndices.java index 676e22511ed85..c27807eedb554 100644 --- a/server/src/main/java/org/elasticsearch/gateway/LocalAllocateDangledIndices.java +++ b/server/src/main/java/org/elasticsearch/gateway/LocalAllocateDangledIndices.java @@ -35,9 +35,11 @@ import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.cluster.routing.allocation.AllocationService; import org.elasticsearch.cluster.service.ClusterService; +import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.discovery.MasterNotDiscoveredException; import org.elasticsearch.tasks.Task; import org.elasticsearch.threadpool.ThreadPool; @@ -142,6 +144,9 @@ public ClusterState execute(ClusterState currentState) { // with the current version and upgrade it if needed. upgradedIndexMetadata = metadataIndexUpgradeService.upgradeIndexMetadata(indexMetadata, minIndexCompatibilityVersion); + upgradedIndexMetadata = IndexMetadata.builder(upgradedIndexMetadata).settings( + Settings.builder().put(upgradedIndexMetadata.getSettings()).put( + IndexMetadata.SETTING_HISTORY_UUID, UUIDs.randomBase64UUID())).build(); } catch (Exception ex) { // upgrade failed - adding index as closed logger.warn(() -> new ParameterizedMessage("found dangled index [{}] on node [{}]. This index cannot be " + From 84922d08eec00f1ea0735f14b38f303567e053c7 Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Wed, 20 May 2020 18:09:16 +0200 Subject: [PATCH 5/5] new uuid on unsafe bootstrap as well] --- .../UnsafeBootstrapAndDetachCommandIT.java | 4 ++++ .../coordination/UnsafeBootstrapMasterCommand.java | 14 +++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/server/src/internalClusterTest/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapAndDetachCommandIT.java b/server/src/internalClusterTest/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapAndDetachCommandIT.java index 478305912395e..e15d68bec1bf0 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapAndDetachCommandIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapAndDetachCommandIT.java @@ -23,6 +23,7 @@ import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; import org.elasticsearch.cli.MockTerminal; import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; @@ -46,6 +47,7 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.notNullValue; @ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, autoManageMasterNodes = false) public class UnsafeBootstrapAndDetachCommandIT extends ESIntegTestCase { @@ -292,6 +294,8 @@ public void test3MasterNodes2Failed() throws Exception { logger.info("--> ensure index test is green"); ensureGreen("test"); + IndexMetadata indexMetadata = clusterService().state().metadata().index("test"); + assertThat(indexMetadata.getSettings().get(IndexMetadata.SETTING_HISTORY_UUID), notNullValue()); logger.info("--> detach-cluster on 2nd and 3rd master-eligible nodes"); Environment environmentMaster2 = TestEnvironment.newEnvironment( diff --git a/server/src/main/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapMasterCommand.java b/server/src/main/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapMasterCommand.java index a019f1478707e..a43dd923975b5 100644 --- a/server/src/main/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapMasterCommand.java +++ b/server/src/main/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapMasterCommand.java @@ -18,12 +18,15 @@ */ package org.elasticsearch.cluster.coordination; +import com.carrotsearch.hppc.cursors.ObjectCursor; import joptsimple.OptionSet; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.cli.Terminal; import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.service.ClusterService; +import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; @@ -106,13 +109,18 @@ protected void processNodePaths(Terminal terminal, Path[] dataPaths, OptionSet o .put(metadata.persistentSettings()) .put(UNSAFE_BOOTSTRAP.getKey(), true) .build(); - Metadata newMetadata = Metadata.builder(metadata) + Metadata.Builder newMetadata = Metadata.builder(metadata) .clusterUUID(Metadata.UNKNOWN_CLUSTER_UUID) .generateClusterUuidIfNeeded() .clusterUUIDCommitted(true) .persistentSettings(persistentSettings) - .coordinationMetadata(newCoordinationMetadata) - .build(); + .coordinationMetadata(newCoordinationMetadata); + for (ObjectCursor idx : metadata.indices().values()) { + IndexMetadata indexMetadata = idx.value; + newMetadata.put(IndexMetadata.builder(indexMetadata).settings( + Settings.builder().put(indexMetadata.getSettings()) + .put(IndexMetadata.SETTING_HISTORY_UUID, UUIDs.randomBase64UUID()))); + } final ClusterState newClusterState = ClusterState.builder(oldClusterState) .metadata(newMetadata).build();