Search in sources :

Example 36 with TransportException

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

the class TransportAddVotingConfigExclusionsActionTests method testTimesOut.

public void testTimesOut() throws InterruptedException {
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    final SetOnce<TransportException> exceptionHolder = new SetOnce<>();
    transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME, new AddVotingConfigExclusionsRequest(new String[] { "other1" }, TimeValue.timeValueMillis(100)), expectError(e -> {
        exceptionHolder.set(e);
        countDownLatch.countDown();
    }));
    assertTrue(countDownLatch.await(30, TimeUnit.SECONDS));
    final Throwable rootCause = exceptionHolder.get().getRootCause();
    assertThat(rootCause, instanceOf(ElasticsearchTimeoutException.class));
    assertThat(rootCause.getMessage(), startsWith("timed out waiting for voting config exclusions [{other1}"));
}
Also used : Builder(org.elasticsearch.cluster.node.DiscoveryNodes.Builder) Listener(org.elasticsearch.cluster.ClusterStateObserver.Listener) ClusterServiceUtils.createClusterService(org.elasticsearch.test.ClusterServiceUtils.createClusterService) CoordinationMetadata(org.elasticsearch.cluster.coordination.CoordinationMetadata) ClusterState(org.elasticsearch.cluster.ClusterState) ClusterStateUpdateTask(org.elasticsearch.cluster.ClusterStateUpdateTask) Settings(org.elasticsearch.common.settings.Settings) VotingConfigExclusion(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) ThreadPool(org.elasticsearch.threadpool.ThreadPool) ClusterName(org.elasticsearch.cluster.ClusterName) ClusterStateObserver(org.elasticsearch.cluster.ClusterStateObserver) AfterClass(org.junit.AfterClass) Set(java.util.Set) Matchers.startsWith(org.hamcrest.Matchers.startsWith) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) CountDownLatch(java.util.concurrent.CountDownLatch) Version(org.elasticsearch.Version) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) TimeValue(io.crate.common.unit.TimeValue) TransportResponseHandler(org.elasticsearch.transport.TransportResponseHandler) DiscoveryNodeRole(org.elasticsearch.cluster.node.DiscoveryNodeRole) TransportException(org.elasticsearch.transport.TransportException) BeforeClass(org.junit.BeforeClass) ClusterService(org.elasticsearch.cluster.service.ClusterService) ClusterState.builder(org.elasticsearch.cluster.ClusterState.builder) Names(org.elasticsearch.threadpool.ThreadPool.Names) HashSet(java.util.HashSet) ElasticsearchTimeoutException(org.elasticsearch.ElasticsearchTimeoutException) Metadata(org.elasticsearch.cluster.metadata.Metadata) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) MAXIMUM_VOTING_CONFIG_EXCLUSIONS_SETTING(org.elasticsearch.action.admin.cluster.configuration.TransportAddVotingConfigExclusionsAction.MAXIMUM_VOTING_CONFIG_EXCLUSIONS_SETTING) VotingConfiguration(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration) ESTestCase(org.elasticsearch.test.ESTestCase) TransportService(org.elasticsearch.transport.TransportService) Before(org.junit.Before) Collections.emptyMap(java.util.Collections.emptyMap) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) SetOnce(org.apache.lucene.util.SetOnce) Collections.emptySet(java.util.Collections.emptySet) MockTransport(org.elasticsearch.test.transport.MockTransport) IOException(java.io.IOException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) StreamInput(org.elasticsearch.common.io.stream.StreamInput) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) ClusterServiceUtils.setState(org.elasticsearch.test.ClusterServiceUtils.setState) ElasticsearchTimeoutException(org.elasticsearch.ElasticsearchTimeoutException) SetOnce(org.apache.lucene.util.SetOnce) CountDownLatch(java.util.concurrent.CountDownLatch) TransportException(org.elasticsearch.transport.TransportException)

Example 37 with TransportException

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

the class ShardStateAction method sendShardAction.

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

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

            @Override
            public void handleException(TransportException exp) {
                if (isMasterChannelException(exp)) {
                    waitForNewMasterAndRetry(actionName, observer, request, listener, changePredicate);
                } else {
                    LOGGER.warn(new ParameterizedMessage("unexpected failure while sending request [{}] to [{}] for shard entry [{}]", actionName, masterNode, request), 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) FailedToCommitClusterStateException(org.elasticsearch.cluster.coordination.FailedToCommitClusterStateException) RemoteTransportException(org.elasticsearch.transport.RemoteTransportException) TransportException(org.elasticsearch.transport.TransportException) NotMasterException(org.elasticsearch.cluster.NotMasterException) IOException(java.io.IOException) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) EmptyTransportResponseHandler(org.elasticsearch.transport.EmptyTransportResponseHandler)

Example 38 with TransportException

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

the class SyncedFlushService method sendSyncRequests.

void sendSyncRequests(final String syncId, final List<ShardRouting> shards, ClusterState state, Map<String, PreSyncedFlushResponse> preSyncResponses, final ShardId shardId, final int totalShards, final ActionListener<ShardsSyncedFlushResult> listener) {
    final CountDown countDown = new CountDown(shards.size());
    final Map<ShardRouting, ShardSyncedFlushResponse> results = ConcurrentCollections.newConcurrentMap();
    final int numDocsOnPrimary = numDocsOnPrimary(shards, preSyncResponses);
    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"));
            countDownAndSendResponseIfDone(syncId, shards, shardId, totalShards, listener, countDown, results);
            continue;
        }
        final PreSyncedFlushResponse preSyncedResponse = preSyncResponses.get(shard.currentNodeId());
        if (preSyncedResponse == 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"));
            countDownAndSendResponseIfDone(syncId, shards, shardId, totalShards, listener, countDown, results);
            continue;
        }
        if (preSyncedResponse.numDocs != numDocsOnPrimary && preSyncedResponse.numDocs != PreSyncedFlushResponse.UNKNOWN_NUM_DOCS && numDocsOnPrimary != PreSyncedFlushResponse.UNKNOWN_NUM_DOCS) {
            LOGGER.warn("{} can't to issue sync id [{}] for out of sync replica [{}] with num docs [{}]; num docs on primary [{}]", shardId, syncId, shard, preSyncedResponse.numDocs, numDocsOnPrimary);
            results.put(shard, new ShardSyncedFlushResponse("out of sync replica; " + "num docs on replica [" + preSyncedResponse.numDocs + "]; num docs on primary [" + numDocsOnPrimary + "]"));
            countDownAndSendResponseIfDone(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, preSyncedResponse.commitId), new TransportResponseHandler<ShardSyncedFlushResponse>() {

            @Override
            public ShardSyncedFlushResponse read(StreamInput in) throws IOException {
                return new ShardSyncedFlushResponse(in);
            }

            @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
                countDownAndSendResponseIfDone(syncId, shards, shardId, totalShards, listener, countDown, results);
            }

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

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

Example 39 with TransportException

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

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, PreSyncedFlushResponse>> listener) {
    final CountDown countDown = new CountDown(shards.size());
    final ConcurrentMap<String, PreSyncedFlushResponse> presyncResponses = 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(presyncResponses);
            }
            continue;
        }
        transportService.sendRequest(node, PRE_SYNCED_FLUSH_ACTION_NAME, new PreShardSyncedFlushRequest(shard.shardId()), new TransportResponseHandler<PreSyncedFlushResponse>() {

            @Override
            public PreSyncedFlushResponse read(StreamInput in) throws IOException {
                return new PreSyncedFlushResponse(in);
            }

            @Override
            public void handleResponse(PreSyncedFlushResponse response) {
                PreSyncedFlushResponse existing = presyncResponses.putIfAbsent(node.getId(), response);
                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(presyncResponses);
                }
            }

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

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

Example 40 with TransportException

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

the class SyncedFlushService method getInflightOpsCount.

/**
 * returns the number of in flight operations on primary. -1 upon error.
 */
protected void getInflightOpsCount(final ShardId shardId, ClusterState state, IndexShardRoutingTable shardRoutingTable, final ActionListener<InFlightOpsResponse> listener) {
    try {
        final ShardRouting primaryShard = shardRoutingTable.primaryShard();
        final DiscoveryNode primaryNode = state.nodes().get(primaryShard.currentNodeId());
        if (primaryNode == null) {
            LOGGER.trace("{} failed to resolve node for primary shard {}, skipping sync", shardId, primaryShard);
            listener.onResponse(new InFlightOpsResponse(-1));
            return;
        }
        LOGGER.trace("{} retrieving in flight operation count", shardId);
        transportService.sendRequest(primaryNode, IN_FLIGHT_OPS_ACTION_NAME, new InFlightOpsRequest(shardId), new TransportResponseHandler<InFlightOpsResponse>() {

            @Override
            public InFlightOpsResponse read(StreamInput in) throws IOException {
                return new InFlightOpsResponse(in);
            }

            @Override
            public void handleResponse(InFlightOpsResponse response) {
                listener.onResponse(response);
            }

            @Override
            public void handleException(TransportException exp) {
                LOGGER.debug("{} unexpected error while retrieving in flight op count", shardId);
                listener.onFailure(exp);
            }

            @Override
            public String executor() {
                return ThreadPool.Names.SAME;
            }
        });
    } catch (Exception e) {
        listener.onFailure(e);
    }
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) StreamInput(org.elasticsearch.common.io.stream.StreamInput) IOException(java.io.IOException) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) TransportException(org.elasticsearch.transport.TransportException) ElasticsearchException(org.elasticsearch.ElasticsearchException) IndexClosedException(org.elasticsearch.indices.IndexClosedException) ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) TransportException(org.elasticsearch.transport.TransportException) IOException(java.io.IOException)

Aggregations

TransportException (org.elasticsearch.transport.TransportException)46 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)30 IOException (java.io.IOException)28 StreamInput (org.elasticsearch.common.io.stream.StreamInput)17 ElasticsearchException (org.elasticsearch.ElasticsearchException)16 ClusterState (org.elasticsearch.cluster.ClusterState)16 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)15 TransportResponse (org.elasticsearch.transport.TransportResponse)14 TransportResponseHandler (org.elasticsearch.transport.TransportResponseHandler)12 TransportService (org.elasticsearch.transport.TransportService)12 Settings (org.elasticsearch.common.settings.Settings)10 ClusterService (org.elasticsearch.cluster.service.ClusterService)9 ConnectTransportException (org.elasticsearch.transport.ConnectTransportException)9 EmptyTransportResponseHandler (org.elasticsearch.transport.EmptyTransportResponseHandler)9 Version (org.elasticsearch.Version)8 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)8 TimeValue (io.crate.common.unit.TimeValue)7 ArrayList (java.util.ArrayList)7 Consumer (java.util.function.Consumer)7 ClusterStateObserver (org.elasticsearch.cluster.ClusterStateObserver)7