|
52 | 52 | import static org.hamcrest.Matchers.containsString;
|
53 | 53 | import static org.hamcrest.Matchers.empty;
|
54 | 54 | import static org.hamcrest.Matchers.equalTo;
|
| 55 | +import static org.hamcrest.Matchers.hasItems; |
55 | 56 | import static org.hamcrest.Matchers.is;
|
| 57 | +import static org.hamcrest.Matchers.not; |
56 | 58 | import static org.hamcrest.Matchers.nullValue;
|
57 | 59 |
|
58 | 60 | @ESIntegTestCase.ClusterScope(transportClientRatio = 0)
|
@@ -546,22 +548,64 @@ public void testSnapshotDSDuringRollover() throws Exception {
|
546 | 548 | unblockAllDataNodes(repoName);
|
547 | 549 | final SnapshotInfo snapshotInfo = assertSuccessful(snapshotFuture);
|
548 | 550 |
|
549 |
| - if (snapshotInfo.dataStreams().contains("ds")) { |
550 |
| - assertAcked(client().execute(DeleteDataStreamAction.INSTANCE, new DeleteDataStreamAction.Request(new String[] { "ds" })).get()); |
| 551 | + assertThat(snapshotInfo.dataStreams(), hasItems("ds")); |
| 552 | + assertAcked(client().execute(DeleteDataStreamAction.INSTANCE, new DeleteDataStreamAction.Request(new String[] { "ds" })).get()); |
551 | 553 |
|
552 |
| - RestoreInfo restoreSnapshotResponse = client().admin() |
553 |
| - .cluster() |
554 |
| - .prepareRestoreSnapshot(repoName, snapshotName) |
555 |
| - .setWaitForCompletion(true) |
556 |
| - .setIndices("ds") |
557 |
| - .get() |
558 |
| - .getRestoreInfo(); |
| 554 | + RestoreInfo restoreSnapshotResponse = client().admin() |
| 555 | + .cluster() |
| 556 | + .prepareRestoreSnapshot(repoName, snapshotName) |
| 557 | + .setWaitForCompletion(true) |
| 558 | + .setIndices("ds") |
| 559 | + .get() |
| 560 | + .getRestoreInfo(); |
559 | 561 |
|
560 |
| - assertEquals(restoreSnapshotResponse.successfulShards(), restoreSnapshotResponse.totalShards()); |
561 |
| - assertEquals(restoreSnapshotResponse.failedShards(), 0); |
562 |
| - assertFalse(partial); |
563 |
| - } else { |
564 |
| - assertTrue(partial); |
565 |
| - } |
| 562 | + assertEquals(restoreSnapshotResponse.successfulShards(), restoreSnapshotResponse.totalShards()); |
| 563 | + assertEquals(restoreSnapshotResponse.failedShards(), 0); |
| 564 | + } |
| 565 | + |
| 566 | + public void testSnapshotDSDuringRolloverAndDeleteOldIndex() throws Exception { |
| 567 | + // repository consistency check requires at least one snapshot per registered repository |
| 568 | + createFullSnapshot(REPO, "snap-so-repo-checks-pass"); |
| 569 | + final String repoName = "mock-repo"; |
| 570 | + createRepository(repoName, "mock"); |
| 571 | + blockAllDataNodes(repoName); |
| 572 | + final String snapshotName = "ds-snap"; |
| 573 | + final ActionFuture<CreateSnapshotResponse> snapshotFuture = client().admin() |
| 574 | + .cluster() |
| 575 | + .prepareCreateSnapshot(repoName, snapshotName) |
| 576 | + .setWaitForCompletion(true) |
| 577 | + .setPartial(true) |
| 578 | + .setIncludeGlobalState(randomBoolean()) |
| 579 | + .execute(); |
| 580 | + waitForBlockOnAnyDataNode(repoName); |
| 581 | + awaitNumberOfSnapshotsInProgress(1); |
| 582 | + final RolloverResponse rolloverResponse = client().admin().indices().rolloverIndex(new RolloverRequest("ds", null)).get(); |
| 583 | + assertTrue(rolloverResponse.isRolledOver()); |
| 584 | + |
| 585 | + logger.info("--> deleting former write index"); |
| 586 | + assertAcked(client().admin().indices().prepareDelete(rolloverResponse.getOldIndex())); |
| 587 | + |
| 588 | + unblockAllDataNodes(repoName); |
| 589 | + final SnapshotInfo snapshotInfo = assertSuccessful(snapshotFuture); |
| 590 | + |
| 591 | + assertThat( |
| 592 | + "snapshot should not contain 'ds' since none of its indices existed both at the start and at the end of the snapshot", |
| 593 | + snapshotInfo.dataStreams(), |
| 594 | + not(hasItems("ds")) |
| 595 | + ); |
| 596 | + assertAcked( |
| 597 | + client().execute(DeleteDataStreamAction.INSTANCE, new DeleteDataStreamAction.Request(new String[] { "other-ds" })).get() |
| 598 | + ); |
| 599 | + |
| 600 | + RestoreInfo restoreSnapshotResponse = client().admin() |
| 601 | + .cluster() |
| 602 | + .prepareRestoreSnapshot(repoName, snapshotName) |
| 603 | + .setWaitForCompletion(true) |
| 604 | + .setIndices("other-ds") |
| 605 | + .get() |
| 606 | + .getRestoreInfo(); |
| 607 | + |
| 608 | + assertEquals(restoreSnapshotResponse.successfulShards(), restoreSnapshotResponse.totalShards()); |
| 609 | + assertEquals(restoreSnapshotResponse.failedShards(), 0); |
566 | 610 | }
|
567 | 611 | }
|
0 commit comments