Search in sources :

Example 6 with BroadcastShardOperationFailedException

use of org.elasticsearch.action.support.broadcast.BroadcastShardOperationFailedException in project elasticsearch by elastic.

the class TransportBroadcastByNodeActionTests method testResultAggregation.

public void testResultAggregation() throws ExecutionException, InterruptedException {
    Request request = new Request(new String[] { TEST_INDEX });
    PlainActionFuture<Response> listener = new PlainActionFuture<>();
    // simulate removing the master
    final boolean simulateFailedMasterNode = rarely();
    DiscoveryNode failedMasterNode = null;
    if (simulateFailedMasterNode) {
        failedMasterNode = clusterService.state().nodes().getMasterNode();
        DiscoveryNodes.Builder builder = DiscoveryNodes.builder(clusterService.state().getNodes());
        builder.remove(failedMasterNode.getId());
        builder.masterNodeId(null);
        setState(clusterService, ClusterState.builder(clusterService.state()).nodes(builder));
    }
    action.new AsyncAction(null, request, listener).start();
    Map<String, List<CapturingTransport.CapturedRequest>> capturedRequests = transport.getCapturedRequestsByTargetNodeAndClear();
    ShardsIterator shardIt = clusterService.state().getRoutingTable().allShards(new String[] { TEST_INDEX });
    Map<String, List<ShardRouting>> map = new HashMap<>();
    for (ShardRouting shard : shardIt.asUnordered()) {
        if (!map.containsKey(shard.currentNodeId())) {
            map.put(shard.currentNodeId(), new ArrayList<>());
        }
        map.get(shard.currentNodeId()).add(shard);
    }
    int totalShards = 0;
    int totalSuccessfulShards = 0;
    int totalFailedShards = 0;
    for (Map.Entry<String, List<CapturingTransport.CapturedRequest>> entry : capturedRequests.entrySet()) {
        List<BroadcastShardOperationFailedException> exceptions = new ArrayList<>();
        long requestId = entry.getValue().get(0).requestId;
        if (rarely()) {
            // simulate node failure
            totalShards += map.get(entry.getKey()).size();
            totalFailedShards += map.get(entry.getKey()).size();
            transport.handleRemoteError(requestId, new Exception());
        } else {
            List<ShardRouting> shards = map.get(entry.getKey());
            List<TransportBroadcastByNodeAction.EmptyResult> shardResults = new ArrayList<>();
            for (ShardRouting shard : shards) {
                totalShards++;
                if (rarely()) {
                    // simulate operation failure
                    totalFailedShards++;
                    exceptions.add(new BroadcastShardOperationFailedException(shard.shardId(), "operation indices:admin/test failed"));
                } else {
                    shardResults.add(TransportBroadcastByNodeAction.EmptyResult.INSTANCE);
                }
            }
            totalSuccessfulShards += shardResults.size();
            TransportBroadcastByNodeAction.NodeResponse nodeResponse = action.new NodeResponse(entry.getKey(), shards.size(), shardResults, exceptions);
            transport.handleResponse(requestId, nodeResponse);
        }
    }
    if (simulateFailedMasterNode) {
        totalShards += map.get(failedMasterNode.getId()).size();
    }
    Response response = listener.get();
    assertEquals("total shards", totalShards, response.getTotalShards());
    assertEquals("successful shards", totalSuccessfulShards, response.getSuccessfulShards());
    assertEquals("failed shards", totalFailedShards, response.getFailedShards());
    assertEquals("accumulated exceptions", totalFailedShards, response.getShardFailures().length);
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) HasToString.hasToString(org.hamcrest.object.HasToString.hasToString) ShardsIterator(org.elasticsearch.cluster.routing.ShardsIterator) List(java.util.List) ArrayList(java.util.ArrayList) BroadcastShardOperationFailedException(org.elasticsearch.action.support.broadcast.BroadcastShardOperationFailedException) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) CapturingTransport(org.elasticsearch.test.transport.CapturingTransport) IndicesRequest(org.elasticsearch.action.IndicesRequest) BroadcastRequest(org.elasticsearch.action.support.broadcast.BroadcastRequest) ElasticsearchException(org.elasticsearch.ElasticsearchException) BroadcastShardOperationFailedException(org.elasticsearch.action.support.broadcast.BroadcastShardOperationFailedException) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) IOException(java.io.IOException) ShardOperationFailedException(org.elasticsearch.action.ShardOperationFailedException) ExecutionException(java.util.concurrent.ExecutionException) BroadcastResponse(org.elasticsearch.action.support.broadcast.BroadcastResponse) TransportResponse(org.elasticsearch.transport.TransportResponse) PlainActionFuture(org.elasticsearch.action.support.PlainActionFuture) TestShardRouting(org.elasticsearch.cluster.routing.TestShardRouting) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) Map(java.util.Map) HashMap(java.util.HashMap) Collections.emptyMap(java.util.Collections.emptyMap)

Example 7 with BroadcastShardOperationFailedException

use of org.elasticsearch.action.support.broadcast.BroadcastShardOperationFailedException in project crate by crate.

the class TransportBroadcastReplicationAction method finishAndNotifyListener.

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));
}
Also used : BroadcastShardOperationFailedException(org.elasticsearch.action.support.broadcast.BroadcastShardOperationFailedException) DefaultShardOperationFailedException(org.elasticsearch.action.support.DefaultShardOperationFailedException)

Aggregations

BroadcastShardOperationFailedException (org.elasticsearch.action.support.broadcast.BroadcastShardOperationFailedException)7 ArrayList (java.util.ArrayList)4 DefaultShardOperationFailedException (org.elasticsearch.action.support.DefaultShardOperationFailedException)4 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)4 ShardOperationFailedException (org.elasticsearch.action.ShardOperationFailedException)3 IOException (java.io.IOException)2 ElasticsearchException (org.elasticsearch.ElasticsearchException)2 FailedNodeException (org.elasticsearch.action.FailedNodeException)2 IndicesRequest (org.elasticsearch.action.IndicesRequest)2 BroadcastRequest (org.elasticsearch.action.support.broadcast.BroadcastRequest)2 ClusterBlockException (org.elasticsearch.cluster.block.ClusterBlockException)2 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)2 ShardsIterator (org.elasticsearch.cluster.routing.ShardsIterator)2 TestShardRouting (org.elasticsearch.cluster.routing.TestShardRouting)2 TransportResponse (org.elasticsearch.transport.TransportResponse)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 HasToString.hasToString (org.hamcrest.object.HasToString.hasToString)2 EOFException (java.io.EOFException)1 FileNotFoundException (java.io.FileNotFoundException)1 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)1