|
34 | 34 | import org.elasticsearch.index.IndexNotFoundException; |
35 | 35 | import org.elasticsearch.index.IndexSettings; |
36 | 36 | import org.elasticsearch.indices.IndexClosedException; |
| 37 | +import org.elasticsearch.indices.recovery.RecoveryState; |
37 | 38 | import org.elasticsearch.test.BackgroundIndexer; |
38 | 39 | import org.elasticsearch.test.ESIntegTestCase; |
39 | 40 |
|
|
50 | 51 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; |
51 | 52 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; |
52 | 53 | import static org.hamcrest.Matchers.containsString; |
| 54 | +import static org.hamcrest.Matchers.empty; |
53 | 55 | import static org.hamcrest.Matchers.equalTo; |
54 | 56 | import static org.hamcrest.Matchers.hasSize; |
55 | 57 | import static org.hamcrest.Matchers.is; |
@@ -338,6 +340,33 @@ public void testCloseIndexWaitForActiveShards() throws Exception { |
338 | 340 | assertIndexIsClosed(indexName); |
339 | 341 | } |
340 | 342 |
|
| 343 | + public void testNoopPeerRecoveriesWhenIndexClosed() throws Exception { |
| 344 | + final String indexName = "peer-recovery-test"; |
| 345 | + int numberOfReplicas = between(1, 2); |
| 346 | + internalCluster().ensureAtLeastNumDataNodes(numberOfReplicas + between(1, 2)); |
| 347 | + createIndex(indexName, Settings.builder() |
| 348 | + .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) |
| 349 | + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, numberOfReplicas) |
| 350 | + .put("index.routing.rebalance.enable", "none") |
| 351 | + .build()); |
| 352 | + indexRandom(randomBoolean(), false, randomBoolean(), IntStream.range(0, randomIntBetween(0, 50)) |
| 353 | + .mapToObj(i -> client().prepareIndex(indexName, "_doc").setSource("num", i)).collect(toList())); |
| 354 | + ensureGreen(indexName); |
| 355 | + |
| 356 | + // Closing an index should execute noop peer recovery |
| 357 | + assertAcked(client().admin().indices().prepareClose(indexName).get()); |
| 358 | + assertIndexIsClosed(indexName); |
| 359 | + ensureGreen(indexName); |
| 360 | + assertNoFileBasedRecovery(indexName); |
| 361 | + |
| 362 | + // Open a closed index should execute noop recovery |
| 363 | + assertAcked(client().admin().indices().prepareOpen(indexName).get()); |
| 364 | + assertIndexIsOpened(indexName); |
| 365 | + ensureGreen(indexName); |
| 366 | + assertNoFileBasedRecovery(indexName); |
| 367 | + internalCluster().assertSameDocIdsOnShards(); |
| 368 | + } |
| 369 | + |
341 | 370 | static void assertIndexIsClosed(final String... indices) { |
342 | 371 | final ClusterState clusterState = client().admin().cluster().prepareState().get().getState(); |
343 | 372 | for (String index : indices) { |
@@ -383,4 +412,12 @@ static void assertException(final Throwable throwable, final String indexName) { |
383 | 412 | fail("Unexpected exception: " + t); |
384 | 413 | } |
385 | 414 | } |
| 415 | + |
| 416 | + void assertNoFileBasedRecovery(String indexName) { |
| 417 | + for (RecoveryState recovery : client().admin().indices().prepareRecoveries(indexName).get().shardRecoveryStates().get(indexName)) { |
| 418 | + if (recovery.getPrimary() == false) { |
| 419 | + assertThat(recovery.getIndex().fileDetails(), empty()); |
| 420 | + } |
| 421 | + } |
| 422 | + } |
386 | 423 | } |
0 commit comments