Search in sources :

Example 1 with InternalNode

use of io.prestosql.metadata.InternalNode in project hetu-core by openlookeng.

the class TestDynamicFilterUtil method registerDf.

public static void registerDf(String filterId, Session session, JoinNode.DistributionType joinType, DynamicFilterService dynamicFilterService) {
    JoinNode node = mock(JoinNode.class);
    HashMap<String, Symbol> dfs = new HashMap<>();
    List<JoinNode.EquiJoinClause> criteria = new ArrayList<JoinNode.EquiJoinClause>();
    Symbol right = new Symbol("rightCol");
    Symbol left = new Symbol("leftCol");
    JoinNode.EquiJoinClause clause = new JoinNode.EquiJoinClause(left, right);
    criteria.add(clause);
    dfs.put(filterId, right);
    when(node.getCriteria()).thenReturn(criteria);
    when(node.getDynamicFilters()).thenReturn(dfs);
    when(node.getDistributionType()).thenReturn(Optional.of(joinType));
    RemoteSourceNode leftNode = mock(RemoteSourceNode.class);
    when(node.getLeft()).thenReturn(leftNode);
    HashSet<TaskId> tasks = new HashSet<>();
    tasks.add(new TaskId("task1.0"));
    tasks.add(new TaskId("task1.1"));
    StageStateMachine stateMachine = mock(StageStateMachine.class);
    when(stateMachine.getSession()).thenReturn(session);
    InternalNode worker = mock(InternalNode.class);
    InternalNode worker2 = mock(InternalNode.class);
    HashSet<InternalNode> workers = new HashSet<>();
    when(worker.getNodeIdentifier()).thenReturn("w1");
    when(worker2.getNodeIdentifier()).thenReturn("w2");
    workers.add(worker);
    workers.add(worker2);
    dynamicFilterService.registerTasks(node, tasks, workers, stateMachine);
}
Also used : TaskId(io.prestosql.execution.TaskId) HashMap(java.util.HashMap) JoinNode(io.prestosql.spi.plan.JoinNode) Symbol(io.prestosql.spi.plan.Symbol) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) RemoteSourceNode(io.prestosql.sql.planner.plan.RemoteSourceNode) StageStateMachine(io.prestosql.execution.StageStateMachine) InternalNode(io.prestosql.metadata.InternalNode) HashSet(java.util.HashSet)

Example 2 with InternalNode

use of io.prestosql.metadata.InternalNode in project hetu-core by openlookeng.

the class DistributedQueryRunner method isConnectionVisibleToAllNodes.

private boolean isConnectionVisibleToAllNodes(CatalogName catalogName) {
    for (TestingPrestoServer server : servers) {
        server.refreshNodes();
        Set<InternalNode> activeNodesWithConnector = server.getActiveNodesWithConnector(catalogName);
        if (activeNodesWithConnector.size() != servers.size()) {
            return false;
        }
    }
    return true;
}
Also used : TestingPrestoServer(io.prestosql.server.testing.TestingPrestoServer) InternalNode(io.prestosql.metadata.InternalNode)

Example 3 with InternalNode

use of io.prestosql.metadata.InternalNode in project hetu-core by openlookeng.

the class SqlStageExecution method scheduleTask.

private synchronized RemoteTask scheduleTask(InternalNode node, TaskId taskId, String instanceId, Multimap<PlanNodeId, Split> sourceSplits, OptionalInt totalPartitions) {
    checkArgument(!allTasks.contains(taskId), "A task with id %s already exists", taskId);
    if (SystemSessionProperties.isSnapshotEnabled(stateMachine.getSession())) {
        // Snapshot: inform snapshot manager so it knows about all tasks,
        // and can determine if a snapshot is complete for all tasks.
        snapshotManager.addNewTask(taskId);
    }
    ImmutableMultimap.Builder<PlanNodeId, Split> initialSplits = ImmutableMultimap.builder();
    initialSplits.putAll(sourceSplits);
    sourceTasks.forEach((planNodeId, task) -> {
        if (task.getTaskStatus().getState() != TaskState.FINISHED) {
            initialSplits.put(planNodeId, newConnectSplit(taskId, task));
        }
    });
    OutputBuffers localOutputBuffers = this.outputBuffers.get();
    checkState(localOutputBuffers != null, "Initial output buffers must be set before a task can be scheduled");
    RemoteTask task = remoteTaskFactory.createRemoteTask(stateMachine.getSession(), taskId, instanceId, node, stateMachine.getFragment(), initialSplits.build(), totalPartitions, localOutputBuffers, nodeTaskMap.createPartitionedSplitCountTracker(node, taskId), summarizeTaskInfo, Optional.ofNullable(parentId), snapshotManager);
    completeSources.forEach(task::noMoreSplits);
    allTasks.add(taskId);
    tasks.computeIfAbsent(node, key -> newConcurrentHashSet()).add(task);
    nodeTaskMap.addTask(node, task);
    task.addStateChangeListener(new StageTaskListener());
    task.addFinalTaskInfoListener(this::updateFinalTaskInfo);
    if (!stateMachine.getState().isDone()) {
        task.start();
    } else {
        // stage finished while we were scheduling this task
        task.abort();
    }
    return task;
}
Also used : PlanNodeId(io.prestosql.spi.plan.PlanNodeId) REMOTE_HOST_GONE(io.prestosql.spi.StandardErrorCode.REMOTE_HOST_GONE) SystemSessionProperties(io.prestosql.SystemSessionProperties) SystemSessionProperties.isSnapshotEnabled(io.prestosql.SystemSessionProperties.isSnapshotEnabled) PlanFragmentId(io.prestosql.sql.planner.plan.PlanFragmentId) Duration(io.airlift.units.Duration) HttpPageBufferClient(io.prestosql.operator.HttpPageBufferClient) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) HashMultimap(com.google.common.collect.HashMultimap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) URI(java.net.URI) PlanNodeId(io.prestosql.spi.plan.PlanNodeId) PrestoException(io.prestosql.spi.PrestoException) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) GONE(io.prestosql.failuredetector.FailureDetector.State.GONE) Collection(java.util.Collection) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TableScanNode(io.prestosql.spi.plan.TableScanNode) Set(java.util.Set) ThreadSafe(javax.annotation.concurrent.ThreadSafe) PlanNode(io.prestosql.spi.plan.PlanNode) UUID(java.util.UUID) GuardedBy(javax.annotation.concurrent.GuardedBy) REMOTE_CONNECTOR_ID(io.prestosql.operator.ExchangeOperator.REMOTE_CONNECTOR_ID) Sets(com.google.common.collect.Sets) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) SplitSchedulerStats(io.prestosql.execution.scheduler.SplitSchedulerStats) Entry(java.util.Map.Entry) HttpUriBuilder.uriBuilderFrom(io.airlift.http.client.HttpUriBuilder.uriBuilderFrom) GENERIC_INTERNAL_ERROR(io.prestosql.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR) Optional(java.util.Optional) StateChangeListener(io.prestosql.execution.StateMachine.StateChangeListener) Logger(io.airlift.log.Logger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RemoteSourceNode(io.prestosql.sql.planner.plan.RemoteSourceNode) Split(io.prestosql.metadata.Split) Multimap(com.google.common.collect.Multimap) OutputBuffers(io.prestosql.execution.buffer.OutputBuffers) OptionalInt(java.util.OptionalInt) AtomicReference(java.util.concurrent.atomic.AtomicReference) SemiJoinNode(io.prestosql.sql.planner.plan.SemiJoinNode) ArrayList(java.util.ArrayList) SystemSessionProperties.isEnableDynamicFiltering(io.prestosql.SystemSessionProperties.isEnableDynamicFiltering) HashSet(java.util.HashSet) RemoteSplit(io.prestosql.split.RemoteSplit) ImmutableList(com.google.common.collect.ImmutableList) SystemSessionProperties.isReuseTableScanEnabled(io.prestosql.SystemSessionProperties.isReuseTableScanEnabled) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) QueryId(io.prestosql.spi.QueryId) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) ExecutorService(java.util.concurrent.ExecutorService) JoinNode(io.prestosql.spi.plan.JoinNode) PlanFragment(io.prestosql.sql.planner.PlanFragment) SimpleHttpResponseHandler(io.prestosql.server.remotetask.SimpleHttpResponseHandler) Executor(java.util.concurrent.Executor) InternalNode(io.prestosql.metadata.InternalNode) Sets.newConcurrentHashSet(com.google.common.collect.Sets.newConcurrentHashSet) QuerySnapshotManager(io.prestosql.snapshot.QuerySnapshotManager) DynamicFilterService(io.prestosql.dynamicfilter.DynamicFilterService) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) HttpStatus(io.airlift.http.client.HttpStatus) FailureDetector(io.prestosql.failuredetector.FailureDetector) Collections(java.util.Collections) OutputBuffers(io.prestosql.execution.buffer.OutputBuffers) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Split(io.prestosql.metadata.Split) RemoteSplit(io.prestosql.split.RemoteSplit)

Example 4 with InternalNode

use of io.prestosql.metadata.InternalNode in project hetu-core by openlookeng.

the class DistributedResourceGroupTemp method refreshGlobalValues.

private void refreshGlobalValues() {
    synchronized (root) {
        globalTotalRunningQueries = localRunningQueries.size();
        globalTotalQueuedQueries = localQueuedQueries.size();
        globalDescendantQueuedQueries = localDescendantQueuedQueries;
        globalDescendantRunningQueries = localDescendantRunningQueries;
        globalCachedMemoryUsageBytes = localCachedMemoryUsageBytes;
        globalCpuUsageMillis = localCpuUsageMillis;
        internalNodeManager.refreshNodes();
        try {
            for (InternalNode coordinator : internalNodeManager.getCoordinators()) {
                if (coordinator.equals(internalNodeManager.getCurrentNode())) {
                    continue;
                }
                StateMap<String, String> resourceGroupMap = ((StateMap) stateStore.getOrCreateStateCollection(createCoordinatorCollectionName(coordinator), StateCollection.Type.MAP));
                DistributedResourceGroupAggrStats groupAggrStats = resourceGroupMap.containsKey(getId().toString()) ? MAPPER.readerFor(DistributedResourceGroupAggrStats.class).readValue(resourceGroupMap.get(getId().toString())) : null;
                if (groupAggrStats != null) {
                    globalTotalRunningQueries += groupAggrStats.getRunningQueries();
                    globalTotalQueuedQueries += groupAggrStats.getQueuedQueries();
                    globalDescendantQueuedQueries += groupAggrStats.getDescendantQueuedQueries();
                    globalDescendantRunningQueries += groupAggrStats.getDescendantRunningQueries();
                    globalCachedMemoryUsageBytes += groupAggrStats.getCachedMemoryUsageBytes();
                    globalCpuUsageMillis += groupAggrStats.getCachedMemoryUsageBytes();
                }
            }
        } catch (JsonProcessingException e) {
            throw new RuntimeException(String.format("Error fetching resource group state with group id = %s, caused by ObjectMapper: %s", id, e.getMessage()));
        }
    }
}
Also used : InternalNode(io.prestosql.metadata.InternalNode) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 5 with InternalNode

use of io.prestosql.metadata.InternalNode in project hetu-core by openlookeng.

the class NodePartitioningManager method getNodePartitioningMap.

public NodePartitionMap getNodePartitioningMap(Session session, PartitioningHandle partitioningHandle, boolean isSnapshotEnabled, Integer nodeCount) {
    requireNonNull(session, "session is null");
    requireNonNull(partitioningHandle, "partitioningHandle is null");
    if (partitioningHandle.getConnectorHandle() instanceof SystemPartitioningHandle) {
        return ((SystemPartitioningHandle) partitioningHandle.getConnectorHandle()).getNodePartitionMap(session, nodeScheduler, isSnapshotEnabled, nodeCount);
    }
    CatalogName catalogName = partitioningHandle.getConnectorId().orElseThrow(() -> new IllegalArgumentException("No connector ID for partitioning handle: " + partitioningHandle));
    ConnectorNodePartitioningProvider partitioningProvider = partitioningProviders.get(catalogName);
    checkArgument(partitioningProvider != null, "No partitioning provider for connector %s", catalogName);
    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;
    if (connectorBucketNodeMap.hasFixedMapping()) {
        bucketToNode = getFixedMapping(connectorBucketNodeMap);
    } else {
        NodeSelector nodeSelector = nodeScheduler.createNodeSelector(catalogName, false, null);
        List<InternalNode> nodes;
        if (isSnapshotEnabled) {
            Integer count = nodeCount;
            if (count == null) {
                // Initial schedule: reserve some nodes
                count = calculateTaskCount(nodeSelector.selectableNodeCount());
            }
            nodes = nodeSelector.selectRandomNodes(count);
            checkCondition(nodes.size() == count, NO_NODES_AVAILABLE, "Snapshot: not enough worker nodes to resume expected number of tasks: " + count);
        } else {
            nodes = nodeSelector.allNodes();
        }
        bucketToNode = createArbitraryBucketToNode(nodes, connectorBucketNodeMap.getBucketCount());
    }
    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));
}
Also used : IntStream(java.util.stream.IntStream) ConnectorSplit(io.prestosql.spi.connector.ConnectorSplit) NodeScheduler(io.prestosql.execution.scheduler.NodeScheduler) Split(io.prestosql.metadata.Split) NO_NODES_AVAILABLE(io.prestosql.spi.StandardErrorCode.NO_NODES_AVAILABLE) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) Inject(javax.inject.Inject) SnapshotConfig.calculateTaskCount(io.prestosql.snapshot.SnapshotConfig.calculateTaskCount) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Failures.checkCondition(io.prestosql.util.Failures.checkCondition) ConnectorNodePartitioningProvider(io.prestosql.spi.connector.ConnectorNodePartitioningProvider) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) Type(io.prestosql.spi.type.Type) FixedBucketNodeMap(io.prestosql.execution.scheduler.FixedBucketNodeMap) BiMap(com.google.common.collect.BiMap) DynamicBucketNodeMap(io.prestosql.execution.scheduler.group.DynamicBucketNodeMap) InternalNode(io.prestosql.metadata.InternalNode) Collection(java.util.Collection) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) CatalogName(io.prestosql.spi.connector.CatalogName) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ToIntFunction(java.util.function.ToIntFunction) BucketFunction(io.prestosql.spi.connector.BucketFunction) BucketNodeMap(io.prestosql.execution.scheduler.BucketNodeMap) HashBiMap(com.google.common.collect.HashBiMap) List(java.util.List) BucketPartitionFunction(io.prestosql.operator.BucketPartitionFunction) Stream(java.util.stream.Stream) ConnectorPartitionHandle(io.prestosql.spi.connector.ConnectorPartitionHandle) NodeSelector(io.prestosql.execution.scheduler.NodeSelector) ConnectorBucketNodeMap(io.prestosql.spi.connector.ConnectorBucketNodeMap) Optional(java.util.Optional) PartitionFunction(io.prestosql.operator.PartitionFunction) Collections(java.util.Collections) ConnectorNodePartitioningProvider(io.prestosql.spi.connector.ConnectorNodePartitioningProvider) ConnectorBucketNodeMap(io.prestosql.spi.connector.ConnectorBucketNodeMap) CatalogName(io.prestosql.spi.connector.CatalogName) InternalNode(io.prestosql.metadata.InternalNode) NodeSelector(io.prestosql.execution.scheduler.NodeSelector)

Aggregations

InternalNode (io.prestosql.metadata.InternalNode)58 Split (io.prestosql.metadata.Split)31 ConnectorSplit (io.prestosql.spi.connector.ConnectorSplit)21 Test (org.testng.annotations.Test)20 TestingSplit (io.prestosql.testing.TestingSplit)18 HashSet (java.util.HashSet)17 MockSplit (io.prestosql.MockSplit)16 HashMap (java.util.HashMap)15 ImmutableList (com.google.common.collect.ImmutableList)14 RemoteTask (io.prestosql.execution.RemoteTask)14 PlanNodeId (io.prestosql.spi.plan.PlanNodeId)14 LinkedHashSet (java.util.LinkedHashSet)14 Map (java.util.Map)12 NodeTaskMap (io.prestosql.execution.NodeTaskMap)11 ArrayList (java.util.ArrayList)11 ImmutableSet (com.google.common.collect.ImmutableSet)9 MockRemoteTaskFactory (io.prestosql.execution.MockRemoteTaskFactory)9 TaskId (io.prestosql.execution.TaskId)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 PrestoException (io.prestosql.spi.PrestoException)8