Search in sources :

Example 11 with TransportException

use of org.elasticsearch.transport.TransportException in project elasticsearch by elastic.

the class RemoteClusterConnection method fetchShardsInternal.

private void fetchShardsInternal(SearchRequest searchRequest, List<String> indices, final ActionListener<ClusterSearchShardsResponse> listener) {
    final DiscoveryNode node = nodeSupplier.get();
    ClusterSearchShardsRequest searchShardsRequest = new ClusterSearchShardsRequest(indices.toArray(new String[indices.size()])).indicesOptions(searchRequest.indicesOptions()).local(true).preference(searchRequest.preference()).routing(searchRequest.routing());
    transportService.sendRequest(node, ClusterSearchShardsAction.NAME, searchShardsRequest, new TransportResponseHandler<ClusterSearchShardsResponse>() {

        @Override
        public ClusterSearchShardsResponse newInstance() {
            return new ClusterSearchShardsResponse();
        }

        @Override
        public void handleResponse(ClusterSearchShardsResponse clusterSearchShardsResponse) {
            listener.onResponse(clusterSearchShardsResponse);
        }

        @Override
        public void handleException(TransportException e) {
            listener.onFailure(e);
        }

        @Override
        public String executor() {
            return ThreadPool.Names.SEARCH;
        }
    });
}
Also used : ClusterSearchShardsResponse(org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsResponse) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ClusterSearchShardsRequest(org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequest) ConnectTransportException(org.elasticsearch.transport.ConnectTransportException) TransportException(org.elasticsearch.transport.TransportException)

Example 12 with TransportException

use of org.elasticsearch.transport.TransportException in project elasticsearch by elastic.

the class ShardStateAction method sendShardAction.

private void sendShardAction(final String actionName, final ClusterState currentState, final ShardEntry shardEntry, final Listener listener) {
    ClusterStateObserver observer = new ClusterStateObserver(currentState, clusterService, null, logger, threadPool.getThreadContext());
    DiscoveryNode masterNode = currentState.nodes().getMasterNode();
    Predicate<ClusterState> changePredicate = MasterNodeChangePredicate.build(currentState);
    if (masterNode == null) {
        logger.warn("{} no master known for action [{}] for shard entry [{}]", shardEntry.shardId, actionName, shardEntry);
        waitForNewMasterAndRetry(actionName, observer, shardEntry, listener, changePredicate);
    } else {
        logger.debug("{} sending [{}] to [{}] for shard entry [{}]", shardEntry.shardId, actionName, masterNode.getId(), shardEntry);
        transportService.sendRequest(masterNode, actionName, shardEntry, new EmptyTransportResponseHandler(ThreadPool.Names.SAME) {

            @Override
            public void handleResponse(TransportResponse.Empty response) {
                listener.onSuccess();
            }

            @Override
            public void handleException(TransportException exp) {
                if (isMasterChannelException(exp)) {
                    waitForNewMasterAndRetry(actionName, observer, shardEntry, listener, changePredicate);
                } else {
                    logger.warn((Supplier<?>) () -> new ParameterizedMessage("{} unexpected failure while sending request [{}] to [{}] for shard entry [{}]", shardEntry.shardId, actionName, masterNode, shardEntry), exp);
                    listener.onFailure(exp instanceof RemoteTransportException ? (Exception) (exp.getCause() instanceof Exception ? exp.getCause() : new ElasticsearchException(exp.getCause())) : exp);
                }
            }
        });
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) RemoteTransportException(org.elasticsearch.transport.RemoteTransportException) ClusterStateObserver(org.elasticsearch.cluster.ClusterStateObserver) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ElasticsearchException(org.elasticsearch.ElasticsearchException) TransportResponse(org.elasticsearch.transport.TransportResponse) ConnectTransportException(org.elasticsearch.transport.ConnectTransportException) RemoteTransportException(org.elasticsearch.transport.RemoteTransportException) TransportException(org.elasticsearch.transport.TransportException) ElasticsearchException(org.elasticsearch.ElasticsearchException) NodeClosedException(org.elasticsearch.node.NodeClosedException) ConnectTransportException(org.elasticsearch.transport.ConnectTransportException) NodeDisconnectedException(org.elasticsearch.transport.NodeDisconnectedException) RemoteTransportException(org.elasticsearch.transport.RemoteTransportException) TransportException(org.elasticsearch.transport.TransportException) NotMasterException(org.elasticsearch.cluster.NotMasterException) IOException(java.io.IOException) Supplier(org.apache.logging.log4j.util.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) EmptyTransportResponseHandler(org.elasticsearch.transport.EmptyTransportResponseHandler)

Example 13 with TransportException

use of org.elasticsearch.transport.TransportException in project elasticsearch by elastic.

the class RemoteClusterService method collectSearchShards.

void collectSearchShards(SearchRequest searchRequest, Map<String, List<String>> remoteIndicesByCluster, ActionListener<Map<String, ClusterSearchShardsResponse>> listener) {
    final CountDown responsesCountDown = new CountDown(remoteIndicesByCluster.size());
    final Map<String, ClusterSearchShardsResponse> searchShardsResponses = new ConcurrentHashMap<>();
    final AtomicReference<TransportException> transportException = new AtomicReference<>();
    for (Map.Entry<String, List<String>> entry : remoteIndicesByCluster.entrySet()) {
        final String clusterName = entry.getKey();
        RemoteClusterConnection remoteClusterConnection = remoteClusters.get(clusterName);
        if (remoteClusterConnection == null) {
            throw new IllegalArgumentException("no such remote cluster: " + clusterName);
        }
        final List<String> indices = entry.getValue();
        remoteClusterConnection.fetchSearchShards(searchRequest, indices, new ActionListener<ClusterSearchShardsResponse>() {

            @Override
            public void onResponse(ClusterSearchShardsResponse clusterSearchShardsResponse) {
                searchShardsResponses.put(clusterName, clusterSearchShardsResponse);
                if (responsesCountDown.countDown()) {
                    TransportException exception = transportException.get();
                    if (exception == null) {
                        listener.onResponse(searchShardsResponses);
                    } else {
                        listener.onFailure(transportException.get());
                    }
                }
            }

            @Override
            public void onFailure(Exception e) {
                TransportException exception = new TransportException("unable to communicate with remote cluster [" + clusterName + "]", e);
                if (transportException.compareAndSet(null, exception) == false) {
                    exception = transportException.accumulateAndGet(exception, (previous, current) -> {
                        current.addSuppressed(previous);
                        return current;
                    });
                }
                if (responsesCountDown.countDown()) {
                    listener.onFailure(exception);
                }
            }
        });
    }
}
Also used : ClusterSearchShardsResponse(org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDown(org.elasticsearch.common.util.concurrent.CountDown) TransportException(org.elasticsearch.transport.TransportException) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) TransportException(org.elasticsearch.transport.TransportException) ArrayList(java.util.ArrayList) List(java.util.List) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 14 with TransportException

use of org.elasticsearch.transport.TransportException in project elasticsearch by elastic.

the class SyncedFlushService method sendSyncRequests.

void sendSyncRequests(final String syncId, final List<ShardRouting> shards, ClusterState state, Map<String, Engine.CommitId> expectedCommitIds, final ShardId shardId, final int totalShards, final ActionListener<ShardsSyncedFlushResult> listener) {
    final CountDown countDown = new CountDown(shards.size());
    final Map<ShardRouting, ShardSyncedFlushResponse> results = ConcurrentCollections.newConcurrentMap();
    for (final ShardRouting shard : shards) {
        final DiscoveryNode node = state.nodes().get(shard.currentNodeId());
        if (node == null) {
            logger.trace("{} is assigned to an unknown node. skipping for sync id [{}]. shard routing {}", shardId, syncId, shard);
            results.put(shard, new ShardSyncedFlushResponse("unknown node"));
            contDownAndSendResponseIfDone(syncId, shards, shardId, totalShards, listener, countDown, results);
            continue;
        }
        final Engine.CommitId expectedCommitId = expectedCommitIds.get(shard.currentNodeId());
        if (expectedCommitId == null) {
            logger.trace("{} can't resolve expected commit id for current node, skipping for sync id [{}]. shard routing {}", shardId, syncId, shard);
            results.put(shard, new ShardSyncedFlushResponse("no commit id from pre-sync flush"));
            contDownAndSendResponseIfDone(syncId, shards, shardId, totalShards, listener, countDown, results);
            continue;
        }
        logger.trace("{} sending synced flush request to {}. sync id [{}].", shardId, shard, syncId);
        transportService.sendRequest(node, SYNCED_FLUSH_ACTION_NAME, new ShardSyncedFlushRequest(shard.shardId(), syncId, expectedCommitId), new TransportResponseHandler<ShardSyncedFlushResponse>() {

            @Override
            public ShardSyncedFlushResponse newInstance() {
                return new ShardSyncedFlushResponse();
            }

            @Override
            public void handleResponse(ShardSyncedFlushResponse response) {
                ShardSyncedFlushResponse existing = results.put(shard, response);
                assert existing == null : "got two answers for node [" + node + "]";
                // count after the assert so we won't decrement twice in handleException
                contDownAndSendResponseIfDone(syncId, shards, shardId, totalShards, listener, countDown, results);
            }

            @Override
            public void handleException(TransportException exp) {
                logger.trace((Supplier<?>) () -> new ParameterizedMessage("{} error while performing synced flush on [{}], skipping", shardId, shard), exp);
                results.put(shard, new ShardSyncedFlushResponse(exp.getMessage()));
                contDownAndSendResponseIfDone(syncId, shards, shardId, totalShards, listener, countDown, results);
            }

            @Override
            public String executor() {
                return ThreadPool.Names.SAME;
            }
        });
    }
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) CountDown(org.elasticsearch.common.util.concurrent.CountDown) TransportException(org.elasticsearch.transport.TransportException) Supplier(org.apache.logging.log4j.util.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) Engine(org.elasticsearch.index.engine.Engine)

Example 15 with TransportException

use of org.elasticsearch.transport.TransportException in project elasticsearch by elastic.

the class SyncedFlushService method sendPreSyncRequests.

/**
     * send presync requests to all started copies of the given shard
     */
void sendPreSyncRequests(final List<ShardRouting> shards, final ClusterState state, final ShardId shardId, final ActionListener<Map<String, Engine.CommitId>> listener) {
    final CountDown countDown = new CountDown(shards.size());
    final ConcurrentMap<String, Engine.CommitId> commitIds = ConcurrentCollections.newConcurrentMap();
    for (final ShardRouting shard : shards) {
        logger.trace("{} sending pre-synced flush request to {}", shardId, shard);
        final DiscoveryNode node = state.nodes().get(shard.currentNodeId());
        if (node == null) {
            logger.trace("{} shard routing {} refers to an unknown node. skipping.", shardId, shard);
            if (countDown.countDown()) {
                listener.onResponse(commitIds);
            }
            continue;
        }
        transportService.sendRequest(node, PRE_SYNCED_FLUSH_ACTION_NAME, new PreShardSyncedFlushRequest(shard.shardId()), new TransportResponseHandler<PreSyncedFlushResponse>() {

            @Override
            public PreSyncedFlushResponse newInstance() {
                return new PreSyncedFlushResponse();
            }

            @Override
            public void handleResponse(PreSyncedFlushResponse response) {
                Engine.CommitId existing = commitIds.putIfAbsent(node.getId(), response.commitId());
                assert existing == null : "got two answers for node [" + node + "]";
                // count after the assert so we won't decrement twice in handleException
                if (countDown.countDown()) {
                    listener.onResponse(commitIds);
                }
            }

            @Override
            public void handleException(TransportException exp) {
                logger.trace((Supplier<?>) () -> new ParameterizedMessage("{} error while performing pre synced flush on [{}], skipping", shardId, shard), exp);
                if (countDown.countDown()) {
                    listener.onResponse(commitIds);
                }
            }

            @Override
            public String executor() {
                return ThreadPool.Names.SAME;
            }
        });
    }
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) CountDown(org.elasticsearch.common.util.concurrent.CountDown) TransportException(org.elasticsearch.transport.TransportException) Supplier(org.apache.logging.log4j.util.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting)

Aggregations

TransportException (org.elasticsearch.transport.TransportException)21 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)11 IOException (java.io.IOException)10 ElasticsearchException (org.elasticsearch.ElasticsearchException)8 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)7 EmptyTransportResponseHandler (org.elasticsearch.transport.EmptyTransportResponseHandler)7 TransportResponse (org.elasticsearch.transport.TransportResponse)7 ClusterState (org.elasticsearch.cluster.ClusterState)6 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 Supplier (org.apache.logging.log4j.util.Supplier)5 ConnectTransportException (org.elasticsearch.transport.ConnectTransportException)4 ArrayList (java.util.ArrayList)3 ExecutionException (java.util.concurrent.ExecutionException)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 PlainActionFuture (org.elasticsearch.action.support.PlainActionFuture)3 CountDown (org.elasticsearch.common.util.concurrent.CountDown)3 ShardId (org.elasticsearch.index.shard.ShardId)3 TransportRequestOptions (org.elasticsearch.transport.TransportRequestOptions)3 TransportResponseHandler (org.elasticsearch.transport.TransportResponseHandler)3