Search in sources :

Example 11 with DiscoveryNode

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

the class Routing method forTableOnAllNodes.

public static Routing forTableOnAllNodes(TableIdent tableIdent, DiscoveryNodes nodes) {
    TreeMapBuilder<String, Map<String, List<Integer>>> nodesMapBuilder = TreeMapBuilder.newMapBuilder();
    Map<String, List<Integer>> tableMap = TreeMapBuilder.<String, List<Integer>>newMapBuilder().put(tableIdent.fqn(), Collections.<Integer>emptyList()).map();
    for (DiscoveryNode node : nodes) {
        nodesMapBuilder.put(node.getId(), tableMap);
    }
    return new Routing(nodesMapBuilder.map());
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 12 with DiscoveryNode

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

the class NodeStatsIterator method getNodeStatsContextFromRemoteState.

private CompletableFuture<List<NodeStatsContext>> getNodeStatsContextFromRemoteState(Set<ColumnIdent> toCollect) {
    final CompletableFuture<List<NodeStatsContext>> nodeStatsContextsFuture = new CompletableFuture<>();
    final List<NodeStatsContext> rows = Collections.synchronizedList(new ArrayList<NodeStatsContext>(nodes.size()));
    final AtomicInteger remainingNodesToCollect = new AtomicInteger(nodes.size());
    for (final DiscoveryNode node : nodes) {
        final String nodeId = node.getId();
        final NodeStatsRequest request = new NodeStatsRequest(toCollect);
        transportStatTablesAction.execute(nodeId, request, new ActionListener<NodeStatsResponse>() {

            @Override
            public void onResponse(NodeStatsResponse response) {
                rows.add(response.nodeStatsContext());
                if (remainingNodesToCollect.decrementAndGet() == 0) {
                    nodeStatsContextsFuture.complete(rows);
                }
            }

            @Override
            public void onFailure(Throwable t) {
                if (t instanceof ReceiveTimeoutTransportException) {
                    rows.add(new NodeStatsContext(nodeId, node.name()));
                    if (remainingNodesToCollect.decrementAndGet() == 0) {
                        nodeStatsContextsFuture.complete(rows);
                    }
                } else {
                    nodeStatsContextsFuture.completeExceptionally(t);
                }
            }
        }, TimeValue.timeValueMillis(3000L));
    }
    return nodeStatsContextsFuture;
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) NodeStatsResponse(io.crate.executor.transport.NodeStatsResponse) ReceiveTimeoutTransportException(org.elasticsearch.transport.ReceiveTimeoutTransportException) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NodeStatsRequest(io.crate.executor.transport.NodeStatsRequest) NodeStatsContext(io.crate.operation.reference.sys.node.NodeStatsContext)

Example 13 with DiscoveryNode

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

the class NodeStatsCollectSource method nodeIds.

@Nullable
static Collection<DiscoveryNode> nodeIds(WhereClause whereClause, Collection<DiscoveryNode> nodes, Functions functions) {
    if (!whereClause.hasQuery()) {
        return nodes;
    }
    LocalSysColReferenceResolver localSysColReferenceResolver = new LocalSysColReferenceResolver(ImmutableList.of(SysNodesTableInfo.Columns.NAME, SysNodesTableInfo.Columns.ID));
    EvaluatingNormalizer normalizer = new EvaluatingNormalizer(functions, RowGranularity.DOC, ReplaceMode.COPY, localSysColReferenceResolver, null);
    List<DiscoveryNode> newNodes = new ArrayList<>();
    for (DiscoveryNode node : nodes) {
        String nodeId = node.getId();
        for (RowCollectExpression<NodeStatsContext, ?> expression : localSysColReferenceResolver.expressions()) {
            expression.setNextRow(new NodeStatsContext(nodeId, node.name()));
        }
        Symbol normalized = normalizer.normalize(whereClause.query(), null);
        if (normalized.equals(whereClause.query())) {
            // No local available sys nodes columns in where clause
            return nodes;
        }
        if (WhereClause.canMatch(normalized)) {
            newNodes.add(node);
        }
    }
    return newNodes;
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) EvaluatingNormalizer(io.crate.analyze.EvaluatingNormalizer) Symbol(io.crate.analyze.symbol.Symbol) ArrayList(java.util.ArrayList) NodeStatsContext(io.crate.operation.reference.sys.node.NodeStatsContext) Nullable(org.elasticsearch.common.Nullable)

Example 14 with DiscoveryNode

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

the class NodeStatsCollectSource method getCollector.

@Override
public CrateCollector getCollector(CollectPhase phase, BatchConsumer consumer, JobCollectContext jobCollectContext) {
    RoutedCollectPhase collectPhase = (RoutedCollectPhase) phase;
    if (collectPhase.whereClause().noMatch()) {
        return RowsCollector.empty(consumer);
    }
    Collection<DiscoveryNode> nodes = nodeIds(collectPhase.whereClause(), Lists.newArrayList(clusterService.state().getNodes().iterator()), functions);
    if (nodes.isEmpty()) {
        return RowsCollector.empty(consumer);
    }
    BatchIterator nodeStatsIterator = NodeStatsIterator.newInstance(nodeStatsAction, collectPhase, nodes, inputFactory);
    return BatchIteratorCollectorBridge.newInstance(nodeStatsIterator, consumer);
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) BatchIterator(io.crate.data.BatchIterator) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase)

Example 15 with DiscoveryNode

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

the class CopyStatementPlanner method getExecutionNodes.

private static Collection<String> getExecutionNodes(DiscoveryNodes allNodes, int maxNodes, final Predicate<DiscoveryNode> nodeFilters) {
    final AtomicInteger counter = new AtomicInteger(maxNodes);
    final List<String> nodes = new ArrayList<>(allNodes.size());
    allNodes.dataNodes().values().forEach(new ObjectProcedure<DiscoveryNode>() {

        @Override
        public void apply(DiscoveryNode value) {
            if (nodeFilters.apply(value) && counter.getAndDecrement() > 0) {
                nodes.add(value.getId());
            }
        }
    });
    return nodes;
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

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