use of org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse in project OpenSearch by opensearch-project.
the class SharedClusterSnapshotRestoreIT method testRestoreSnapshotWithCorruptedGlobalState.
/**
* Tests that a snapshot with a corrupted global state file can still be restored
*/
public void testRestoreSnapshotWithCorruptedGlobalState() throws Exception {
final Path repo = randomRepoPath();
final String repoName = "test-repo";
createRepository(repoName, "fs", repo);
createIndex("test-idx-1", "test-idx-2");
indexRandom(true, client().prepareIndex("test-idx-1").setSource("foo", "bar"), client().prepareIndex("test-idx-2").setSource("foo", "bar"), client().prepareIndex("test-idx-2").setSource("foo", "bar"));
flushAndRefresh("test-idx-1", "test-idx-2");
final String snapshotName = "test-snap";
final SnapshotInfo snapshotInfo = createFullSnapshot(repoName, snapshotName);
final Path globalStatePath = repo.resolve("meta-" + snapshotInfo.snapshotId().getUUID() + ".dat");
try (SeekableByteChannel outChan = Files.newByteChannel(globalStatePath, StandardOpenOption.WRITE)) {
outChan.truncate(randomInt(10));
}
List<SnapshotInfo> snapshotInfos = clusterAdmin().prepareGetSnapshots(repoName).get().getSnapshots();
assertThat(snapshotInfos.size(), equalTo(1));
assertThat(snapshotInfos.get(0).state(), equalTo(SnapshotState.SUCCESS));
assertThat(snapshotInfos.get(0).snapshotId().getName(), equalTo(snapshotName));
SnapshotsStatusResponse snapshotStatusResponse = clusterAdmin().prepareSnapshotStatus(repoName).setSnapshots(snapshotName).get();
assertThat(snapshotStatusResponse.getSnapshots(), hasSize(1));
assertThat(snapshotStatusResponse.getSnapshots().get(0).getSnapshot().getSnapshotId().getName(), equalTo(snapshotName));
assertAcked(client().admin().indices().prepareDelete("test-idx-1", "test-idx-2"));
SnapshotException ex = expectThrows(SnapshotException.class, () -> clusterAdmin().prepareRestoreSnapshot(repoName, snapshotName).setRestoreGlobalState(true).setWaitForCompletion(true).get());
assertThat(ex.getRepositoryName(), equalTo(repoName));
assertThat(ex.getSnapshotName(), equalTo(snapshotName));
assertThat(ex.getMessage(), containsString("failed to read global metadata"));
RestoreSnapshotResponse restoreSnapshotResponse = clusterAdmin().prepareRestoreSnapshot(repoName, snapshotName).setWaitForCompletion(true).get();
assertThat(restoreSnapshotResponse.getRestoreInfo().failedShards(), equalTo(0));
assertThat(restoreSnapshotResponse.getRestoreInfo().successfulShards(), equalTo(snapshotInfo.successfulShards()));
ensureGreen("test-idx-1", "test-idx-2");
assertHitCount(client().prepareSearch("test-idx-*").setSize(0).get(), 3);
}
use of org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse in project OpenSearch by opensearch-project.
the class ConcurrentSnapshotsIT method assertSnapshotStatusCountOnRepo.
private static void assertSnapshotStatusCountOnRepo(String otherBlockedRepoName, int count) {
final SnapshotsStatusResponse snapshotsStatusResponse = client().admin().cluster().prepareSnapshotStatus(otherBlockedRepoName).get();
final List<SnapshotStatus> snapshotStatuses = snapshotsStatusResponse.getSnapshots();
assertThat(snapshotStatuses, hasSize(count));
}
use of org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse in project OpenSearch by opensearch-project.
the class CorruptedBlobStoreRepositoryIT method testDeleteSnapshotWithCorruptedGlobalState.
/**
* Tests that a snapshot with a corrupted global state file can still be deleted
*/
public void testDeleteSnapshotWithCorruptedGlobalState() throws Exception {
final Path repo = randomRepoPath();
createRepository("test-repo", "fs", Settings.builder().put("location", repo).put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES));
createIndex("test-idx-1", "test-idx-2");
indexRandom(true, client().prepareIndex("test-idx-1").setSource("foo", "bar"), client().prepareIndex("test-idx-2").setSource("foo", "bar"), client().prepareIndex("test-idx-2").setSource("foo", "bar"));
flushAndRefresh("test-idx-1", "test-idx-2");
SnapshotInfo snapshotInfo = createFullSnapshot("test-repo", "test-snap");
final Path globalStatePath = repo.resolve("meta-" + snapshotInfo.snapshotId().getUUID() + ".dat");
if (randomBoolean()) {
// Delete the global state metadata file
IOUtils.deleteFilesIgnoringExceptions(globalStatePath);
} else {
// Truncate the global state metadata file
try (SeekableByteChannel outChan = Files.newByteChannel(globalStatePath, StandardOpenOption.WRITE)) {
outChan.truncate(randomInt(10));
}
}
List<SnapshotInfo> snapshotInfos = clusterAdmin().prepareGetSnapshots("test-repo").get().getSnapshots();
assertThat(snapshotInfos.size(), equalTo(1));
assertThat(snapshotInfos.get(0).state(), equalTo(SnapshotState.SUCCESS));
assertThat(snapshotInfos.get(0).snapshotId().getName(), equalTo("test-snap"));
SnapshotsStatusResponse snapshotStatusResponse = clusterAdmin().prepareSnapshotStatus("test-repo").setSnapshots("test-snap").get();
assertThat(snapshotStatusResponse.getSnapshots(), hasSize(1));
assertThat(snapshotStatusResponse.getSnapshots().get(0).getSnapshot().getSnapshotId().getName(), equalTo("test-snap"));
assertAcked(startDeleteSnapshot("test-repo", "test-snap").get());
expectThrows(SnapshotMissingException.class, () -> clusterAdmin().prepareGetSnapshots("test-repo").addSnapshots("test-snap").get());
assertRequestBuilderThrows(clusterAdmin().prepareSnapshotStatus("test-repo").addSnapshots("test-snap"), SnapshotMissingException.class);
createFullSnapshot("test-repo", "test-snap");
}
use of org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse in project OpenSearch by opensearch-project.
the class SnapshotClientDocumentationIT method testSnapshotSnapshotsStatus.
public void testSnapshotSnapshotsStatus() throws IOException {
RestHighLevelClient client = highLevelClient();
createTestRepositories();
createTestIndex();
createTestSnapshots();
// tag::snapshots-status-request
SnapshotsStatusRequest request = new SnapshotsStatusRequest();
// end::snapshots-status-request
// tag::snapshots-status-request-repository
// <1>
request.repository(repositoryName);
// end::snapshots-status-request-repository
// tag::snapshots-status-request-snapshots
String[] snapshots = new String[] { snapshotName };
// <1>
request.snapshots(snapshots);
// end::snapshots-status-request-snapshots
// tag::snapshots-status-request-ignoreUnavailable
// <1>
request.ignoreUnavailable(true);
// end::snapshots-status-request-ignoreUnavailable
// tag::snapshots-status-request-masterTimeout
// <1>
request.masterNodeTimeout(TimeValue.timeValueMinutes(1));
// <2>
request.masterNodeTimeout("1m");
// end::snapshots-status-request-masterTimeout
// tag::snapshots-status-execute
SnapshotsStatusResponse response = client.snapshot().status(request, RequestOptions.DEFAULT);
// end::snapshots-status-execute
// tag::snapshots-status-response
List<SnapshotStatus> snapshotStatusesResponse = response.getSnapshots();
// <1>
SnapshotStatus snapshotStatus = snapshotStatusesResponse.get(0);
// <2>
SnapshotsInProgress.State snapshotState = snapshotStatus.getState();
// <3>
SnapshotStats shardStats = snapshotStatus.getIndices().get(indexName).getShards().get(0).getStats();
// end::snapshots-status-response
assertThat(snapshotStatusesResponse.size(), equalTo(1));
assertThat(snapshotStatusesResponse.get(0).getSnapshot().getRepository(), equalTo(SnapshotClientDocumentationIT.repositoryName));
assertThat(snapshotStatusesResponse.get(0).getSnapshot().getSnapshotId().getName(), equalTo(snapshotName));
assertThat(snapshotState.completed(), equalTo(true));
}
use of org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse in project OpenSearch by opensearch-project.
the class SnapshotIT method testSnapshotsStatus.
public void testSnapshotsStatus() throws IOException {
String testRepository = "test";
String testSnapshot = "snapshot";
String testIndex = "test_index";
AcknowledgedResponse putRepositoryResponse = createTestRepository(testRepository, FsRepository.TYPE, "{\"location\": \".\"}");
assertTrue(putRepositoryResponse.isAcknowledged());
createIndex(testIndex, Settings.EMPTY);
CreateSnapshotRequest createSnapshotRequest = new CreateSnapshotRequest(testRepository, testSnapshot);
createSnapshotRequest.indices(testIndex);
createSnapshotRequest.waitForCompletion(true);
CreateSnapshotResponse createSnapshotResponse = createTestSnapshot(createSnapshotRequest);
// check that the request went ok without parsing JSON here. When using the high level client, check acknowledgement instead.
assertEquals(RestStatus.OK, createSnapshotResponse.status());
SnapshotsStatusRequest request = new SnapshotsStatusRequest();
request.repository(testRepository);
request.snapshots(new String[] { testSnapshot });
SnapshotsStatusResponse response = execute(request, highLevelClient().snapshot()::status, highLevelClient().snapshot()::statusAsync);
assertThat(response.getSnapshots().size(), equalTo(1));
assertThat(response.getSnapshots().get(0).getSnapshot().getRepository(), equalTo(testRepository));
assertThat(response.getSnapshots().get(0).getSnapshot().getSnapshotId().getName(), equalTo(testSnapshot));
assertThat(response.getSnapshots().get(0).getIndices().containsKey(testIndex), is(true));
}
Aggregations