Fix race in testCreateIndexWaitsForAllActiveShards
When index creation is not acknowledged (due to a very low request timeout) it is possible that the index is still created. If a subsequent index-exists request completes before the cluster state of the index creation has been fully applied, it might miss the newly created index.
This commit is contained in:
parent
fc4b439635
commit
2cf94d2d8a
|
@ -35,7 +35,6 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcke
|
|||
public class ActiveShardsObserverIT extends ESIntegTestCase {
|
||||
|
||||
public void testCreateIndexNoActiveShardsTimesOut() throws Exception {
|
||||
final String indexName = "test-idx";
|
||||
Settings.Builder settingsBuilder = Settings.builder()
|
||||
.put(indexSettings())
|
||||
.put(INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), randomIntBetween(1, 5))
|
||||
|
@ -45,7 +44,7 @@ public class ActiveShardsObserverIT extends ESIntegTestCase {
|
|||
settingsBuilder.put("index.routing.allocation.exclude._name", exclude);
|
||||
}
|
||||
Settings settings = settingsBuilder.build();
|
||||
assertFalse(prepareCreate(indexName)
|
||||
assertFalse(prepareCreate("test-idx")
|
||||
.setSettings(settings)
|
||||
.setWaitForActiveShards(randomBoolean() ? ActiveShardCount.from(1) : ActiveShardCount.ALL)
|
||||
.setTimeout("100ms")
|
||||
|
@ -54,7 +53,6 @@ public class ActiveShardsObserverIT extends ESIntegTestCase {
|
|||
}
|
||||
|
||||
public void testCreateIndexNoActiveShardsNoWaiting() throws Exception {
|
||||
final String indexName = "test-idx";
|
||||
Settings.Builder settingsBuilder = Settings.builder()
|
||||
.put(indexSettings())
|
||||
.put(INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), randomIntBetween(1, 5))
|
||||
|
@ -64,7 +62,7 @@ public class ActiveShardsObserverIT extends ESIntegTestCase {
|
|||
settingsBuilder.put("index.routing.allocation.exclude._name", exclude);
|
||||
}
|
||||
Settings settings = settingsBuilder.build();
|
||||
CreateIndexResponse response = prepareCreate(indexName)
|
||||
CreateIndexResponse response = prepareCreate("test-idx")
|
||||
.setSettings(settings)
|
||||
.setWaitForActiveShards(ActiveShardCount.from(0))
|
||||
.get();
|
||||
|
@ -72,7 +70,6 @@ public class ActiveShardsObserverIT extends ESIntegTestCase {
|
|||
}
|
||||
|
||||
public void testCreateIndexNotEnoughActiveShardsTimesOut() throws Exception {
|
||||
final String indexName = "test-idx";
|
||||
final int numDataNodes = internalCluster().numDataNodes();
|
||||
final int numReplicas = numDataNodes + randomInt(4);
|
||||
Settings settings = Settings.builder()
|
||||
|
@ -80,7 +77,7 @@ public class ActiveShardsObserverIT extends ESIntegTestCase {
|
|||
.put(INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), randomIntBetween(1, 7))
|
||||
.put(INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), numReplicas)
|
||||
.build();
|
||||
assertFalse(prepareCreate(indexName)
|
||||
assertFalse(prepareCreate("test-idx")
|
||||
.setSettings(settings)
|
||||
.setWaitForActiveShards(ActiveShardCount.from(randomIntBetween(numDataNodes + 1, numReplicas + 1)))
|
||||
.setTimeout("100ms")
|
||||
|
@ -100,7 +97,6 @@ public class ActiveShardsObserverIT extends ESIntegTestCase {
|
|||
}
|
||||
|
||||
public void testCreateIndexWaitsForAllActiveShards() throws Exception {
|
||||
final String indexName = "test-idx";
|
||||
// not enough data nodes, index creation times out
|
||||
final int numReplicas = internalCluster().numDataNodes() + randomInt(4);
|
||||
Settings settings = Settings.builder()
|
||||
|
@ -108,23 +104,20 @@ 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(indexName)
|
||||
assertFalse(prepareCreate("test-idx1")
|
||||
.setSettings(settings)
|
||||
.setWaitForActiveShards(ActiveShardCount.ALL)
|
||||
.setTimeout("100ms")
|
||||
.get()
|
||||
.isShardsAcked());
|
||||
if (client().admin().indices().prepareExists(indexName).get().isExists()) {
|
||||
assertAcked(client().admin().indices().prepareDelete(indexName));
|
||||
}
|
||||
|
||||
// enough data nodes, all shards are active
|
||||
settings = Settings.builder()
|
||||
settings = Settings.builder()
|
||||
.put(indexSettings())
|
||||
.put(INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), randomIntBetween(1, 7))
|
||||
.put(INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), internalCluster().numDataNodes() - 1)
|
||||
.build();
|
||||
assertAcked(prepareCreate(indexName).setSettings(settings).setWaitForActiveShards(ActiveShardCount.ALL).get());
|
||||
assertAcked(prepareCreate("test-idx2").setSettings(settings).setWaitForActiveShards(ActiveShardCount.ALL).get());
|
||||
}
|
||||
|
||||
public void testCreateIndexStopsWaitingWhenIndexDeleted() throws Exception {
|
||||
|
|
Loading…
Reference in New Issue