Search in sources :

Example 1 with ALL_COORDINATORS

use of com.facebook.presto.spi.SystemTable.Distribution.ALL_COORDINATORS in project presto by prestodb.

the class SystemSplitManager method getSplits.

@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorTableLayoutHandle layout, SplitSchedulingContext splitSchedulingContext) {
    SystemTableLayoutHandle layoutHandle = (SystemTableLayoutHandle) layout;
    SystemTableHandle tableHandle = layoutHandle.getTable();
    TupleDomain<ColumnHandle> constraint = layoutHandle.getConstraint();
    SystemTable systemTable = tables.getSystemTable(session, tableHandle.getSchemaTableName()).orElseThrow(() -> new PrestoException(NOT_FOUND, format("Table %s not found", tableHandle.getSchemaTableName())));
    Distribution tableDistributionMode = systemTable.getDistribution();
    if (tableDistributionMode == SINGLE_COORDINATOR) {
        HostAddress address = nodeManager.getCurrentNode().getHostAndPort();
        ConnectorSplit split = new SystemSplit(tableHandle.getConnectorId(), tableHandle, 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).stream().filter(node -> !node.isResourceManager()).collect(toImmutableSet()));
    }
    Set<InternalNode> nodeSet = nodes.build();
    for (InternalNode node : nodeSet) {
        splits.add(new SystemSplit(tableHandle.getConnectorId(), tableHandle, node.getHostAndPort(), constraint));
    }
    return new FixedSplitSource(splits.build());
}
Also used : ALL_COORDINATORS(com.facebook.presto.spi.SystemTable.Distribution.ALL_COORDINATORS) ConnectorSplitSource(com.facebook.presto.spi.ConnectorSplitSource) NOT_FOUND(com.facebook.presto.spi.StandardErrorCode.NOT_FOUND) ConnectorTableLayoutHandle(com.facebook.presto.spi.ConnectorTableLayoutHandle) SINGLE_COORDINATOR(com.facebook.presto.spi.SystemTable.Distribution.SINGLE_COORDINATOR) PrestoException(com.facebook.presto.spi.PrestoException) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) ACTIVE(com.facebook.presto.spi.NodeState.ACTIVE) InternalNodeManager(com.facebook.presto.metadata.InternalNodeManager) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) SystemTable(com.facebook.presto.spi.SystemTable) ConnectorSplitManager(com.facebook.presto.spi.connector.ConnectorSplitManager) ImmutableSet(com.google.common.collect.ImmutableSet) ALL_NODES(com.facebook.presto.spi.SystemTable.Distribution.ALL_NODES) HostAddress(com.facebook.presto.spi.HostAddress) Set(java.util.Set) FixedSplitSource(com.facebook.presto.spi.FixedSplitSource) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) String.format(java.lang.String.format) InternalNode(com.facebook.presto.metadata.InternalNode) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit) ColumnHandle(com.facebook.presto.spi.ColumnHandle) Distribution(com.facebook.presto.spi.SystemTable.Distribution) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ImmutableList(com.google.common.collect.ImmutableList) PrestoException(com.facebook.presto.spi.PrestoException) HostAddress(com.facebook.presto.spi.HostAddress) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ImmutableSet(com.google.common.collect.ImmutableSet) FixedSplitSource(com.facebook.presto.spi.FixedSplitSource) Distribution(com.facebook.presto.spi.SystemTable.Distribution) SystemTable(com.facebook.presto.spi.SystemTable) InternalNode(com.facebook.presto.metadata.InternalNode) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit)

Aggregations

TupleDomain (com.facebook.presto.common.predicate.TupleDomain)1 InternalNode (com.facebook.presto.metadata.InternalNode)1 InternalNodeManager (com.facebook.presto.metadata.InternalNodeManager)1 ColumnHandle (com.facebook.presto.spi.ColumnHandle)1 ConnectorSession (com.facebook.presto.spi.ConnectorSession)1 ConnectorSplit (com.facebook.presto.spi.ConnectorSplit)1 ConnectorSplitSource (com.facebook.presto.spi.ConnectorSplitSource)1 ConnectorTableLayoutHandle (com.facebook.presto.spi.ConnectorTableLayoutHandle)1 FixedSplitSource (com.facebook.presto.spi.FixedSplitSource)1 HostAddress (com.facebook.presto.spi.HostAddress)1 ACTIVE (com.facebook.presto.spi.NodeState.ACTIVE)1 PrestoException (com.facebook.presto.spi.PrestoException)1 NOT_FOUND (com.facebook.presto.spi.StandardErrorCode.NOT_FOUND)1 SystemTable (com.facebook.presto.spi.SystemTable)1 Distribution (com.facebook.presto.spi.SystemTable.Distribution)1 ALL_COORDINATORS (com.facebook.presto.spi.SystemTable.Distribution.ALL_COORDINATORS)1 ALL_NODES (com.facebook.presto.spi.SystemTable.Distribution.ALL_NODES)1 SINGLE_COORDINATOR (com.facebook.presto.spi.SystemTable.Distribution.SINGLE_COORDINATOR)1 ConnectorSplitManager (com.facebook.presto.spi.connector.ConnectorSplitManager)1 ConnectorTransactionHandle (com.facebook.presto.spi.connector.ConnectorTransactionHandle)1