Search in sources :

Example 46 with DiscoveryNode

use of org.elasticsearch.cluster.node.DiscoveryNode in project elasticsearch by elastic.

the class RestTasksAction method buildRow.

private void buildRow(Table table, boolean fullId, boolean detailed, DiscoveryNodes discoveryNodes, TaskInfo taskInfo) {
    table.startRow();
    String nodeId = taskInfo.getTaskId().getNodeId();
    DiscoveryNode node = discoveryNodes.get(nodeId);
    table.addCell(taskInfo.getId());
    table.addCell(taskInfo.getAction());
    table.addCell(taskInfo.getTaskId().toString());
    if (taskInfo.getParentTaskId().isSet()) {
        table.addCell(taskInfo.getParentTaskId().toString());
    } else {
        table.addCell("-");
    }
    table.addCell(taskInfo.getType());
    table.addCell(taskInfo.getStartTime());
    table.addCell(dateFormat.print(taskInfo.getStartTime()));
    table.addCell(taskInfo.getRunningTimeNanos());
    table.addCell(TimeValue.timeValueNanos(taskInfo.getRunningTimeNanos()).toString());
    // Node information. Note that the node may be null because it has left the cluster between when we got this response and now.
    table.addCell(fullId ? nodeId : Strings.substring(nodeId, 0, 4));
    table.addCell(node == null ? "-" : node.getHostAddress());
    table.addCell(node.getAddress().address().getPort());
    table.addCell(node == null ? "-" : node.getName());
    table.addCell(node == null ? "-" : node.getVersion().toString());
    if (detailed) {
        table.addCell(taskInfo.getDescription());
    }
    table.endRow();
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode)

Example 47 with DiscoveryNode

use of org.elasticsearch.cluster.node.DiscoveryNode in project elasticsearch by elastic.

the class SnapshotShardsService method syncShardStatsOnNewMaster.

/**
     * Checks if any shards were processed that the new master doesn't know about
     */
private void syncShardStatsOnNewMaster(ClusterChangedEvent event) {
    SnapshotsInProgress snapshotsInProgress = event.state().custom(SnapshotsInProgress.TYPE);
    if (snapshotsInProgress == null) {
        return;
    }
    final String localNodeId = event.state().nodes().getLocalNodeId();
    final DiscoveryNode masterNode = event.state().nodes().getMasterNode();
    for (SnapshotsInProgress.Entry snapshot : snapshotsInProgress.entries()) {
        if (snapshot.state() == State.STARTED || snapshot.state() == State.ABORTED) {
            Map<ShardId, IndexShardSnapshotStatus> localShards = currentSnapshotShards(snapshot.snapshot());
            if (localShards != null) {
                ImmutableOpenMap<ShardId, ShardSnapshotStatus> masterShards = snapshot.shards();
                for (Map.Entry<ShardId, IndexShardSnapshotStatus> localShard : localShards.entrySet()) {
                    ShardId shardId = localShard.getKey();
                    IndexShardSnapshotStatus localShardStatus = localShard.getValue();
                    ShardSnapshotStatus masterShard = masterShards.get(shardId);
                    if (masterShard != null && masterShard.state().completed() == false) {
                        // Master knows about the shard and thinks it has not completed
                        if (localShardStatus.stage() == Stage.DONE) {
                            // but we think the shard is done - we need to make new master know that the shard is done
                            logger.debug("[{}] new master thinks the shard [{}] is not completed but the shard is done locally, updating status on the master", snapshot.snapshot(), shardId);
                            updateIndexShardSnapshotStatus(snapshot.snapshot(), shardId, new ShardSnapshotStatus(localNodeId, State.SUCCESS), masterNode);
                        } else if (localShard.getValue().stage() == Stage.FAILURE) {
                            // but we think the shard failed - we need to make new master know that the shard failed
                            logger.debug("[{}] new master thinks the shard [{}] is not completed but the shard failed locally, updating status on master", snapshot.snapshot(), shardId);
                            updateIndexShardSnapshotStatus(snapshot.snapshot(), shardId, new ShardSnapshotStatus(localNodeId, State.FAILED, localShardStatus.failure()), masterNode);
                        }
                    }
                }
            }
        }
    }
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) IndexShardSnapshotStatus(org.elasticsearch.index.snapshots.IndexShardSnapshotStatus) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) SnapshotsInProgress(org.elasticsearch.cluster.SnapshotsInProgress) ShardSnapshotStatus(org.elasticsearch.cluster.SnapshotsInProgress.ShardSnapshotStatus) IndexShardSnapshotStatus(org.elasticsearch.index.snapshots.IndexShardSnapshotStatus) Map(java.util.Map) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) HashMap(java.util.HashMap) Collections.emptyMap(java.util.Collections.emptyMap) Collections.unmodifiableMap(java.util.Collections.unmodifiableMap)

Example 48 with DiscoveryNode

use of org.elasticsearch.cluster.node.DiscoveryNode in project elasticsearch by elastic.

the class TransportService method handshake.

/**
     * Executes a high-level handshake using the given connection
     * and returns the discovery node of the node the connection
     * was established with. The handshake will fail if the cluster
     * name on the target node doesn't match the local cluster name.
     *
     * @param connection       the connection to a specific node
     * @param handshakeTimeout handshake timeout
     * @param clusterNamePredicate cluster name validation predicate
     * @return the connected node
     * @throws ConnectTransportException if the connection failed
     * @throws IllegalStateException if the handshake failed
     */
public DiscoveryNode handshake(final Transport.Connection connection, final long handshakeTimeout, Predicate<ClusterName> clusterNamePredicate) throws ConnectTransportException {
    final HandshakeResponse response;
    final DiscoveryNode node = connection.getNode();
    try {
        PlainTransportFuture<HandshakeResponse> futureHandler = new PlainTransportFuture<>(new FutureTransportResponseHandler<HandshakeResponse>() {

            @Override
            public HandshakeResponse newInstance() {
                return new HandshakeResponse();
            }
        });
        sendRequest(connection, HANDSHAKE_ACTION_NAME, HandshakeRequest.INSTANCE, TransportRequestOptions.builder().withTimeout(handshakeTimeout).build(), futureHandler);
        response = futureHandler.txGet();
    } catch (Exception e) {
        throw new IllegalStateException("handshake failed with " + node, e);
    }
    if (!clusterNamePredicate.test(response.clusterName)) {
        throw new IllegalStateException("handshake failed, mismatched cluster name [" + response.clusterName + "] - " + node);
    } else if (response.version.isCompatible(localNode.getVersion()) == false) {
        throw new IllegalStateException("handshake failed, incompatible version [" + response.version + "] - " + node);
    }
    return response.discoveryNode;
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException) TaskCancelledException(org.elasticsearch.tasks.TaskCancelledException)

Example 49 with DiscoveryNode

use of org.elasticsearch.cluster.node.DiscoveryNode in project elasticsearch by elastic.

the class TaskManager method storeResult.

/**
     * Stores the task failure
     */
public <Response extends ActionResponse> void storeResult(Task task, Exception error, ActionListener<Response> listener) {
    DiscoveryNode localNode = lastDiscoveryNodes.getLocalNode();
    if (localNode == null) {
        // too early to store anything, shouldn't really be here - just pass the error along
        listener.onFailure(error);
        return;
    }
    final TaskResult taskResult;
    try {
        taskResult = task.result(localNode, error);
    } catch (IOException ex) {
        logger.warn((Supplier<?>) () -> new ParameterizedMessage("couldn't store error {}", ExceptionsHelper.detailedMessage(error)), ex);
        listener.onFailure(ex);
        return;
    }
    taskResultsService.storeResult(taskResult, new ActionListener<Void>() {

        @Override
        public void onResponse(Void aVoid) {
            listener.onFailure(error);
        }

        @Override
        public void onFailure(Exception e) {
            logger.warn((Supplier<?>) () -> new ParameterizedMessage("couldn't store error {}", ExceptionsHelper.detailedMessage(error)), e);
            listener.onFailure(e);
        }
    });
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Supplier(org.apache.logging.log4j.util.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) IOException(java.io.IOException) ElasticsearchException(org.elasticsearch.ElasticsearchException) IOException(java.io.IOException) ElasticsearchTimeoutException(org.elasticsearch.ElasticsearchTimeoutException)

Example 50 with DiscoveryNode

use of org.elasticsearch.cluster.node.DiscoveryNode in project elasticsearch by elastic.

the class TaskManager method storeResult.

/**
     * Stores the task result
     */
public <Response extends ActionResponse> void storeResult(Task task, Response response, ActionListener<Response> listener) {
    DiscoveryNode localNode = lastDiscoveryNodes.getLocalNode();
    if (localNode == null) {
        // too early to store anything, shouldn't really be here - just pass the response along
        logger.warn("couldn't store response {}, the node didn't join the cluster yet", response);
        listener.onResponse(response);
        return;
    }
    final TaskResult taskResult;
    try {
        taskResult = task.result(localNode, response);
    } catch (IOException ex) {
        logger.warn((Supplier<?>) () -> new ParameterizedMessage("couldn't store response {}", response), ex);
        listener.onFailure(ex);
        return;
    }
    taskResultsService.storeResult(taskResult, new ActionListener<Void>() {

        @Override
        public void onResponse(Void aVoid) {
            listener.onResponse(response);
        }

        @Override
        public void onFailure(Exception e) {
            logger.warn((Supplier<?>) () -> new ParameterizedMessage("couldn't store response {}", response), e);
            listener.onFailure(e);
        }
    });
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Supplier(org.apache.logging.log4j.util.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) IOException(java.io.IOException) ElasticsearchException(org.elasticsearch.ElasticsearchException) IOException(java.io.IOException) ElasticsearchTimeoutException(org.elasticsearch.ElasticsearchTimeoutException)

Aggregations

DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)352 ClusterState (org.elasticsearch.cluster.ClusterState)83 ArrayList (java.util.ArrayList)82 Settings (org.elasticsearch.common.settings.Settings)79 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)74 IOException (java.io.IOException)69 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)52 HashMap (java.util.HashMap)45 ShardId (org.elasticsearch.index.shard.ShardId)45 HashSet (java.util.HashSet)43 List (java.util.List)41 TransportAddress (org.elasticsearch.common.transport.TransportAddress)41 CountDownLatch (java.util.concurrent.CountDownLatch)39 MockTransportService (org.elasticsearch.test.transport.MockTransportService)39 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)37 Map (java.util.Map)35 ExecutionException (java.util.concurrent.ExecutionException)35 Version (org.elasticsearch.Version)35 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)31 ClusterName (org.elasticsearch.cluster.ClusterName)30