org.elasticsearch.action.support.DefaultShardOperationFailedException Java Examples

The following examples show how to use org.elasticsearch.action.support.DefaultShardOperationFailedException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TransportBroadcastReplicationAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
private void finishAndNotifyListener(ActionListener listener, CopyOnWriteArrayList<ShardResponse> shardsResponses) {
    logger.trace("{}: got all shard responses", actionName);
    int successfulShards = 0;
    int failedShards = 0;
    int totalNumCopies = 0;
    List<ShardOperationFailedException> shardFailures = null;
    for (int i = 0; i < shardsResponses.size(); i++) {
        ActionWriteResponse shardResponse = shardsResponses.get(i);
        if (shardResponse == null) {
            // non active shard, ignore
        } else {
            failedShards += shardResponse.getShardInfo().getFailed();
            successfulShards += shardResponse.getShardInfo().getSuccessful();
            totalNumCopies += shardResponse.getShardInfo().getTotal();
            if (shardFailures == null) {
                shardFailures = new ArrayList<>();
            }
            for (ActionWriteResponse.ShardInfo.Failure failure : shardResponse.getShardInfo().getFailures()) {
                shardFailures.add(new DefaultShardOperationFailedException(new BroadcastShardOperationFailedException(new ShardId(failure.index(), failure.shardId()), failure.getCause())));
            }
        }
    }
    listener.onResponse(newResponse(successfulShards, failedShards, totalNumCopies, shardFailures));
}
 
Example #2
Source File: TransportBroadcastReplicationAction.java    From crate with Apache License 2.0 6 votes vote down vote up
private void finishAndNotifyListener(ActionListener listener, CopyOnWriteArrayList<ShardResponse> shardsResponses) {
    logger.trace("{}: got all shard responses", actionName);
    int successfulShards = 0;
    int failedShards = 0;
    int totalNumCopies = 0;
    List<DefaultShardOperationFailedException> shardFailures = null;
    for (int i = 0; i < shardsResponses.size(); i++) {
        ReplicationResponse shardResponse = shardsResponses.get(i);
        if (shardResponse == null) {
            // non active shard, ignore
        } else {
            failedShards += shardResponse.getShardInfo().getFailed();
            successfulShards += shardResponse.getShardInfo().getSuccessful();
            totalNumCopies += shardResponse.getShardInfo().getTotal();
            if (shardFailures == null) {
                shardFailures = new ArrayList<>();
            }
            for (ReplicationResponse.ShardInfo.Failure failure : shardResponse.getShardInfo().getFailures()) {
                shardFailures.add(new DefaultShardOperationFailedException(new BroadcastShardOperationFailedException(failure.fullShardId(), failure.getCause())));
            }
        }
    }
    listener.onResponse(newResponse(successfulShards, failedShards, totalNumCopies, shardFailures));
}
 
Example #3
Source File: TransportDfsOnlyAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
protected DfsOnlyResponse newResponse(DfsOnlyRequest request, AtomicReferenceArray shardsResponses, ClusterState clusterState) {
    int successfulShards = 0;
    int failedShards = 0;
    List<ShardOperationFailedException> shardFailures = null;
    AtomicArray<DfsSearchResult> dfsResults = new AtomicArray<>(shardsResponses.length());
    for (int i = 0; i < shardsResponses.length(); i++) {
        Object shardResponse = shardsResponses.get(i);
        if (shardResponse == null) {
            // simply ignore non active shards
        } else if (shardResponse instanceof BroadcastShardOperationFailedException) {
            failedShards++;
            if (shardFailures == null) {
                shardFailures = new ArrayList<>();
            }
            shardFailures.add(new DefaultShardOperationFailedException((BroadcastShardOperationFailedException) shardResponse));
        } else {
            dfsResults.set(i, ((ShardDfsOnlyResponse) shardResponse).getDfsSearchResult());
            successfulShards++;
        }
    }
    AggregatedDfs dfs = searchPhaseController.aggregateDfs(dfsResults);
    return new DfsOnlyResponse(dfs, shardsResponses.length(), successfulShards, failedShards, shardFailures, buildTookInMillis(request));
}
 
Example #4
Source File: AbstractTransportExportAction.java    From elasticsearch-inout-plugin with Apache License 2.0 6 votes vote down vote up
@Override
protected ExportResponse newResponse(ExportRequest request, AtomicReferenceArray shardsResponses, ClusterState clusterState) {
    int successfulShards = 0;
    int failedShards = 0;
    List<ShardOperationFailedException> shardFailures = null;
    List<ShardExportResponse> responses = new ArrayList<ShardExportResponse>();
    for (int i = 0; i < shardsResponses.length(); i++) {
        Object shardResponse = shardsResponses.get(i);
        if (shardResponse == null) {
            failedShards++;
        } else if (shardResponse instanceof BroadcastShardOperationFailedException) {
            failedShards++;
            if (shardFailures == null) {
                shardFailures = newArrayList();
            }
            shardFailures.add(new DefaultShardOperationFailedException((BroadcastShardOperationFailedException) shardResponse));
        } else {
            responses.add((ShardExportResponse) shardResponse);
            successfulShards++;
        }
    }
    return new ExportResponse(responses, shardsResponses.length(), successfulShards, failedShards, shardFailures);
}
 
Example #5
Source File: TransportRecoveryAction.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
protected RecoveryResponse newResponse(RecoveryRequest request, int totalShards, int successfulShards, int failedShards, List<RecoveryState> responses, List<DefaultShardOperationFailedException> shardFailures, ClusterState clusterState) {
    Map<String, List<RecoveryState>> shardResponses = new HashMap<>();
    for (RecoveryState recoveryState : responses) {
        if (recoveryState == null) {
            continue;
        }
        String indexName = recoveryState.getShardId().getIndexName();
        if (!shardResponses.containsKey(indexName)) {
            shardResponses.put(indexName, new ArrayList<>());
        }
        if (request.activeOnly()) {
            if (recoveryState.getStage() != RecoveryState.Stage.DONE) {
                shardResponses.get(indexName).add(recoveryState);
            }
        } else {
            shardResponses.get(indexName).add(recoveryState);
        }
    }
    return new RecoveryResponse(totalShards, successfulShards, failedShards, shardResponses, shardFailures);
}
 
Example #6
Source File: TransportValidateQueryAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
protected ValidateQueryResponse newResponse(ValidateQueryRequest request, AtomicReferenceArray shardsResponses, ClusterState clusterState) {
    int successfulShards = 0;
    int failedShards = 0;
    boolean valid = true;
    List<ShardOperationFailedException> shardFailures = null;
    List<QueryExplanation> queryExplanations = null;
    for (int i = 0; i < shardsResponses.length(); i++) {
        Object shardResponse = shardsResponses.get(i);
        if (shardResponse == null) {
            // simply ignore non active shards
        } else if (shardResponse instanceof BroadcastShardOperationFailedException) {
            failedShards++;
            if (shardFailures == null) {
                shardFailures = new ArrayList<>();
            }
            shardFailures.add(new DefaultShardOperationFailedException((BroadcastShardOperationFailedException) shardResponse));
        } else {
            ShardValidateQueryResponse validateQueryResponse = (ShardValidateQueryResponse) shardResponse;
            valid = valid && validateQueryResponse.isValid();
            if (request.explain() || request.rewrite()) {
                if (queryExplanations == null) {
                    queryExplanations = new ArrayList<>();
                }
                queryExplanations.add(new QueryExplanation(
                        validateQueryResponse.getIndex(),
                        validateQueryResponse.isValid(),
                        validateQueryResponse.getExplanation(),
                        validateQueryResponse.getError()
                ));
            }
            successfulShards++;
        }
    }
    return new ValidateQueryResponse(valid, queryExplanations, shardsResponses.length(), successfulShards, failedShards, shardFailures);
}
 
Example #7
Source File: ElasticsearchAssertions.java    From crate with Apache License 2.0 5 votes vote down vote up
public static String formatShardStatus(BroadcastResponse response) {
    StringBuilder msg = new StringBuilder();
    msg.append(" Total shards: ").append(response.getTotalShards())
       .append(" Successful shards: ").append(response.getSuccessfulShards())
       .append(" & ").append(response.getFailedShards()).append(" shard failures:");
    for (DefaultShardOperationFailedException failure : response.getShardFailures()) {
        msg.append("\n ").append(failure);
    }
    return msg.toString();
}
 
Example #8
Source File: ElasticsearchAssertions.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Checks that all shard requests of a replicated broadcast request failed due to a cluster block
 *
 * @param replicatedBroadcastResponse the response that should only contain failed shard responses
 *
 * */
public static void assertBlocked(BroadcastResponse replicatedBroadcastResponse) {
    assertThat("all shard requests should have failed",
            replicatedBroadcastResponse.getFailedShards(), equalTo(replicatedBroadcastResponse.getTotalShards()));
    for (DefaultShardOperationFailedException exception : replicatedBroadcastResponse.getShardFailures()) {
        ClusterBlockException clusterBlockException =
                (ClusterBlockException) ExceptionsHelper.unwrap(exception.getCause(), ClusterBlockException.class);
        assertNotNull("expected the cause of failure to be a ClusterBlockException but got " + exception.getCause().getMessage(),
                clusterBlockException);
        assertThat(clusterBlockException.blocks().size(), greaterThan(0));
        assertThat(clusterBlockException.status(), CoreMatchers.equalTo(RestStatus.FORBIDDEN));
    }
}
 
Example #9
Source File: TransportBroadcastByNodeAction.java    From crate with Apache License 2.0 5 votes vote down vote up
private Response newResponse(
        Request request,
        AtomicReferenceArray responses,
        List<NoShardAvailableActionException> unavailableShardExceptions,
        Map<String, List<ShardRouting>> nodes,
        ClusterState clusterState) {
    int totalShards = 0;
    int successfulShards = 0;
    List<ShardOperationResult> broadcastByNodeResponses = new ArrayList<>();
    List<DefaultShardOperationFailedException> exceptions = new ArrayList<>();
    for (int i = 0; i < responses.length(); i++) {
        if (responses.get(i) instanceof FailedNodeException) {
            FailedNodeException exception = (FailedNodeException) responses.get(i);
            totalShards += nodes.get(exception.nodeId()).size();
            for (ShardRouting shard : nodes.get(exception.nodeId())) {
                exceptions.add(new DefaultShardOperationFailedException(shard.getIndexName(), shard.getId(), exception));
            }
        } else {
            NodeResponse response = (NodeResponse) responses.get(i);
            broadcastByNodeResponses.addAll(response.results);
            totalShards += response.getTotalShards();
            successfulShards += response.getSuccessfulShards();
            for (BroadcastShardOperationFailedException throwable : response.getExceptions()) {
                if (!TransportActions.isShardNotAvailableException(throwable)) {
                    exceptions.add(new DefaultShardOperationFailedException(throwable.getShardId().getIndexName(), throwable.getShardId().getId(), throwable));
                }
            }
        }
    }
    totalShards += unavailableShardExceptions.size();
    int failedShards = exceptions.size();
    return newResponse(request, totalShards, successfulShards, failedShards, broadcastByNodeResponses, exceptions, clusterState);
}
 
Example #10
Source File: BroadcastResponse.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public void writeTo(StreamOutput out) throws IOException {
    out.writeVInt(totalShards);
    out.writeVInt(successfulShards);
    out.writeVInt(failedShards);
    out.writeVInt(shardFailures.length);
    for (DefaultShardOperationFailedException exp : shardFailures) {
        exp.writeTo(out);
    }
}
 
Example #11
Source File: BroadcastResponse.java    From crate with Apache License 2.0 5 votes vote down vote up
public BroadcastResponse(StreamInput in) throws IOException {
    totalShards = in.readVInt();
    successfulShards = in.readVInt();
    failedShards = in.readVInt();
    int size = in.readVInt();
    if (size > 0) {
        shardFailures = new DefaultShardOperationFailedException[size];
        for (int i = 0; i < size; i++) {
            shardFailures[i] = new DefaultShardOperationFailedException(in);
        }
    } else {
        shardFailures = EMPTY;
    }
}
 
Example #12
Source File: BroadcastResponse.java    From crate with Apache License 2.0 5 votes vote down vote up
public BroadcastResponse(int totalShards, int successfulShards, int failedShards,
                         List<DefaultShardOperationFailedException> shardFailures) {
    this.totalShards = totalShards;
    this.successfulShards = successfulShards;
    this.failedShards = failedShards;
    if (shardFailures == null) {
        this.shardFailures = EMPTY;
    } else {
        this.shardFailures = shardFailures.toArray(new DefaultShardOperationFailedException[0]);
    }
}
 
Example #13
Source File: TransportExistsAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
protected ExistsResponse newResponse(ExistsRequest request, AtomicReferenceArray shardsResponses, ClusterState clusterState) {
    int successfulShards = 0;
    int failedShards = 0;
    boolean exists = false;
    List<ShardOperationFailedException> shardFailures = null;

    // if docs do exist, the last response will have exists = true (since we early terminate the shard requests)
    for (int i = shardsResponses.length() - 1; i >= 0 ; i--) {
        Object shardResponse = shardsResponses.get(i);
        if (shardResponse == null) {
            // simply ignore non active shards
        } else if (shardResponse instanceof BroadcastShardOperationFailedException) {
            failedShards++;
            if (shardFailures == null) {
                shardFailures = new ArrayList<>();
            }
            shardFailures.add(new DefaultShardOperationFailedException((BroadcastShardOperationFailedException) shardResponse));
        } else {
            successfulShards++;
            if ((exists = ((ShardExistsResponse) shardResponse).exists())) {
                successfulShards = shardsResponses.length() - failedShards;
                break;
            }
        }
    }
    return new ExistsResponse(exists, shardsResponses.length(), successfulShards, failedShards, shardFailures);
}
 
Example #14
Source File: TransportBroadcastByNodeAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private final Response newResponse(
        Request request,
        AtomicReferenceArray responses,
        List<NoShardAvailableActionException> unavailableShardExceptions,
        Map<String, List<ShardRouting>> nodes,
        ClusterState clusterState) {
    int totalShards = 0;
    int successfulShards = 0;
    List<ShardOperationResult> broadcastByNodeResponses = new ArrayList<>();
    List<ShardOperationFailedException> exceptions = new ArrayList<>();
    for (int i = 0; i < responses.length(); i++) {
        if (responses.get(i) instanceof FailedNodeException) {
            FailedNodeException exception = (FailedNodeException) responses.get(i);
            totalShards += nodes.get(exception.nodeId()).size();
            for (ShardRouting shard : nodes.get(exception.nodeId())) {
                exceptions.add(new DefaultShardOperationFailedException(shard.getIndex(), shard.getId(), exception));
            }
        } else {
            NodeResponse response = (NodeResponse) responses.get(i);
            broadcastByNodeResponses.addAll(response.results);
            totalShards += response.getTotalShards();
            successfulShards += response.getSuccessfulShards();
            for (BroadcastShardOperationFailedException throwable : response.getExceptions()) {
                if (!TransportActions.isShardNotAvailableException(throwable)) {
                    exceptions.add(new DefaultShardOperationFailedException(throwable.getIndex(), throwable.getShardId().getId(), throwable));
                }
            }
        }
    }
    totalShards += unavailableShardExceptions.size();
    int failedShards = exceptions.size();
    return newResponse(request, totalShards, successfulShards, failedShards, broadcastByNodeResponses, exceptions, clusterState);
}
 
Example #15
Source File: TransportSuggestAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
protected SuggestResponse newResponse(SuggestRequest request, AtomicReferenceArray shardsResponses, ClusterState clusterState) {
    int successfulShards = 0;
    int failedShards = 0;

    final Map<String, List<Suggest.Suggestion>> groupedSuggestions = new HashMap<>();

    List<ShardOperationFailedException> shardFailures = null;
    for (int i = 0; i < shardsResponses.length(); i++) {
        Object shardResponse = shardsResponses.get(i);
        if (shardResponse == null) {
            // simply ignore non active shards
        } else if (shardResponse instanceof BroadcastShardOperationFailedException) {
            failedShards++;
            if (shardFailures == null) {
                shardFailures = new ArrayList<>();
            }
            shardFailures.add(new DefaultShardOperationFailedException((BroadcastShardOperationFailedException) shardResponse));
        } else {
            Suggest suggest = ((ShardSuggestResponse) shardResponse).getSuggest();
            Suggest.group(groupedSuggestions, suggest);
            successfulShards++;
        }
    }

    return new SuggestResponse(new Suggest(Suggest.reduce(groupedSuggestions)), shardsResponses.length(), successfulShards, failedShards, shardFailures);
}
 
Example #16
Source File: AbstractTransportSearchIntoAction.java    From elasticsearch-inout-plugin with Apache License 2.0 5 votes vote down vote up
@Override
protected SearchIntoResponse newResponse(SearchIntoRequest request,
        AtomicReferenceArray shardsResponses, ClusterState clusterState) {
    int successfulShards = 0;
    int failedShards = 0;
    List<ShardOperationFailedException> shardFailures = null;
    List<ShardSearchIntoResponse> responses = new
            ArrayList<ShardSearchIntoResponse>();
    for (int i = 0; i < shardsResponses.length(); i++) {
        Object shardResponse = shardsResponses.get(i);
        if (shardResponse == null) {
            failedShards++;
        } else if (shardResponse instanceof
                BroadcastShardOperationFailedException) {
            failedShards++;
            if (shardFailures == null) {
                shardFailures = newArrayList();
            }
            shardFailures.add(new DefaultShardOperationFailedException(
                    (BroadcastShardOperationFailedException)
                            shardResponse));
        } else {
            responses.add((ShardSearchIntoResponse) shardResponse);
            successfulShards++;
        }
    }
    return new SearchIntoResponse(responses, shardsResponses.length(),
            successfulShards, failedShards, shardFailures);
}
 
Example #17
Source File: BroadcastResponse.java    From crate with Apache License 2.0 4 votes vote down vote up
/**
 * The list of shard failures exception.
 */
public DefaultShardOperationFailedException[] getShardFailures() {
    return shardFailures;
}
 
Example #18
Source File: TransportBroadcastReplicationAction.java    From crate with Apache License 2.0 4 votes vote down vote up
protected abstract BroadcastResponse newResponse(int successfulShards, int failedShards, int totalNumCopies,
List<DefaultShardOperationFailedException> shardFailures);
 
Example #19
Source File: TransportForceMergeAction.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
protected ForceMergeResponse newResponse(ForceMergeRequest request, int totalShards, int successfulShards, int failedShards, List<EmptyResult> responses, List<DefaultShardOperationFailedException> shardFailures, ClusterState clusterState) {
    return new ForceMergeResponse(totalShards, successfulShards, failedShards, shardFailures);
}
 
Example #20
Source File: ForceMergeResponse.java    From crate with Apache License 2.0 4 votes vote down vote up
ForceMergeResponse(int totalShards, int successfulShards, int failedShards, List<DefaultShardOperationFailedException> shardFailures) {
    super(totalShards, successfulShards, failedShards, shardFailures);
}
 
Example #21
Source File: FlushResponse.java    From crate with Apache License 2.0 4 votes vote down vote up
FlushResponse(int totalShards, int successfulShards, int failedShards, List<DefaultShardOperationFailedException> shardFailures) {
    super(totalShards, successfulShards, failedShards, shardFailures);
}
 
Example #22
Source File: UpgradeResponse.java    From crate with Apache License 2.0 4 votes vote down vote up
UpgradeResponse(Map<String, Tuple<Version, String>> versions, int totalShards, int successfulShards, int failedShards,
                List<DefaultShardOperationFailedException> shardFailures) {
    super(totalShards, successfulShards, failedShards, shardFailures);
    this.versions = versions;
}
 
Example #23
Source File: TransportFlushAction.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
protected FlushResponse newResponse(int successfulShards, int failedShards, int totalNumCopies, List
        <DefaultShardOperationFailedException> shardFailures) {
    return new FlushResponse(totalNumCopies, successfulShards, failedShards, shardFailures);
}
 
Example #24
Source File: TransportIndicesStatsAction.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
protected IndicesStatsResponse newResponse(IndicesStatsRequest request, int totalShards, int successfulShards, int failedShards, List<ShardStats> responses, List<DefaultShardOperationFailedException> shardFailures, ClusterState clusterState) {
    return new IndicesStatsResponse(responses.toArray(new ShardStats[responses.size()]), totalShards, successfulShards, failedShards, shardFailures);
}
 
Example #25
Source File: IndicesStatsResponse.java    From crate with Apache License 2.0 4 votes vote down vote up
IndicesStatsResponse(ShardStats[] shards, int totalShards, int successfulShards, int failedShards,
                     List<DefaultShardOperationFailedException> shardFailures) {
    super(totalShards, successfulShards, failedShards, shardFailures);
    this.shards = shards;
}
 
Example #26
Source File: TransportRefreshAction.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
protected RefreshResponse newResponse(int successfulShards, int failedShards, int totalNumCopies,
                                      List<DefaultShardOperationFailedException> shardFailures) {
    return new RefreshResponse(totalNumCopies, successfulShards, failedShards, shardFailures);
}
 
Example #27
Source File: RefreshResponse.java    From crate with Apache License 2.0 4 votes vote down vote up
RefreshResponse(int totalShards, int successfulShards, int failedShards, List<DefaultShardOperationFailedException> shardFailures) {
    super(totalShards, successfulShards, failedShards, shardFailures);
}
 
Example #28
Source File: RecoveryResponse.java    From crate with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs recovery information for a collection of indices and associated shards. Keeps track of how many total shards
 * were seen, and out of those how many were successfully processed and how many failed.
 *
 * @param totalShards       Total count of shards seen
 * @param successfulShards  Count of shards successfully processed
 * @param failedShards      Count of shards which failed to process
 * @param shardRecoveryStates    Map of indices to shard recovery information
 * @param shardFailures     List of failures processing shards
 */
public RecoveryResponse(int totalShards, int successfulShards, int failedShards, Map<String, List<RecoveryState>> shardRecoveryStates,
                        List<DefaultShardOperationFailedException> shardFailures) {
    super(totalShards, successfulShards, failedShards, shardFailures);
    this.shardRecoveryStates = shardRecoveryStates;
}
 
Example #29
Source File: TransportBroadcastByNodeAction.java    From crate with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new response to the underlying request.
 *
 * @param request          the underlying request
 * @param totalShards      the total number of shards considered for execution of the operation
 * @param successfulShards the total number of shards for which execution of the operation was successful
 * @param failedShards     the total number of shards for which execution of the operation failed
 * @param results          the per-node aggregated shard-level results
 * @param shardFailures    the exceptions corresponding to shard operation failures
 * @param clusterState     the cluster state
 * @return the response
 */
protected abstract Response newResponse(Request request, int totalShards, int successfulShards, int failedShards, List<ShardOperationResult> results, List<DefaultShardOperationFailedException> shardFailures, ClusterState clusterState);