Search in sources :

Example 1 with HostAddress

use of io.trino.spi.HostAddress in project trino by trinodb.

the class SystemSplitManager method getSplits.

@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorTableHandle tableHandle, SplitSchedulingStrategy splitSchedulingStrategy, DynamicFilter dynamicFilter) {
    SystemTableHandle table = (SystemTableHandle) tableHandle;
    TupleDomain<ColumnHandle> constraint = table.getConstraint();
    SystemTable systemTable = tables.getSystemTable(session, table.getSchemaTableName()).orElseThrow(() -> new TableNotFoundException(table.getSchemaTableName()));
    Distribution tableDistributionMode = systemTable.getDistribution();
    if (tableDistributionMode == SINGLE_COORDINATOR) {
        HostAddress address = nodeManager.getCurrentNode().getHostAndPort();
        ConnectorSplit split = new SystemSplit(address, constraint);
        return new FixedSplitSource(ImmutableList.of(split));
    }
    ImmutableList.Builder<ConnectorSplit> splits = ImmutableList.builder();
    ImmutableSet.Builder<InternalNode> nodes = ImmutableSet.builder();
    if (tableDistributionMode == ALL_COORDINATORS) {
        nodes.addAll(nodeManager.getCoordinators());
    } else if (tableDistributionMode == ALL_NODES) {
        nodes.addAll(nodeManager.getNodes(ACTIVE));
    }
    Set<InternalNode> nodeSet = nodes.build();
    for (InternalNode node : nodeSet) {
        splits.add(new SystemSplit(node.getHostAndPort(), constraint));
    }
    return new FixedSplitSource(splits.build());
}
Also used : ColumnHandle(io.trino.spi.connector.ColumnHandle) ImmutableList(com.google.common.collect.ImmutableList) HostAddress(io.trino.spi.HostAddress) TableNotFoundException(io.trino.spi.connector.TableNotFoundException) ImmutableSet(com.google.common.collect.ImmutableSet) FixedSplitSource(io.trino.spi.connector.FixedSplitSource) Distribution(io.trino.spi.connector.SystemTable.Distribution) SystemTable(io.trino.spi.connector.SystemTable) InternalNode(io.trino.metadata.InternalNode) ConnectorSplit(io.trino.spi.connector.ConnectorSplit)

Example 2 with HostAddress

use of io.trino.spi.HostAddress in project trino by trinodb.

the class TopologyAwareNodeSelector method computeAssignments.

@Override
public SplitPlacementResult computeAssignments(Set<Split> splits, List<RemoteTask> existingTasks) {
    NodeMap nodeMap = this.nodeMap.get().get();
    Multimap<InternalNode, Split> assignment = HashMultimap.create();
    NodeAssignmentStats assignmentStats = new NodeAssignmentStats(nodeTaskMap, nodeMap, existingTasks);
    int[] topologicCounters = new int[topologicalSplitCounters.size()];
    Set<NetworkLocation> filledLocations = new HashSet<>();
    Set<InternalNode> blockedExactNodes = new HashSet<>();
    boolean splitWaitingForAnyNode = false;
    for (Split split : splits) {
        SplitWeight splitWeight = split.getSplitWeight();
        if (!split.isRemotelyAccessible()) {
            List<InternalNode> candidateNodes = selectExactNodes(nodeMap, split.getAddresses(), includeCoordinator);
            if (candidateNodes.isEmpty()) {
                log.debug("No nodes available to schedule %s. Available nodes %s", split, nodeMap.getNodesByHost().keys());
                throw new TrinoException(NO_NODES_AVAILABLE, "No nodes available to run query");
            }
            InternalNode chosenNode = bestNodeSplitCount(splitWeight, candidateNodes.iterator(), minCandidates, maxPendingSplitsWeightPerTask, assignmentStats);
            if (chosenNode != null) {
                assignment.put(chosenNode, split);
                assignmentStats.addAssignedSplit(chosenNode, splitWeight);
            } else // Exact node set won't matter, if a split is waiting for any node
            if (!splitWaitingForAnyNode) {
                blockedExactNodes.addAll(candidateNodes);
            }
            continue;
        }
        InternalNode chosenNode = null;
        int depth = topologicalSplitCounters.size() - 1;
        int chosenDepth = 0;
        Set<NetworkLocation> locations = new HashSet<>();
        for (HostAddress host : split.getAddresses()) {
            locations.add(networkTopology.locate(host));
        }
        if (locations.isEmpty()) {
            // Add the root location
            locations.add(ROOT_LOCATION);
            depth = 0;
        }
        // Try each address at progressively shallower network locations
        for (int i = depth; i >= 0 && chosenNode == null; i--) {
            for (NetworkLocation location : locations) {
                // For example, locations which couldn't be located will be at the "root" location
                if (location.getSegments().size() < i) {
                    continue;
                }
                location = location.subLocation(0, i);
                if (filledLocations.contains(location)) {
                    continue;
                }
                Set<InternalNode> nodes = nodeMap.getWorkersByNetworkPath().get(location);
                chosenNode = bestNodeSplitCount(splitWeight, new ResettableRandomizedIterator<>(nodes), minCandidates, calculateMaxPendingSplitsWeightPerTask(i, depth), assignmentStats);
                if (chosenNode != null) {
                    chosenDepth = i;
                    break;
                }
                filledLocations.add(location);
            }
        }
        if (chosenNode != null) {
            assignment.put(chosenNode, split);
            assignmentStats.addAssignedSplit(chosenNode, splitWeight);
            topologicCounters[chosenDepth]++;
        } else {
            splitWaitingForAnyNode = true;
        }
    }
    for (int i = 0; i < topologicCounters.length; i++) {
        if (topologicCounters[i] > 0) {
            topologicalSplitCounters.get(i).update(topologicCounters[i]);
        }
    }
    ListenableFuture<Void> blocked;
    long maxPendingForWildcardNetworkAffinity = calculateMaxPendingSplitsWeightPerTask(0, topologicalSplitCounters.size() - 1);
    if (splitWaitingForAnyNode) {
        blocked = toWhenHasSplitQueueSpaceFuture(existingTasks, calculateLowWatermark(maxPendingForWildcardNetworkAffinity));
    } else {
        blocked = toWhenHasSplitQueueSpaceFuture(blockedExactNodes, existingTasks, calculateLowWatermark(maxPendingForWildcardNetworkAffinity));
    }
    return new SplitPlacementResult(blocked, assignment);
}
Also used : HostAddress(io.trino.spi.HostAddress) SplitWeight(io.trino.spi.SplitWeight) TrinoException(io.trino.spi.TrinoException) InternalNode(io.trino.metadata.InternalNode) Split(io.trino.metadata.Split) HashSet(java.util.HashSet)

Example 3 with HostAddress

use of io.trino.spi.HostAddress 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 4 with HostAddress

use of io.trino.spi.HostAddress 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 5 with HostAddress

use of io.trino.spi.HostAddress in project trino by trinodb.

the class TestHostAddressFactory method testToHostAddressList.

@Test
public void testToHostAddressList() throws Exception {
    Set<Host> hosts = ImmutableSet.of(new TestHost(new InetSocketAddress(InetAddress.getByAddress(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }), 3000)), new TestHost(new InetSocketAddress(InetAddress.getByAddress(new byte[] { 1, 2, 3, 4 }), 3000)));
    HostAddressFactory hostAddressFactory = new HostAddressFactory();
    List<HostAddress> list = hostAddressFactory.toHostAddressList(hosts);
    assertEquals(list.toString(), "[[102:304:506:708:90a:b0c:d0e:f10], 1.2.3.4]");
}
Also used : TestHost(com.datastax.driver.core.TestHost) InetSocketAddress(java.net.InetSocketAddress) TestHost(com.datastax.driver.core.TestHost) Host(com.datastax.driver.core.Host) HostAddress(io.trino.spi.HostAddress) Test(org.testng.annotations.Test)

Aggregations

HostAddress (io.trino.spi.HostAddress)24 ImmutableList (com.google.common.collect.ImmutableList)9 ConnectorSplit (io.trino.spi.connector.ConnectorSplit)8 Test (org.testng.annotations.Test)7 InternalNode (io.trino.metadata.InternalNode)6 HashSet (java.util.HashSet)5 List (java.util.List)5 Map (java.util.Map)5 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)4 ImmutableSet (com.google.common.collect.ImmutableSet)4 HashMap (java.util.HashMap)4 Objects.requireNonNull (java.util.Objects.requireNonNull)4 Split (io.trino.metadata.Split)3 TrinoException (io.trino.spi.TrinoException)3 FixedSplitSource (io.trino.spi.connector.FixedSplitSource)3 Objects (java.util.Objects)3 Properties (java.util.Properties)3 Host (com.datastax.driver.core.Host)2 HashMultimap (com.google.common.collect.HashMultimap)2 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)2