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
This commit is contained in:
Arvind Ramachandran 2019-10-31 06:07:39 -04:00 committed by David Turner
parent 00d3151eea
commit eefa84bc94
2 changed files with 29 additions and 0 deletions

View File

@ -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;
}

View File

@ -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