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