From eefa84bc94c39da9bd119a662c4882e696212281 Mon Sep 17 00:00:00 2001 From: Arvind Ramachandran Date: Thu, 31 Oct 2019 06:07:39 -0400 Subject: [PATCH] Ignore dangling indices created in newer versions (#48652) Today it is possible that we import a dangling index that was created in a newer version than one or more of the nodes in the cluster. Such an index would prevent the older node(s) from rejoining the cluster if they were to briefly leave it for some reason. This commit prevents the import of such dangling indices. Fixes #34264 --- .../gateway/LocalAllocateDangledIndices.java | 7 ++++++ .../indices/IndicesServiceTests.java | 22 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/server/src/main/java/org/elasticsearch/gateway/LocalAllocateDangledIndices.java b/server/src/main/java/org/elasticsearch/gateway/LocalAllocateDangledIndices.java index 79d83e21504..495730a8d3b 100644 --- a/server/src/main/java/org/elasticsearch/gateway/LocalAllocateDangledIndices.java +++ b/server/src/main/java/org/elasticsearch/gateway/LocalAllocateDangledIndices.java @@ -117,6 +117,13 @@ public class LocalAllocateDangledIndices { minIndexCompatibilityVersion); continue; } + if (currentState.nodes().getMinNodeVersion().before(indexMetaData.getCreationVersion())) { + logger.warn("ignoring dangled index [{}] on node [{}]" + + " since its created version [{}] is later than the oldest versioned node in the cluster [{}]", + indexMetaData.getIndex(), request.fromNode, indexMetaData.getCreationVersion(), + currentState.getNodes().getMasterNode().getVersion()); + continue; + } if (currentState.metaData().hasIndex(indexMetaData.getIndex().getName())) { continue; } diff --git a/server/src/test/java/org/elasticsearch/indices/IndicesServiceTests.java b/server/src/test/java/org/elasticsearch/indices/IndicesServiceTests.java index 40b7b327630..566479ea906 100644 --- a/server/src/test/java/org/elasticsearch/indices/IndicesServiceTests.java +++ b/server/src/test/java/org/elasticsearch/indices/IndicesServiceTests.java @@ -404,6 +404,28 @@ public class IndicesServiceTests extends ESSingleNodeTestCase { assertNotNull(clusterService.state().getMetaData().index(alias)); } + public void testDanglingIndicesWithLaterVersion() throws Exception { + final String indexNameLater = "test-idxnewer"; + final ClusterService clusterService = getInstanceFromNode(ClusterService.class); + final ClusterState originalState = clusterService.state(); + + //import an index with minor version incremented by one over cluster master version, it should be ignored + final LocalAllocateDangledIndices dangling = getInstanceFromNode(LocalAllocateDangledIndices.class); + final Settings idxSettingsLater = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, + Version.fromId(Version.CURRENT.id + 10000)) + .put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()) + .build(); + final IndexMetaData indexMetaDataLater = new IndexMetaData.Builder(indexNameLater) + .settings(idxSettingsLater) + .numberOfShards(1) + .numberOfReplicas(0) + .build(); + CountDownLatch latch = new CountDownLatch(1); + dangling.allocateDangled(Arrays.asList(indexMetaDataLater), ActionListener.wrap(latch::countDown)); + latch.await(); + assertThat(clusterService.state(), equalTo(originalState)); + } + /** * This test checks an edge case where, if a node had an index (lets call it A with UUID 1), then * deleted it (so a tombstone entry for A will exist in the cluster state), then created