Search in sources :

Example 6 with InternalNode

use of io.trino.metadata.InternalNode in project trino by trinodb.

the class TopologyAwareNodeSelector method bestNodeSplitCount.

@Nullable
private InternalNode bestNodeSplitCount(SplitWeight splitWeight, Iterator<InternalNode> candidates, int minCandidatesWhenFull, long maxPendingSplitsWeightPerTask, NodeAssignmentStats assignmentStats) {
    InternalNode bestQueueNotFull = null;
    long minWeight = Long.MAX_VALUE;
    int fullCandidatesConsidered = 0;
    while (candidates.hasNext() && (fullCandidatesConsidered < minCandidatesWhenFull || bestQueueNotFull == null)) {
        InternalNode node = candidates.next();
        if (assignmentStats.getUnacknowledgedSplitCountForStage(node) >= maxUnacknowledgedSplitsPerTask) {
            fullCandidatesConsidered++;
            continue;
        }
        if (canAssignSplitBasedOnWeight(assignmentStats.getTotalSplitsWeight(node), maxSplitsWeightPerNode, splitWeight)) {
            return node;
        }
        fullCandidatesConsidered++;
        long taskQueuedWeight = assignmentStats.getQueuedSplitsWeightForStage(node);
        if (taskQueuedWeight < minWeight && canAssignSplitBasedOnWeight(taskQueuedWeight, maxPendingSplitsWeightPerTask, splitWeight)) {
            minWeight = taskQueuedWeight;
            bestQueueNotFull = node;
        }
    }
    return bestQueueNotFull;
}
Also used : InternalNode(io.trino.metadata.InternalNode) Nullable(javax.annotation.Nullable)

Example 7 with InternalNode

use of io.trino.metadata.InternalNode in project trino by trinodb.

the class TopologyAwareNodeSelectorFactory method createNodeMap.

private NodeMap createNodeMap(Optional<CatalogName> catalogName) {
    Set<InternalNode> nodes = catalogName.map(nodeManager::getActiveConnectorNodes).orElseGet(() -> nodeManager.getNodes(ACTIVE));
    Set<String> coordinatorNodeIds = nodeManager.getCoordinators().stream().map(InternalNode::getNodeIdentifier).collect(toImmutableSet());
    ImmutableSetMultimap.Builder<HostAddress, InternalNode> byHostAndPort = ImmutableSetMultimap.builder();
    ImmutableSetMultimap.Builder<InetAddress, InternalNode> byHost = ImmutableSetMultimap.builder();
    ImmutableSetMultimap.Builder<NetworkLocation, InternalNode> workersByNetworkPath = ImmutableSetMultimap.builder();
    for (InternalNode node : nodes) {
        if (includeCoordinator || !coordinatorNodeIds.contains(node.getNodeIdentifier())) {
            NetworkLocation location = networkTopology.locate(node.getHostAndPort());
            for (int i = 0; i <= location.getSegments().size(); i++) {
                workersByNetworkPath.put(location.subLocation(0, i), node);
            }
        }
        try {
            byHostAndPort.put(node.getHostAndPort(), node);
            byHost.put(node.getInternalAddress(), node);
        } catch (UnknownHostException e) {
            if (markInaccessibleNode(node)) {
                LOG.warn(e, "Unable to resolve host name for node: %s", node);
            }
        }
    }
    return new NodeMap(byHostAndPort.build(), byHost.build(), workersByNetworkPath.build(), coordinatorNodeIds);
}
Also used : UnknownHostException(java.net.UnknownHostException) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) HostAddress(io.trino.spi.HostAddress) InternalNode(io.trino.metadata.InternalNode) InetAddress(java.net.InetAddress)

Example 8 with InternalNode

use of io.trino.metadata.InternalNode in project trino by trinodb.

the class UniformNodeSelector method equateDistribution.

/**
 * The method tries to make the distribution of splits more uniform. All nodes are arranged into a maxHeap and a minHeap
 * based on the number of splits that are assigned to them. Splits are redistributed, one at a time, from a maxNode to a
 * minNode until we have as uniform a distribution as possible.
 *
 * @param assignment the node-splits multimap after the first and the second stage
 * @param assignmentStats required to obtain info regarding splits assigned to a node outside the current batch of assignment
 * @param nodeMap to get a list of all nodes to which splits can be assigned
 */
private void equateDistribution(Multimap<InternalNode, Split> assignment, NodeAssignmentStats assignmentStats, NodeMap nodeMap, boolean includeCoordinator) {
    if (assignment.isEmpty()) {
        return;
    }
    Collection<InternalNode> allNodes = nodeMap.getNodesByHostAndPort().values().stream().filter(node -> includeCoordinator || !nodeMap.getCoordinatorNodeIds().contains(node.getNodeIdentifier())).collect(toImmutableList());
    if (allNodes.size() < 2) {
        return;
    }
    IndexedPriorityQueue<InternalNode> maxNodes = new IndexedPriorityQueue<>();
    for (InternalNode node : assignment.keySet()) {
        maxNodes.addOrUpdate(node, assignmentStats.getTotalSplitsWeight(node));
    }
    IndexedPriorityQueue<InternalNode> minNodes = new IndexedPriorityQueue<>();
    for (InternalNode node : allNodes) {
        minNodes.addOrUpdate(node, Long.MAX_VALUE - assignmentStats.getTotalSplitsWeight(node));
    }
    while (true) {
        if (maxNodes.isEmpty()) {
            return;
        }
        // fetch min and max node
        InternalNode maxNode = maxNodes.poll();
        InternalNode minNode = minNodes.poll();
        // misassigned splits greatly (in absolute values).
        if (assignmentStats.getTotalSplitsWeight(maxNode) - assignmentStats.getTotalSplitsWeight(minNode) <= SplitWeight.rawValueForStandardSplitCount(5)) {
            return;
        }
        // move split from max to min
        Split redistributed = redistributeSplit(assignment, maxNode, minNode, nodeMap.getNodesByHost());
        assignmentStats.removeAssignedSplit(maxNode, redistributed.getSplitWeight());
        assignmentStats.addAssignedSplit(minNode, redistributed.getSplitWeight());
        // add max back into maxNodes only if it still has assignments
        if (assignment.containsKey(maxNode)) {
            maxNodes.addOrUpdate(maxNode, assignmentStats.getTotalSplitsWeight(maxNode));
        }
        // Add or update both the Priority Queues with the updated node priorities
        maxNodes.addOrUpdate(minNode, assignmentStats.getTotalSplitsWeight(minNode));
        minNodes.addOrUpdate(minNode, Long.MAX_VALUE - assignmentStats.getTotalSplitsWeight(minNode));
        minNodes.addOrUpdate(maxNode, Long.MAX_VALUE - assignmentStats.getTotalSplitsWeight(maxNode));
    }
}
Also used : InternalNodeManager(io.trino.metadata.InternalNodeManager) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) NodeTaskMap(io.trino.execution.NodeTaskMap) Logger(io.airlift.log.Logger) Multimap(com.google.common.collect.Multimap) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) SplitWeight(io.trino.spi.SplitWeight) InetAddress(java.net.InetAddress) HashSet(java.util.HashSet) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) HashMultimap(com.google.common.collect.HashMultimap) NodeScheduler.randomizedNodes(io.trino.execution.scheduler.NodeScheduler.randomizedNodes) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) Suppliers(com.google.common.base.Suppliers) NodeScheduler.selectNodes(io.trino.execution.scheduler.NodeScheduler.selectNodes) Nullable(javax.annotation.Nullable) ImmutableSet(com.google.common.collect.ImmutableSet) SplitsBalancingPolicy(io.trino.execution.scheduler.NodeSchedulerConfig.SplitsBalancingPolicy) Iterator(java.util.Iterator) Collection(java.util.Collection) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) NodeScheduler.selectDistributionNodes(io.trino.execution.scheduler.NodeScheduler.selectDistributionNodes) RemoteTask(io.trino.execution.RemoteTask) Set(java.util.Set) TrinoException(io.trino.spi.TrinoException) UnknownHostException(java.net.UnknownHostException) SetMultimap(com.google.common.collect.SetMultimap) InternalNode(io.trino.metadata.InternalNode) List(java.util.List) NodeScheduler.selectExactNodes(io.trino.execution.scheduler.NodeScheduler.selectExactNodes) Comparator.comparingLong(java.util.Comparator.comparingLong) IndexedPriorityQueue(io.trino.execution.resourcegroups.IndexedPriorityQueue) Split(io.trino.metadata.Split) Optional(java.util.Optional) NodeScheduler.calculateLowWatermark(io.trino.execution.scheduler.NodeScheduler.calculateLowWatermark) NO_NODES_AVAILABLE(io.trino.spi.StandardErrorCode.NO_NODES_AVAILABLE) VisibleForTesting(com.google.common.annotations.VisibleForTesting) NodeScheduler.toWhenHasSplitQueueSpaceFuture(io.trino.execution.scheduler.NodeScheduler.toWhenHasSplitQueueSpaceFuture) NodeScheduler.getAllNodes(io.trino.execution.scheduler.NodeScheduler.getAllNodes) HostAddress(io.trino.spi.HostAddress) InternalNode(io.trino.metadata.InternalNode) Split(io.trino.metadata.Split) IndexedPriorityQueue(io.trino.execution.resourcegroups.IndexedPriorityQueue)

Example 9 with InternalNode

use of io.trino.metadata.InternalNode in project trino by trinodb.

the class UniformNodeSelectorFactory method createNodeMap.

private NodeMap createNodeMap(Optional<CatalogName> catalogName) {
    Set<InternalNode> nodes = catalogName.map(nodeManager::getActiveConnectorNodes).orElseGet(() -> nodeManager.getNodes(ACTIVE));
    Set<String> coordinatorNodeIds = nodeManager.getCoordinators().stream().map(InternalNode::getNodeIdentifier).collect(toImmutableSet());
    ImmutableSetMultimap.Builder<HostAddress, InternalNode> byHostAndPort = ImmutableSetMultimap.builder();
    ImmutableSetMultimap.Builder<InetAddress, InternalNode> byHost = ImmutableSetMultimap.builder();
    for (InternalNode node : nodes) {
        try {
            byHostAndPort.put(node.getHostAndPort(), node);
            byHost.put(node.getInternalAddress(), node);
        } catch (UnknownHostException e) {
            if (markInaccessibleNode(node)) {
                LOG.warn(e, "Unable to resolve host name for node: %s", node);
            }
        }
    }
    return new NodeMap(byHostAndPort.build(), byHost.build(), ImmutableSetMultimap.of(), coordinatorNodeIds);
}
Also used : UnknownHostException(java.net.UnknownHostException) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) InternalNode(io.trino.metadata.InternalNode) HostAddress(io.trino.spi.HostAddress) InetAddress(java.net.InetAddress)

Example 10 with InternalNode

use of io.trino.metadata.InternalNode in project trino by trinodb.

the class DynamicLifespanScheduler method schedule.

@Override
public SettableFuture<Void> schedule(SourceScheduler scheduler) {
    // Return a new future even if newDriverGroupReady has not finished.
    // Returning the same SettableFuture instance could lead to ListenableFuture retaining too many listener objects.
    checkState(initialScheduled);
    List<Lifespan> recentlyCompletedDriverGroups;
    synchronized (this) {
        recentlyCompletedDriverGroups = ImmutableList.copyOf(this.recentlyCompletedDriverGroups);
        this.recentlyCompletedDriverGroups.clear();
        newDriverGroupReady = SettableFuture.create();
    }
    for (Lifespan driverGroup : recentlyCompletedDriverGroups) {
        if (!driverGroups.hasNext()) {
            break;
        }
        int driverGroupId = driverGroups.nextInt();
        InternalNode nodeForCompletedDriverGroup = bucketNodeMap.getAssignedNode(driverGroup.getId()).orElseThrow(IllegalStateException::new);
        bucketNodeMap.assignBucketToNode(driverGroupId, nodeForCompletedDriverGroup);
        scheduler.startLifespan(Lifespan.driverGroup(driverGroupId), partitionHandles.get(driverGroupId));
    }
    if (!driverGroups.hasNext()) {
        scheduler.noMoreLifespans();
    }
    return newDriverGroupReady;
}
Also used : InternalNode(io.trino.metadata.InternalNode) Lifespan(io.trino.execution.Lifespan)

Aggregations

InternalNode (io.trino.metadata.InternalNode)57 Split (io.trino.metadata.Split)27 Test (org.testng.annotations.Test)25 ConnectorSplit (io.trino.spi.connector.ConnectorSplit)21 LinkedHashSet (java.util.LinkedHashSet)17 ImmutableList (com.google.common.collect.ImmutableList)16 HashSet (java.util.HashSet)16 RemoteTask (io.trino.execution.RemoteTask)12 ImmutableSet (com.google.common.collect.ImmutableSet)9 HostAddress (io.trino.spi.HostAddress)9 List (java.util.List)9 NodeTaskMap (io.trino.execution.NodeTaskMap)8 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)7 InMemoryNodeManager (io.trino.metadata.InMemoryNodeManager)7 InetAddress (java.net.InetAddress)7 UnknownHostException (java.net.UnknownHostException)7 ArrayList (java.util.ArrayList)7 Objects.requireNonNull (java.util.Objects.requireNonNull)7 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)6 SplitWeight (io.trino.spi.SplitWeight)6