use of org.opensearch.snapshots.SnapshotShardFailure in project OpenSearch by opensearch-project.
the class CreateSnapshotResponseTests method createTestInstance.
@Override
protected CreateSnapshotResponse createTestInstance() {
SnapshotId snapshotId = new SnapshotId("test", UUID.randomUUID().toString());
List<String> indices = new ArrayList<>();
indices.add("test0");
indices.add("test1");
List<String> dataStreams = new ArrayList<>();
dataStreams.add("test0");
dataStreams.add("test1");
String reason = "reason";
long startTime = System.currentTimeMillis();
long endTime = startTime + 10000;
int totalShards = randomIntBetween(1, 3);
int successfulShards = randomIntBetween(0, totalShards);
List<SnapshotShardFailure> shardFailures = new ArrayList<>();
for (int count = successfulShards; count < totalShards; ++count) {
shardFailures.add(new SnapshotShardFailure("node-id", new ShardId("index-" + count, UUID.randomUUID().toString(), randomInt()), "reason"));
}
boolean globalState = randomBoolean();
return new CreateSnapshotResponse(new SnapshotInfo(snapshotId, indices, dataStreams, startTime, reason, endTime, totalShards, shardFailures, globalState, SnapshotInfoTests.randomUserMetadata()));
}
use of org.opensearch.snapshots.SnapshotShardFailure in project OpenSearch by opensearch-project.
the class GetSnapshotsResponseTests method createTestInstance.
@Override
protected GetSnapshotsResponse createTestInstance() {
ArrayList<SnapshotInfo> snapshots = new ArrayList<>();
for (int i = 0; i < randomIntBetween(5, 10); ++i) {
SnapshotId snapshotId = new SnapshotId("snapshot " + i, UUIDs.base64UUID());
String reason = randomBoolean() ? null : "reason";
ShardId shardId = new ShardId("index", UUIDs.base64UUID(), 2);
List<SnapshotShardFailure> shardFailures = Collections.singletonList(new SnapshotShardFailure("node-id", shardId, "reason"));
snapshots.add(new SnapshotInfo(snapshotId, Arrays.asList("index1", "index2"), Collections.singletonList("ds"), System.currentTimeMillis(), reason, System.currentTimeMillis(), randomIntBetween(2, 3), shardFailures, randomBoolean(), SnapshotInfoTests.randomUserMetadata()));
}
return new GetSnapshotsResponse(snapshots);
}
use of org.opensearch.snapshots.SnapshotShardFailure in project OpenSearch by opensearch-project.
the class TransportSnapshotsStatusAction method snapshotShards.
/**
* Returns status of shards currently finished snapshots
* <p>
* This method is executed on cluster-manager node and it's complimentary to the
* {@link SnapshotShardsService#currentSnapshotShards(Snapshot)} because it
* returns similar information but for already finished snapshots.
* </p>
*
* @param repositoryName repository name
* @param snapshotInfo snapshot info
* @return map of shard id to snapshot status
*/
private Map<ShardId, IndexShardSnapshotStatus> snapshotShards(final String repositoryName, final RepositoryData repositoryData, final SnapshotInfo snapshotInfo) throws IOException {
final Repository repository = repositoriesService.repository(repositoryName);
final Map<ShardId, IndexShardSnapshotStatus> shardStatus = new HashMap<>();
for (String index : snapshotInfo.indices()) {
IndexId indexId = repositoryData.resolveIndexId(index);
IndexMetadata indexMetadata = repository.getSnapshotIndexMetaData(repositoryData, snapshotInfo.snapshotId(), indexId);
if (indexMetadata != null) {
int numberOfShards = indexMetadata.getNumberOfShards();
for (int i = 0; i < numberOfShards; i++) {
ShardId shardId = new ShardId(indexMetadata.getIndex(), i);
SnapshotShardFailure shardFailure = findShardFailure(snapshotInfo.shardFailures(), shardId);
if (shardFailure != null) {
shardStatus.put(shardId, IndexShardSnapshotStatus.newFailed(shardFailure.reason()));
} else {
final IndexShardSnapshotStatus shardSnapshotStatus;
if (snapshotInfo.state() == SnapshotState.FAILED) {
// If the snapshot failed, but the shard's snapshot does
// not have an exception, it means that partial snapshots
// were disabled and in this case, the shard snapshot will
// *not* have any metadata, so attempting to read the shard
// snapshot status will throw an exception. Instead, we create
// a status for the shard to indicate that the shard snapshot
// could not be taken due to partial being set to false.
shardSnapshotStatus = IndexShardSnapshotStatus.newFailed("skipped");
} else {
shardSnapshotStatus = repository.getShardSnapshotStatus(snapshotInfo.snapshotId(), indexId, shardId);
}
shardStatus.put(shardId, shardSnapshotStatus);
}
}
}
}
return unmodifiableMap(shardStatus);
}
use of org.opensearch.snapshots.SnapshotShardFailure in project OpenSearch by opensearch-project.
the class SnapshotClientDocumentationIT method testSnapshotGetSnapshots.
@SuppressWarnings("unused")
public void testSnapshotGetSnapshots() throws IOException {
RestHighLevelClient client = highLevelClient();
createTestRepositories();
createTestIndex();
createTestSnapshots();
// tag::get-snapshots-request
GetSnapshotsRequest request = new GetSnapshotsRequest();
// end::get-snapshots-request
// tag::get-snapshots-request-repositoryName
// <1>
request.repository(repositoryName);
// end::get-snapshots-request-repositoryName
// tag::get-snapshots-request-snapshots
String[] snapshots = { snapshotName };
// <1>
request.snapshots(snapshots);
// end::get-snapshots-request-snapshots
// tag::get-snapshots-request-masterTimeout
// <1>
request.masterNodeTimeout(TimeValue.timeValueMinutes(1));
// <2>
request.masterNodeTimeout("1m");
// end::get-snapshots-request-masterTimeout
// tag::get-snapshots-request-verbose
// <1>
request.verbose(true);
// end::get-snapshots-request-verbose
// tag::get-snapshots-request-ignore-unavailable
// <1>
request.ignoreUnavailable(false);
// end::get-snapshots-request-ignore-unavailable
// tag::get-snapshots-execute
GetSnapshotsResponse response = client.snapshot().get(request, RequestOptions.DEFAULT);
// end::get-snapshots-execute
// tag::get-snapshots-response
List<SnapshotInfo> snapshotsInfos = response.getSnapshots();
SnapshotInfo snapshotInfo = snapshotsInfos.get(0);
// <1>
RestStatus restStatus = snapshotInfo.status();
// <2>
SnapshotId snapshotId = snapshotInfo.snapshotId();
// <3>
SnapshotState snapshotState = snapshotInfo.state();
// <4>
List<SnapshotShardFailure> snapshotShardFailures = snapshotInfo.shardFailures();
// <5>
long startTime = snapshotInfo.startTime();
// <6>
long endTime = snapshotInfo.endTime();
// end::get-snapshots-response
assertEquals(1, snapshotsInfos.size());
}
Aggregations