Search in sources :

Example 1 with ConnectorBucketNodeMap

use of com.facebook.presto.spi.connector.ConnectorBucketNodeMap in project presto by prestodb.

the class NodePartitioningManager method getConnectorBucketNodeMap.

private ConnectorBucketNodeMap getConnectorBucketNodeMap(Session session, PartitioningHandle partitioningHandle) {
    checkArgument(!(partitioningHandle.getConnectorHandle() instanceof SystemPartitioningHandle));
    ConnectorId connectorId = partitioningHandle.getConnectorId().orElseThrow(() -> new IllegalArgumentException("No connector ID for partitioning handle: " + partitioningHandle));
    List<Node> nodes = getNodes(session, connectorId);
    ConnectorNodePartitioningProvider partitioningProvider = partitioningProviderManager.getPartitioningProvider(partitioningHandle.getConnectorId().get());
    ConnectorBucketNodeMap connectorBucketNodeMap = partitioningProvider.getBucketNodeMap(partitioningHandle.getTransactionHandle().orElse(null), session.toConnectorSession(partitioningHandle.getConnectorId().get()), partitioningHandle.getConnectorHandle(), nodes);
    checkArgument(connectorBucketNodeMap != null, "No partition map %s", partitioningHandle);
    return connectorBucketNodeMap;
}
Also used : Node(com.facebook.presto.spi.Node) InternalNode(com.facebook.presto.metadata.InternalNode) ConnectorNodePartitioningProvider(com.facebook.presto.spi.connector.ConnectorNodePartitioningProvider) ConnectorBucketNodeMap(com.facebook.presto.spi.connector.ConnectorBucketNodeMap) ConnectorId(com.facebook.presto.spi.ConnectorId)

Example 2 with ConnectorBucketNodeMap

use of com.facebook.presto.spi.connector.ConnectorBucketNodeMap in project presto by prestodb.

the class NodePartitioningManager method getBucketNodeMap.

public BucketNodeMap getBucketNodeMap(Session session, PartitioningHandle partitioningHandle, boolean preferDynamic) {
    ConnectorBucketNodeMap connectorBucketNodeMap = getConnectorBucketNodeMap(session, partitioningHandle);
    NodeSelectionStrategy nodeSelectionStrategy = connectorBucketNodeMap.getNodeSelectionStrategy();
    switch(nodeSelectionStrategy) {
        case HARD_AFFINITY:
            return new FixedBucketNodeMap(getSplitToBucket(session, partitioningHandle), getFixedMapping(connectorBucketNodeMap), false);
        case SOFT_AFFINITY:
            if (preferDynamic) {
                return new DynamicBucketNodeMap(getSplitToBucket(session, partitioningHandle), connectorBucketNodeMap.getBucketCount(), getFixedMapping(connectorBucketNodeMap));
            }
            return new FixedBucketNodeMap(getSplitToBucket(session, partitioningHandle), getFixedMapping(connectorBucketNodeMap), true);
        case NO_PREFERENCE:
            if (preferDynamic) {
                return new DynamicBucketNodeMap(getSplitToBucket(session, partitioningHandle), connectorBucketNodeMap.getBucketCount());
            }
            return new FixedBucketNodeMap(getSplitToBucket(session, partitioningHandle), createArbitraryBucketToNode(nodeScheduler.createNodeSelector(session, partitioningHandle.getConnectorId().get()).selectRandomNodes(getMaxTasksPerStage(session)), connectorBucketNodeMap.getBucketCount()), false);
        default:
            throw new PrestoException(NODE_SELECTION_NOT_SUPPORTED, format("Unsupported node selection strategy %s", nodeSelectionStrategy));
    }
}
Also used : DynamicBucketNodeMap(com.facebook.presto.execution.scheduler.group.DynamicBucketNodeMap) ConnectorBucketNodeMap(com.facebook.presto.spi.connector.ConnectorBucketNodeMap) NodeSelectionStrategy(com.facebook.presto.spi.schedule.NodeSelectionStrategy) PrestoException(com.facebook.presto.spi.PrestoException) FixedBucketNodeMap(com.facebook.presto.execution.scheduler.FixedBucketNodeMap)

Example 3 with ConnectorBucketNodeMap

use of com.facebook.presto.spi.connector.ConnectorBucketNodeMap in project presto by prestodb.

the class TestLocalExchange method testCreatePartitionFunction.

@Test
public void testCreatePartitionFunction() {
    int partitionCount = 10;
    PartitioningProviderManager partitioningProviderManager = new PartitioningProviderManager();
    partitioningProviderManager.addPartitioningProvider(new ConnectorId("prism"), new ConnectorNodePartitioningProvider() {

        @Override
        public ConnectorBucketNodeMap getBucketNodeMap(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorPartitioningHandle partitioningHandle, List<Node> sortedNodes) {
            return createBucketNodeMap(Stream.generate(() -> sortedNodes).flatMap(List::stream).limit(10).collect(toImmutableList()), SOFT_AFFINITY);
        }

        @Override
        public ToIntFunction<ConnectorSplit> getSplitBucketFunction(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorPartitioningHandle partitioningHandle) {
            return null;
        }

        @Override
        public BucketFunction getBucketFunction(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorPartitioningHandle partitioningHandle, List<Type> partitionChannelTypes, int bucketCount) {
            return (Page page, int position) -> partitionCount;
        }

        @Override
        public int getBucketCount(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorPartitioningHandle partitioningHandle) {
            return 10;
        }
    });
    PartitioningHandle partitioningHandle = new PartitioningHandle(Optional.of(new ConnectorId("prism")), Optional.of(new ConnectorTransactionHandle() {

        @Override
        public int hashCode() {
            return super.hashCode();
        }

        @Override
        public boolean equals(Object obj) {
            return super.equals(obj);
        }
    }), new ConnectorPartitioningHandle() {

        @Override
        public boolean isSingleNode() {
            return false;
        }

        @Override
        public boolean isCoordinatorOnly() {
            return false;
        }
    });
    PartitionFunction partitionFunction = createPartitionFunction(partitioningProviderManager, session, partitioningHandle, 600, ImmutableList.of(), false);
    assertEquals(partitionFunction.getPartitionCount(), partitionCount);
}
Also used : LocalExchange.createPartitionFunction(com.facebook.presto.operator.exchange.LocalExchange.createPartitionFunction) PartitionFunction(com.facebook.presto.operator.PartitionFunction) PartitioningProviderManager(com.facebook.presto.sql.planner.PartitioningProviderManager) Node(com.facebook.presto.spi.Node) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) Page(com.facebook.presto.common.Page) Type(com.facebook.presto.common.type.Type) ConnectorPartitioningHandle(com.facebook.presto.spi.connector.ConnectorPartitioningHandle) ConnectorNodePartitioningProvider(com.facebook.presto.spi.connector.ConnectorNodePartitioningProvider) ConnectorBucketNodeMap(com.facebook.presto.spi.connector.ConnectorBucketNodeMap) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ToIntFunction(java.util.function.ToIntFunction) ConnectorPartitioningHandle(com.facebook.presto.spi.connector.ConnectorPartitioningHandle) PartitioningHandle(com.facebook.presto.sql.planner.PartitioningHandle) BucketFunction(com.facebook.presto.spi.BucketFunction) ConnectorId(com.facebook.presto.spi.ConnectorId) Test(org.testng.annotations.Test)

Example 4 with ConnectorBucketNodeMap

use of com.facebook.presto.spi.connector.ConnectorBucketNodeMap in project presto by prestodb.

the class NodePartitioningManager method getNodePartitioningMap.

public NodePartitionMap getNodePartitioningMap(Session session, PartitioningHandle partitioningHandle) {
    requireNonNull(session, "session is null");
    requireNonNull(partitioningHandle, "partitioningHandle is null");
    if (partitioningHandle.getConnectorHandle() instanceof SystemPartitioningHandle) {
        return ((SystemPartitioningHandle) partitioningHandle.getConnectorHandle()).getNodePartitionMap(session, nodeScheduler);
    }
    ConnectorId connectorId = partitioningHandle.getConnectorId().orElseThrow(() -> new IllegalArgumentException("No connector ID for partitioning handle: " + partitioningHandle));
    ConnectorBucketNodeMap connectorBucketNodeMap = getConnectorBucketNodeMap(session, partitioningHandle);
    // safety check for crazy partitioning
    checkArgument(connectorBucketNodeMap.getBucketCount() < 1_000_000, "Too many buckets in partitioning: %s", connectorBucketNodeMap.getBucketCount());
    List<InternalNode> bucketToNode;
    NodeSelectionStrategy nodeSelectionStrategy = connectorBucketNodeMap.getNodeSelectionStrategy();
    boolean cacheable;
    switch(nodeSelectionStrategy) {
        case HARD_AFFINITY:
            bucketToNode = getFixedMapping(connectorBucketNodeMap);
            cacheable = false;
            break;
        case SOFT_AFFINITY:
            bucketToNode = getFixedMapping(connectorBucketNodeMap);
            cacheable = true;
            break;
        case NO_PREFERENCE:
            bucketToNode = createArbitraryBucketToNode(nodeScheduler.createNodeSelector(session, connectorId).selectRandomNodes(getMaxTasksPerStage(session)), connectorBucketNodeMap.getBucketCount());
            cacheable = false;
            break;
        default:
            throw new PrestoException(NODE_SELECTION_NOT_SUPPORTED, format("Unsupported node selection strategy %s", nodeSelectionStrategy));
    }
    int[] bucketToPartition = new int[connectorBucketNodeMap.getBucketCount()];
    BiMap<InternalNode, Integer> nodeToPartition = HashBiMap.create();
    int nextPartitionId = 0;
    for (int bucket = 0; bucket < bucketToNode.size(); bucket++) {
        InternalNode node = bucketToNode.get(bucket);
        Integer partitionId = nodeToPartition.get(node);
        if (partitionId == null) {
            partitionId = nextPartitionId++;
            nodeToPartition.put(node, partitionId);
        }
        bucketToPartition[bucket] = partitionId;
    }
    List<InternalNode> partitionToNode = IntStream.range(0, nodeToPartition.size()).mapToObj(partitionId -> nodeToPartition.inverse().get(partitionId)).collect(toImmutableList());
    return new NodePartitionMap(partitionToNode, bucketToPartition, getSplitToBucket(session, partitioningHandle), cacheable);
}
Also used : IntStream(java.util.stream.IntStream) ConnectorPartitionHandle(com.facebook.presto.spi.connector.ConnectorPartitionHandle) DEAD(com.facebook.presto.metadata.InternalNode.NodeStatus.DEAD) DynamicBucketNodeMap(com.facebook.presto.execution.scheduler.group.DynamicBucketNodeMap) NodeSelectionStats(com.facebook.presto.execution.scheduler.nodeSelection.NodeSelectionStats) NodeScheduler(com.facebook.presto.execution.scheduler.NodeScheduler) PrestoException(com.facebook.presto.spi.PrestoException) ConnectorNodePartitioningProvider(com.facebook.presto.spi.connector.ConnectorNodePartitioningProvider) EmptySplit(com.facebook.presto.split.EmptySplit) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Node(com.facebook.presto.spi.Node) ImmutableList(com.google.common.collect.ImmutableList) BucketNodeMap(com.facebook.presto.execution.scheduler.BucketNodeMap) Objects.requireNonNull(java.util.Objects.requireNonNull) SystemSessionProperties.getMaxTasksPerStage(com.facebook.presto.SystemSessionProperties.getMaxTasksPerStage) Type(com.facebook.presto.common.type.Type) BiMap(com.google.common.collect.BiMap) BucketPartitionFunction(com.facebook.presto.operator.BucketPartitionFunction) NODE_SELECTION_NOT_SUPPORTED(com.facebook.presto.spi.StandardErrorCode.NODE_SELECTION_NOT_SUPPORTED) FixedBucketNodeMap(com.facebook.presto.execution.scheduler.FixedBucketNodeMap) Session(com.facebook.presto.Session) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ToIntFunction(java.util.function.ToIntFunction) NodeSelectionStrategy(com.facebook.presto.spi.schedule.NodeSelectionStrategy) PartitionFunction(com.facebook.presto.operator.PartitionFunction) String.format(java.lang.String.format) InternalNode(com.facebook.presto.metadata.InternalNode) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit) HashBiMap(com.google.common.collect.HashBiMap) List(java.util.List) BucketFunction(com.facebook.presto.spi.BucketFunction) Split(com.facebook.presto.metadata.Split) ConnectorBucketNodeMap(com.facebook.presto.spi.connector.ConnectorBucketNodeMap) Optional(java.util.Optional) ConnectorId(com.facebook.presto.spi.ConnectorId) Collections(java.util.Collections) NodeSelectionStrategy(com.facebook.presto.spi.schedule.NodeSelectionStrategy) PrestoException(com.facebook.presto.spi.PrestoException) ConnectorBucketNodeMap(com.facebook.presto.spi.connector.ConnectorBucketNodeMap) InternalNode(com.facebook.presto.metadata.InternalNode) ConnectorId(com.facebook.presto.spi.ConnectorId)

Aggregations

ConnectorBucketNodeMap (com.facebook.presto.spi.connector.ConnectorBucketNodeMap)4 ConnectorId (com.facebook.presto.spi.ConnectorId)3 Node (com.facebook.presto.spi.Node)3 ConnectorNodePartitioningProvider (com.facebook.presto.spi.connector.ConnectorNodePartitioningProvider)3 Type (com.facebook.presto.common.type.Type)2 FixedBucketNodeMap (com.facebook.presto.execution.scheduler.FixedBucketNodeMap)2 DynamicBucketNodeMap (com.facebook.presto.execution.scheduler.group.DynamicBucketNodeMap)2 InternalNode (com.facebook.presto.metadata.InternalNode)2 PartitionFunction (com.facebook.presto.operator.PartitionFunction)2 BucketFunction (com.facebook.presto.spi.BucketFunction)2 PrestoException (com.facebook.presto.spi.PrestoException)2 NodeSelectionStrategy (com.facebook.presto.spi.schedule.NodeSelectionStrategy)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 List (java.util.List)2 ToIntFunction (java.util.function.ToIntFunction)2 Session (com.facebook.presto.Session)1 SystemSessionProperties.getMaxTasksPerStage (com.facebook.presto.SystemSessionProperties.getMaxTasksPerStage)1 Page (com.facebook.presto.common.Page)1 BucketNodeMap (com.facebook.presto.execution.scheduler.BucketNodeMap)1