org.elasticsearch.transport.TransportException Java Examples

The following examples show how to use org.elasticsearch.transport.TransportException. 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: DisruptableMockTransport.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public Connection openConnection(DiscoveryNode node, ConnectionProfile profile) {
    final Optional<DisruptableMockTransport> matchingTransport = getDisruptableMockTransport(node.getAddress());
    if (matchingTransport.isPresent()) {
        return new CloseableConnection() {
            @Override
            public DiscoveryNode getNode() {
                return node;
            }

            @Override
            public void sendRequest(long requestId, String action, TransportRequest request, TransportRequestOptions options)
                throws TransportException {
                onSendRequest(requestId, action, request, matchingTransport.get());
            }

            @Override
            public String toString() {
                return "DisruptableMockTransportConnection{node=" + node + '}';
            }
        };
    } else {
        throw new ConnectTransportException(node, "node " + node + " does not exist");
    }
}
 
Example #2
Source File: TransportAddVotingConfigExclusionsActionTests.java    From crate with Apache License 2.0 6 votes vote down vote up
public void testReturnsErrorIfNoMatchingNodes() throws InterruptedException {
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    final SetOnce<TransportException> exceptionHolder = new SetOnce<>();

    transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME,
        new AddVotingConfigExclusionsRequest(new String[]{"not-a-node"}),
        expectError(e -> {
            exceptionHolder.set(e);
            countDownLatch.countDown();
        })
    );

    assertTrue(countDownLatch.await(30, TimeUnit.SECONDS));
    final Throwable rootCause = exceptionHolder.get().getRootCause();
    assertThat(rootCause, instanceOf(IllegalArgumentException.class));
    assertThat(rootCause.getMessage(),
        equalTo("add voting config exclusions request for [not-a-node] matched no master-eligible nodes"));
}
 
Example #3
Source File: MockTransport.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public Connection openConnection(DiscoveryNode node, ConnectionProfile profile) {
    return new CloseableConnection() {
        @Override
        public DiscoveryNode getNode() {
            return node;
        }

        @Override
        public void sendRequest(long requestId, String action, TransportRequest request, TransportRequestOptions options)
            throws TransportException {
            requests.put(requestId, Tuple.tuple(node, action));
            onSendRequest(requestId, action, request, node);
        }

        @Override
        public String toString() {
            return "MockTransportConnection{node=" + node + ", requests=" + requests + '}';
        }
    };
}
 
Example #4
Source File: JoinHelper.java    From crate with Apache License 2.0 6 votes vote down vote up
void sendValidateJoinRequest(DiscoveryNode node, ClusterState state, ActionListener<TransportResponse.Empty> listener) {
    transportService.sendRequest(node, VALIDATE_JOIN_ACTION_NAME,
        new ValidateJoinRequest(state),
        TransportRequestOptions.builder().withTimeout(joinTimeout).build(),
        new EmptyTransportResponseHandler(ThreadPool.Names.GENERIC) {
            @Override
            public void handleResponse(TransportResponse.Empty response) {
                listener.onResponse(response);
            }

            @Override
            public void handleException(TransportException exp) {
                listener.onFailure(exp);
            }
        });
}
 
Example #5
Source File: TransportAddVotingConfigExclusionsActionTests.java    From crate with Apache License 2.0 6 votes vote down vote up
public void testOnlyMatchesMasterEligibleNodes() throws InterruptedException {
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    final SetOnce<TransportException> exceptionHolder = new SetOnce<>();

    transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME,
        new AddVotingConfigExclusionsRequest(new String[]{"_all", "master:false"}),
        expectError(e -> {
            exceptionHolder.set(e);
            countDownLatch.countDown();
        })
    );

    assertTrue(countDownLatch.await(30, TimeUnit.SECONDS));
    final Throwable rootCause = exceptionHolder.get().getRootCause();
    assertThat(rootCause, instanceOf(IllegalArgumentException.class));
    assertThat(rootCause.getMessage(),
        equalTo("add voting config exclusions request for [_all, master:false] matched no master-eligible nodes"));
}
 
Example #6
Source File: TransportAddVotingConfigExclusionsActionTests.java    From crate with Apache License 2.0 6 votes vote down vote up
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}"));
}
 
Example #7
Source File: JoinHelperTests.java    From crate with Apache License 2.0 6 votes vote down vote up
public void testFailedJoinAttemptLogLevel() {
    assertThat(JoinHelper.FailedJoinAttempt.getLogLevel(new TransportException("generic transport exception")), is(Level.INFO));

    assertThat(JoinHelper.FailedJoinAttempt.getLogLevel(
            new RemoteTransportException("remote transport exception with generic cause", new Exception())), is(Level.INFO));

    assertThat(JoinHelper.FailedJoinAttempt.getLogLevel(
            new RemoteTransportException("caused by CoordinationStateRejectedException",
                    new CoordinationStateRejectedException("test"))), is(Level.DEBUG));

    assertThat(JoinHelper.FailedJoinAttempt.getLogLevel(
            new RemoteTransportException("caused by FailedToCommitClusterStateException",
                    new FailedToCommitClusterStateException("test"))), is(Level.DEBUG));

    assertThat(JoinHelper.FailedJoinAttempt.getLogLevel(
            new RemoteTransportException("caused by NotMasterException",
                    new NotMasterException("test"))), is(Level.DEBUG));
}
 
Example #8
Source File: TransportAddVotingConfigExclusionsActionTests.java    From crate with Apache License 2.0 6 votes vote down vote up
private TransportResponseHandler<AddVotingConfigExclusionsResponse> responseHandler(
    Consumer<AddVotingConfigExclusionsResponse> onResponse, Consumer<TransportException> onException) {
    return new TransportResponseHandler<AddVotingConfigExclusionsResponse>() {
        @Override
        public void handleResponse(AddVotingConfigExclusionsResponse response) {
            onResponse.accept(response);
        }

        @Override
        public void handleException(TransportException exp) {
            onException.accept(exp);
        }

        @Override
        public String executor() {
            return Names.SAME;
        }

        @Override
        public AddVotingConfigExclusionsResponse read(StreamInput in) throws IOException {
            return new AddVotingConfigExclusionsResponse(in);
        }
    };
}
 
Example #9
Source File: TransportClearVotingConfigExclusionsActionTests.java    From crate with Apache License 2.0 6 votes vote down vote up
public void testTimesOutIfWaitingForNodesThatAreNotRemoved() throws InterruptedException {
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    final SetOnce<TransportException> responseHolder = new SetOnce<>();

    final ClearVotingConfigExclusionsRequest clearVotingConfigExclusionsRequest = new ClearVotingConfigExclusionsRequest();
    clearVotingConfigExclusionsRequest.setTimeout(TimeValue.timeValueMillis(100));
    transportService.sendRequest(localNode, ClearVotingConfigExclusionsAction.NAME,
        clearVotingConfigExclusionsRequest,
        expectError(e -> {
            responseHolder.set(e);
            countDownLatch.countDown();
        })
    );

    assertTrue(countDownLatch.await(30, TimeUnit.SECONDS));
    assertThat(clusterService.getClusterApplierService().state().getVotingConfigExclusions(),
            containsInAnyOrder(otherNode1Exclusion, otherNode2Exclusion));
    final Throwable rootCause = responseHolder.get().getRootCause();
    assertThat(rootCause, instanceOf(ElasticsearchTimeoutException.class));
    assertThat(rootCause.getMessage(),
        startsWith("timed out waiting for removal of nodes; if nodes should not be removed, set waitForRemoval to false. ["));
}
 
Example #10
Source File: ReplicationOperation.java    From crate with Apache License 2.0 6 votes vote down vote up
private void onNoLongerPrimary(Exception failure) {
    final Throwable cause = ExceptionsHelper.unwrapCause(failure);
    final boolean nodeIsClosing =
        cause instanceof NodeClosedException ||
        (cause instanceof TransportException && "TransportService is closed stopped can't send request".equals(cause.getMessage()));

    final String message;
    if (nodeIsClosing) {
        message = String.format(Locale.ROOT,
            "node with primary [%s] is shutting down while failing replica shard", primary.routingEntry());
        // We prefer not to fail the primary to avoid unnecessary warning log
        // when the node with the primary shard is gracefully shutting down.
    } else {
        if (Assertions.ENABLED) {
            if (failure instanceof ShardStateAction.NoLongerPrimaryShardException == false) {
                throw new AssertionError("unexpected failure", failure);
            }
        }
        // we are no longer the primary, fail ourselves and start over
        message = String.format(Locale.ROOT, "primary shard [%s] was demoted while failing replica shard", primary.routingEntry());
        primary.failShard(message, failure);
    }
    finishAsFailed(new RetryOnPrimaryException(primary.routingEntry().shardId(), message, failure));
}
 
Example #11
Source File: TransportClearVotingConfigExclusionsActionTests.java    From crate with Apache License 2.0 6 votes vote down vote up
private TransportResponseHandler<ClearVotingConfigExclusionsResponse> responseHandler(
    Consumer<ClearVotingConfigExclusionsResponse> onResponse, Consumer<TransportException> onException) {
    return new TransportResponseHandler<ClearVotingConfigExclusionsResponse>() {
        @Override
        public void handleResponse(ClearVotingConfigExclusionsResponse response) {
            onResponse.accept(response);
        }

        @Override
        public void handleException(TransportException exp) {
            onException.accept(exp);
        }

        @Override
        public String executor() {
            return Names.SAME;
        }

        @Override
        public ClearVotingConfigExclusionsResponse read(StreamInput in) throws IOException {
            return new ClearVotingConfigExclusionsResponse(in);
        }
    };
}
 
Example #12
Source File: TransportBroadcastByNodeAction.java    From crate with Apache License 2.0 5 votes vote down vote up
private void sendNodeRequest(final DiscoveryNode node, List<ShardRouting> shards, final int nodeIndex) {
    try {
        NodeRequest nodeRequest = new NodeRequest(node.getId(), request, shards);
        if (task != null) {
            nodeRequest.setParentTask(clusterService.localNode().getId(), task.getId());
        }
        transportService.sendRequest(node, transportNodeBroadcastAction, nodeRequest, new TransportResponseHandler<NodeResponse>() {

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

            @Override
            public void handleResponse(NodeResponse response) {
                onNodeResponse(node, nodeIndex, response);
            }

            @Override
            public void handleException(TransportException exp) {
                onNodeFailure(node, nodeIndex, exp);
            }

            @Override
            public String executor() {
                return ThreadPool.Names.SAME;
            }
        });
    } catch (Exception e) {
        onNodeFailure(node, nodeIndex, e);
    }
}
 
Example #13
Source File: SnapshotShardsService.java    From crate with Apache License 2.0 5 votes vote down vote up
/** Updates the shard snapshot status by sending a {@link UpdateIndexShardSnapshotStatusRequest} to the master node */
private void sendSnapshotShardUpdate(final Snapshot snapshot, final ShardId shardId, final ShardSnapshotStatus status) {
    remoteFailedRequestDeduplicator.executeOnce(
        new UpdateIndexShardSnapshotStatusRequest(snapshot, shardId, status),
        new ActionListener<>() {
            @Override
            public void onResponse(Void aVoid) {
                LOGGER.trace("[{}] [{}] updated snapshot state", snapshot, status);
            }

            @Override
            public void onFailure(Exception e) {
                LOGGER.warn(
                    () -> new ParameterizedMessage("[{}] [{}] failed to update snapshot state", snapshot, status), e);
            }
        },
        (req, reqListener) -> transportService.sendRequest(transportService.getLocalNode(), UPDATE_SNAPSHOT_STATUS_ACTION_NAME, req,
            new TransportResponseHandler<UpdateIndexShardSnapshotStatusResponse>() {
                @Override
                public UpdateIndexShardSnapshotStatusResponse read(StreamInput in) throws IOException {
                    return new UpdateIndexShardSnapshotStatusResponse();
                }

                @Override
                public void handleResponse(UpdateIndexShardSnapshotStatusResponse response) {
                    reqListener.onResponse(null);
                }

                @Override
                public void handleException(TransportException exp) {
                    reqListener.onFailure(exp);
                }

                @Override
                public String executor() {
                    return ThreadPool.Names.SAME;
                }
            })
    );
}
 
Example #14
Source File: PublicationTests.java    From crate with Apache License 2.0 5 votes vote down vote up
public void testClusterStatePublishingFailsOrTimesOutBeforeCommit() throws InterruptedException {
    VotingConfiguration config = new VotingConfiguration(Sets.newHashSet(n1.getId(), n2.getId()));
    initializeCluster(config);

    AssertingAckListener ackListener = new AssertingAckListener(nodes.size());
    DiscoveryNodes discoveryNodes = DiscoveryNodes.builder().add(n1).add(n2).add(n3).localNodeId(n1.getId()).build();
    MockPublication publication = node1.publish(CoordinationStateTests.clusterState(1L, 2L,
        discoveryNodes, config, config, 42L), ackListener, Collections.emptySet());

    boolean timeOut = randomBoolean();
    publication.pendingPublications.entrySet().stream().collect(shuffle()).forEach(e -> {
        if (e.getKey().equals(n2)) {
            if (timeOut) {
                publication.cancel("timed out");
            } else {
                e.getValue().onFailure(new TransportException(new Exception("dummy failure")));
            }
            assertTrue(publication.completed);
            assertFalse(publication.committed);
        } else if (randomBoolean()) {
            PublishResponse publishResponse = nodeResolver.apply(e.getKey()).coordinationState.handlePublishRequest(
                publication.publishRequest);
            e.getValue().onResponse(new PublishWithJoinResponse(publishResponse, Optional.empty()));
        }
    });

    assertThat(publication.pendingCommits.keySet(), equalTo(Collections.emptySet()));
    assertNull(publication.applyCommit);
    assertTrue(publication.completed);
    assertFalse(publication.committed);

    List<Tuple<DiscoveryNode, Throwable>> errors = ackListener.awaitErrors(0L, TimeUnit.SECONDS);
    assertThat(errors.size(), equalTo(3));
    assertThat(errors.stream().map(Tuple::v1).collect(Collectors.toList()), containsInAnyOrder(n1, n2, n3));
    errors.stream().forEach(tuple ->
        assertThat(tuple.v2().getMessage(), containsString(timeOut ? "timed out" :
            tuple.v1().equals(n2) ? "dummy failure" : "non-failed nodes do not form a quorum")));
}
 
Example #15
Source File: ShardStateAction.java    From crate with Apache License 2.0 5 votes vote down vote up
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);
                    }
                }
            });
    }
}
 
Example #16
Source File: StubbableTransport.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public void sendRequest(long requestId, String action, TransportRequest request, TransportRequestOptions options)
    throws IOException, TransportException {
    TransportAddress address = connection.getNode().getAddress();
    SendRequestBehavior behavior = sendBehaviors.getOrDefault(address, defaultSendRequest);
    if (behavior == null) {
        connection.sendRequest(requestId, action, request, options);
    } else {
        behavior.sendRequest(connection, requestId, action, request, options);
    }
}
 
Example #17
Source File: JoinHelper.java    From crate with Apache License 2.0 5 votes vote down vote up
static Level getLogLevel(TransportException e) {
    Throwable cause = e.unwrapCause();
    if (cause instanceof CoordinationStateRejectedException ||
        cause instanceof FailedToCommitClusterStateException ||
        cause instanceof NotMasterException) {
        return Level.DEBUG;
    }
    return Level.INFO;
}
 
Example #18
Source File: TransportReplicationAction.java    From crate with Apache License 2.0 5 votes vote down vote up
private void performAction(final DiscoveryNode node, final String action, final boolean isPrimaryAction,
                           final TransportRequest requestToPerform) {
    transportService.sendRequest(node, action, requestToPerform, transportOptions, new TransportResponseHandler<Response>() {

        @Override
        public Response read(StreamInput in) throws IOException {
            return TransportReplicationAction.this.read(in);
        }

        @Override
        public String executor() {
            return ThreadPool.Names.SAME;
        }

        @Override
        public void handleResponse(Response response) {
            finishOnSuccess(response);
        }

        @Override
        public void handleException(TransportException exp) {
            try {
                // if we got disconnected from the node, or the node / shard is not in the right state (being closed)
                final Throwable cause = exp.unwrapCause();
                if (cause instanceof ConnectTransportException || cause instanceof NodeClosedException ||
                    (isPrimaryAction && retryPrimaryException(cause))) {
                    logger.trace(() -> new ParameterizedMessage(
                            "received an error from node [{}] for request [{}], scheduling a retry",
                            node.getId(), requestToPerform), exp);
                    retry(exp);
                } else {
                    finishAsFailed(exp);
                }
            } catch (Exception e) {
                e.addSuppressed(exp);
                finishWithUnexpectedFailure(e);
            }
        }
    });
}
 
Example #19
Source File: PreVoteCollector.java    From crate with Apache License 2.0 5 votes vote down vote up
void start(final Iterable<DiscoveryNode> broadcastNodes) {
    LOGGER.debug("{} requesting pre-votes from {}", this, broadcastNodes);
    broadcastNodes.forEach(n -> transportService.sendRequest(n, REQUEST_PRE_VOTE_ACTION_NAME, preVoteRequest,
        new TransportResponseHandler<PreVoteResponse>() {
            @Override
            public PreVoteResponse read(StreamInput in) throws IOException {
                return new PreVoteResponse(in);
            }

            @Override
            public void handleResponse(PreVoteResponse response) {
                handlePreVoteResponse(response, n);
            }

            @Override
            public void handleException(TransportException exp) {
                LOGGER.debug(new ParameterizedMessage("{} failed", this), exp);
            }

            @Override
            public String executor() {
                return Names.GENERIC;
            }

            @Override
            public String toString() {
                return "TransportResponseHandler{" + PreVoteCollector.this + ", node=" + n + '}';
            }
        }));
}
 
Example #20
Source File: LocalAllocateDangledIndices.java    From crate with Apache License 2.0 5 votes vote down vote up
public void allocateDangled(Collection<IndexMetaData> indices, final Listener listener) {
    ClusterState clusterState = clusterService.state();
    DiscoveryNode masterNode = clusterState.nodes().getMasterNode();
    if (masterNode == null) {
        listener.onFailure(new MasterNotDiscoveredException("no master to send allocate dangled request"));
        return;
    }
    AllocateDangledRequest request = new AllocateDangledRequest(clusterService.localNode(),
        indices.toArray(new IndexMetaData[indices.size()]));
    transportService.sendRequest(masterNode, ACTION_NAME, request, new TransportResponseHandler<AllocateDangledResponse>() {
        @Override
        public AllocateDangledResponse read(StreamInput in) throws IOException {
            return new AllocateDangledResponse(in);
        }

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

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

        @Override
        public String executor() {
            return ThreadPool.Names.SAME;
        }
    });
}
 
Example #21
Source File: IndicesStore.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public void handleException(TransportException exp) {
    LOGGER.debug(() -> new ParameterizedMessage("shards active request failed for {}", shardId), exp);
    if (awaitingResponses.decrementAndGet() == 0) {
        allNodesResponded();
    }
}
 
Example #22
Source File: SyncedFlushService.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #23
Source File: TransportBroadcastByNodeAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private void sendNodeRequest(final DiscoveryNode node, List<ShardRouting> shards, final int nodeIndex) {
    try {
        NodeRequest nodeRequest = new NodeRequest(node.getId(), request, shards);
        if (task != null) {
            nodeRequest.setParentTask(clusterService.localNode().id(), task.getId());
            taskManager.registerChildTask(task, node.getId());
        }
        transportService.sendRequest(node, transportNodeBroadcastAction, nodeRequest, new BaseTransportResponseHandler<NodeResponse>() {
            @Override
            public NodeResponse newInstance() {
                return new NodeResponse();
            }

            @Override
            public void handleResponse(NodeResponse response) {
                onNodeResponse(node, nodeIndex, response);
            }

            @Override
            public void handleException(TransportException exp) {
                onNodeFailure(node, nodeIndex, exp);
            }

            @Override
            public String executor() {
                return ThreadPool.Names.SAME;
            }
        });
    } catch (Throwable e) {
        onNodeFailure(node, nodeIndex, e);
    }
}
 
Example #24
Source File: TransportCancelTasksAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private void sendSetBanRequest(Set<String> nodes, BanParentTaskRequest request, final BanLock banLock) {
    ClusterState clusterState = clusterService.state();
    for (String node : nodes) {
        DiscoveryNode discoveryNode = clusterState.getNodes().get(node);
        if (discoveryNode != null && discoveryNode.version().onOrAfter(Version.V_2_3_0)) {
            // Check if node still in the cluster
            logger.debug("Sending ban for tasks with the parent [{}] to the node [{}], ban [{}]", request.parentTaskId, node,
                request.ban);
            transportService.sendRequest(discoveryNode, BAN_PARENT_ACTION_NAME, request,
                new EmptyTransportResponseHandler(ThreadPool.Names.SAME) {
                    @Override
                    public void handleResponse(TransportResponse.Empty response) {
                        banLock.onBanSet();
                    }

                    @Override
                    public void handleException(TransportException exp) {
                        banLock.onBanSet();
                    }
                });
        } else {
            banLock.onBanSet();
            logger.debug("Cannot send ban for tasks with the parent [{}] to the node [{}] - the node no longer in the cluster or has an old version",
                request.parentTaskId, node);
        }
    }
}
 
Example #25
Source File: ShardStateAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public void shardStarted(final ShardRouting shardRouting, String indexUUID, final String reason, final DiscoveryNode masterNode) {
    ShardRoutingEntry shardRoutingEntry = new ShardRoutingEntry(shardRouting, indexUUID, reason, clusterService.state().nodes().localNodeId(), null);
    logger.debug("{} sending shard started for {}", shardRoutingEntry.shardRouting.shardId(), shardRoutingEntry);
    transportService.sendRequest(masterNode,
            SHARD_STARTED_ACTION_NAME, new ShardRoutingEntry(shardRouting, indexUUID, reason, clusterService.state().nodes().localNodeId(), null), new EmptyTransportResponseHandler(ThreadPool.Names.SAME) {
                @Override
                public void handleException(TransportException exp) {
                    logger.warn("failed to send shard started to [{}]", exp, masterNode);
                }

            });
}
 
Example #26
Source File: ShardStateAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private void innerShardFailed(final ShardRouting shardRouting, final String indexUUID, final DiscoveryNode masterNode, final String message, final Throwable failure) {
    ShardRoutingEntry shardRoutingEntry = new ShardRoutingEntry(shardRouting, indexUUID, message, clusterService.state().nodes().localNodeId(), failure);
    transportService.sendRequest(masterNode,
            SHARD_FAILED_ACTION_NAME, shardRoutingEntry, new EmptyTransportResponseHandler(ThreadPool.Names.SAME) {
                @Override
                public void handleException(TransportException exp) {
                    logger.warn("failed to send failed shard to {}", exp, masterNode);
                }
            });
}
 
Example #27
Source File: ESHttpContentDecompressor.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
protected DecoderEmbedder<ChannelBuffer> newContentDecoder(String contentEncoding) throws Exception {
    if (compression) {
        // compression is enabled so handle the request according to the headers (compressed and uncompressed)
        return super.newContentDecoder(contentEncoding);
    } else {
        // if compression is disabled only allow "indentity" (uncompressed) requests
        if (HttpHeaders.Values.IDENTITY.equals(contentEncoding)) {
            // nothing to handle here
            return null;
        } else {
            throw new TransportException("Support for compressed content is disabled. You can enable it with http.compression=true");
        }
    }
}
 
Example #28
Source File: PublishClusterStateVersionAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public void publishClusterStateVersionToNode(final long newVersion,
        final DiscoveryNode node, 
        final TimeValue publishTimeout,
        final BlockingClusterStatePublishResponseHandler publishResponseHandler) {
    try {
        BytesStreamOutput bStream = new BytesStreamOutput();
        bStream.writeLong(newVersion);
        clusterService.localNode().writeTo(bStream);
        bStream.writeString(node.getId());
        BytesReference nodeBytes = bStream.bytes();
        TransportRequestOptions options = TransportRequestOptions.builder().withType(TransportRequestOptions.Type.STATE).withCompress(false).withTimeout(publishTimeout).build();
        transportService.sendRequest(node, PUBLISH_VERSION_ACTION_NAME, new BytesTransportRequest(nodeBytes, node.version()), 
                options, 
                new EmptyTransportResponseHandler(ThreadPool.Names.SAME) {
            
            @Override
            public void handleResponse(TransportResponse.Empty response) {
                publishResponseHandler.onResponse(node);
            }
            
            @Override
            public void handleException(TransportException exp) {
                logger.debug("failed to send cluster state to {}, version {}", exp, node, newVersion);
                publishResponseHandler.onFailure(node, exp);
            }
        });
    } catch (Throwable t) {
        logger.warn("error sending cluster state to {}", t, node);
        publishResponseHandler.onFailure(node, t);
    }
}
 
Example #29
Source File: TransportAddVotingConfigExclusionsActionTests.java    From crate with Apache License 2.0 4 votes vote down vote up
private TransportResponseHandler<AddVotingConfigExclusionsResponse> expectError(Consumer<TransportException> onException) {
    return responseHandler(r -> {
        assert false : r;
    }, onException);
}
 
Example #30
Source File: LeaderCheckerTests.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public void handleException(TransportException exp) {
    transportException = exp;
}