Search in sources :

Example 1 with ShardRestoreStatus

use of org.elasticsearch.cluster.RestoreInProgress.ShardRestoreStatus in project elasticsearch by elastic.

the class RestoreService method updateRestoreStateWithDeletedIndices.

public static RestoreInProgress updateRestoreStateWithDeletedIndices(RestoreInProgress oldRestore, Set<Index> deletedIndices) {
    boolean changesMade = false;
    final List<RestoreInProgress.Entry> entries = new ArrayList<>();
    for (RestoreInProgress.Entry entry : oldRestore.entries()) {
        ImmutableOpenMap.Builder<ShardId, ShardRestoreStatus> shardsBuilder = null;
        for (ObjectObjectCursor<ShardId, ShardRestoreStatus> cursor : entry.shards()) {
            ShardId shardId = cursor.key;
            if (deletedIndices.contains(shardId.getIndex())) {
                changesMade = true;
                if (shardsBuilder == null) {
                    shardsBuilder = ImmutableOpenMap.builder(entry.shards());
                }
                shardsBuilder.put(shardId, new ShardRestoreStatus(null, RestoreInProgress.State.FAILURE, "index was deleted"));
            }
        }
        if (shardsBuilder != null) {
            ImmutableOpenMap<ShardId, ShardRestoreStatus> shards = shardsBuilder.build();
            entries.add(new RestoreInProgress.Entry(entry.snapshot(), overallState(RestoreInProgress.State.STARTED, shards), entry.indices(), shards));
        } else {
            entries.add(entry);
        }
    }
    if (changesMade) {
        return new RestoreInProgress(entries.toArray(new RestoreInProgress.Entry[entries.size()]));
    } else {
        return oldRestore;
    }
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) RestoreInProgress(org.elasticsearch.cluster.RestoreInProgress) ShardRestoreStatus(org.elasticsearch.cluster.RestoreInProgress.ShardRestoreStatus) ArrayList(java.util.ArrayList) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap)

Example 2 with ShardRestoreStatus

use of org.elasticsearch.cluster.RestoreInProgress.ShardRestoreStatus in project crate by crate.

the class RestoreService method updateRestoreStateWithDeletedIndices.

public static RestoreInProgress updateRestoreStateWithDeletedIndices(RestoreInProgress oldRestore, Set<Index> deletedIndices) {
    boolean changesMade = false;
    RestoreInProgress.Builder builder = new RestoreInProgress.Builder();
    for (RestoreInProgress.Entry entry : oldRestore) {
        ImmutableOpenMap.Builder<ShardId, ShardRestoreStatus> shardsBuilder = null;
        for (ObjectObjectCursor<ShardId, ShardRestoreStatus> cursor : entry.shards()) {
            ShardId shardId = cursor.key;
            if (deletedIndices.contains(shardId.getIndex())) {
                changesMade = true;
                if (shardsBuilder == null) {
                    shardsBuilder = ImmutableOpenMap.builder(entry.shards());
                }
                shardsBuilder.put(shardId, new ShardRestoreStatus(null, RestoreInProgress.State.FAILURE, "index was deleted"));
            }
        }
        if (shardsBuilder != null) {
            ImmutableOpenMap<ShardId, ShardRestoreStatus> shards = shardsBuilder.build();
            builder.add(new RestoreInProgress.Entry(entry.uuid(), entry.snapshot(), overallState(RestoreInProgress.State.STARTED, shards), entry.indices(), shards));
        } else {
            builder.add(entry);
        }
    }
    if (changesMade) {
        return builder.build();
    } else {
        return oldRestore;
    }
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) RestoreInProgress(org.elasticsearch.cluster.RestoreInProgress) ShardRestoreStatus(org.elasticsearch.cluster.RestoreInProgress.ShardRestoreStatus) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap)

Aggregations

RestoreInProgress (org.elasticsearch.cluster.RestoreInProgress)2 ShardRestoreStatus (org.elasticsearch.cluster.RestoreInProgress.ShardRestoreStatus)2 ImmutableOpenMap (org.elasticsearch.common.collect.ImmutableOpenMap)2 ShardId (org.elasticsearch.index.shard.ShardId)2 ArrayList (java.util.ArrayList)1