Search in sources :

Example 1 with SnapshotShardFailure

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()));
}
Also used : ShardId(org.opensearch.index.shard.ShardId) SnapshotId(org.opensearch.snapshots.SnapshotId) SnapshotShardFailure(org.opensearch.snapshots.SnapshotShardFailure) SnapshotInfo(org.opensearch.snapshots.SnapshotInfo) ArrayList(java.util.ArrayList)

Example 2 with SnapshotShardFailure

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);
}
Also used : ShardId(org.opensearch.index.shard.ShardId) SnapshotId(org.opensearch.snapshots.SnapshotId) SnapshotInfo(org.opensearch.snapshots.SnapshotInfo) SnapshotShardFailure(org.opensearch.snapshots.SnapshotShardFailure) ArrayList(java.util.ArrayList)

Example 3 with SnapshotShardFailure

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);
}
Also used : ShardId(org.opensearch.index.shard.ShardId) IndexShardSnapshotStatus(org.opensearch.index.snapshots.IndexShardSnapshotStatus) IndexId(org.opensearch.repositories.IndexId) Repository(org.opensearch.repositories.Repository) SnapshotShardFailure(org.opensearch.snapshots.SnapshotShardFailure) HashMap(java.util.HashMap) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata)

Example 4 with SnapshotShardFailure

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());
}
Also used : SnapshotShardFailure(org.opensearch.snapshots.SnapshotShardFailure) GetSnapshotsRequest(org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest) RestHighLevelClient(org.opensearch.client.RestHighLevelClient) SnapshotId(org.opensearch.snapshots.SnapshotId) GetSnapshotsResponse(org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse) SnapshotInfo(org.opensearch.snapshots.SnapshotInfo) SnapshotState(org.opensearch.snapshots.SnapshotState) RestStatus(org.opensearch.rest.RestStatus)

Aggregations

SnapshotShardFailure (org.opensearch.snapshots.SnapshotShardFailure)4 ShardId (org.opensearch.index.shard.ShardId)3 SnapshotId (org.opensearch.snapshots.SnapshotId)3 SnapshotInfo (org.opensearch.snapshots.SnapshotInfo)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)1 GetSnapshotsRequest (org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest)1 GetSnapshotsResponse (org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse)1 RestHighLevelClient (org.opensearch.client.RestHighLevelClient)1 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)1 IndexShardSnapshotStatus (org.opensearch.index.snapshots.IndexShardSnapshotStatus)1 IndexId (org.opensearch.repositories.IndexId)1 Repository (org.opensearch.repositories.Repository)1 RestStatus (org.opensearch.rest.RestStatus)1 SnapshotState (org.opensearch.snapshots.SnapshotState)1