Fixes the ActiveShardsObserverIT tests that have a very short index (#19540)
creation timeout so they process the index creation cluster state update before the test finishes and attempts to cleanup. Otherwise, the index creation cluster state update could be processed after the test finishes and cleans up, thereby leaking an index in the cluster state that could cause issues for other tests that wouldn't expect the index to exist. Closes #19530
This commit is contained in:
parent
4d89aa97e9
commit
9765b4a6ff
|
@ -21,6 +21,7 @@ package org.elasticsearch.action.support;
|
|||
|
||||
import org.elasticsearch.action.ListenableActionFuture;
|
||||
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
|
||||
import org.elasticsearch.common.Priority;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
|
||||
|
@ -44,12 +45,14 @@ public class ActiveShardsObserverIT extends ESIntegTestCase {
|
|||
settingsBuilder.put("index.routing.allocation.exclude._name", exclude);
|
||||
}
|
||||
Settings settings = settingsBuilder.build();
|
||||
assertFalse(prepareCreate("test-idx")
|
||||
final String indexName = "test-idx";
|
||||
assertFalse(prepareCreate(indexName)
|
||||
.setSettings(settings)
|
||||
.setWaitForActiveShards(randomBoolean() ? ActiveShardCount.from(1) : ActiveShardCount.ALL)
|
||||
.setTimeout("100ms")
|
||||
.get()
|
||||
.isShardsAcked());
|
||||
waitForIndexCreationToComplete(indexName);
|
||||
}
|
||||
|
||||
public void testCreateIndexNoActiveShardsNoWaiting() throws Exception {
|
||||
|
@ -74,22 +77,24 @@ public class ActiveShardsObserverIT extends ESIntegTestCase {
|
|||
final int numReplicas = numDataNodes + randomInt(4);
|
||||
Settings settings = Settings.builder()
|
||||
.put(indexSettings())
|
||||
.put(INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), randomIntBetween(1, 7))
|
||||
.put(INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), randomIntBetween(1, 5))
|
||||
.put(INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), numReplicas)
|
||||
.build();
|
||||
assertFalse(prepareCreate("test-idx")
|
||||
final String indexName = "test-idx";
|
||||
assertFalse(prepareCreate(indexName)
|
||||
.setSettings(settings)
|
||||
.setWaitForActiveShards(ActiveShardCount.from(randomIntBetween(numDataNodes + 1, numReplicas + 1)))
|
||||
.setTimeout("100ms")
|
||||
.get()
|
||||
.isShardsAcked());
|
||||
waitForIndexCreationToComplete(indexName);
|
||||
}
|
||||
|
||||
public void testCreateIndexEnoughActiveShards() throws Exception {
|
||||
final String indexName = "test-idx";
|
||||
Settings settings = Settings.builder()
|
||||
.put(indexSettings())
|
||||
.put(INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), randomIntBetween(1, 7))
|
||||
.put(INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), randomIntBetween(1, 5))
|
||||
.put(INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), internalCluster().numDataNodes() + randomIntBetween(0, 3))
|
||||
.build();
|
||||
ActiveShardCount waitForActiveShards = ActiveShardCount.from(randomIntBetween(0, internalCluster().numDataNodes()));
|
||||
|
@ -104,12 +109,17 @@ public class ActiveShardsObserverIT extends ESIntegTestCase {
|
|||
.put(INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), randomIntBetween(1, 5))
|
||||
.put(INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), numReplicas)
|
||||
.build();
|
||||
assertFalse(prepareCreate("test-idx1")
|
||||
final String indexName = "test-idx";
|
||||
assertFalse(prepareCreate(indexName)
|
||||
.setSettings(settings)
|
||||
.setWaitForActiveShards(ActiveShardCount.ALL)
|
||||
.setTimeout("100ms")
|
||||
.get()
|
||||
.isShardsAcked());
|
||||
waitForIndexCreationToComplete(indexName);
|
||||
if (client().admin().indices().prepareExists(indexName).get().isExists()) {
|
||||
client().admin().indices().prepareDelete(indexName).get();
|
||||
}
|
||||
|
||||
// enough data nodes, all shards are active
|
||||
settings = Settings.builder()
|
||||
|
@ -117,7 +127,7 @@ public class ActiveShardsObserverIT extends ESIntegTestCase {
|
|||
.put(INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), randomIntBetween(1, 7))
|
||||
.put(INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), internalCluster().numDataNodes() - 1)
|
||||
.build();
|
||||
assertAcked(prepareCreate("test-idx2").setSettings(settings).setWaitForActiveShards(ActiveShardCount.ALL).get());
|
||||
assertAcked(prepareCreate(indexName).setSettings(settings).setWaitForActiveShards(ActiveShardCount.ALL).get());
|
||||
}
|
||||
|
||||
public void testCreateIndexStopsWaitingWhenIndexDeleted() throws Exception {
|
||||
|
@ -145,4 +155,12 @@ public class ActiveShardsObserverIT extends ESIntegTestCase {
|
|||
assertAcked(responseListener.get());
|
||||
}
|
||||
|
||||
// Its possible that the cluster state update task that includes the create index hasn't processed before we timeout,
|
||||
// and subsequently the test cleanup process does not delete the index in question because it does not see it, and
|
||||
// only after the test cleanup does the index creation manifest in the cluster state. To take care of this problem
|
||||
// and its potential ramifications, we wait here for the index creation cluster state update task to finish
|
||||
private void waitForIndexCreationToComplete(final String indexName) {
|
||||
client().admin().cluster().prepareHealth(indexName).setWaitForEvents(Priority.URGENT).get();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue