Search in sources :

Example 51 with InternalNode

use of com.facebook.presto.metadata.InternalNode in project presto by prestodb.

the class TestClusterSizeMonitor method addWorker.

private void addWorker(InMemoryNodeManager nodeManager) {
    String identifier = "worker/" + numWorkers.incrementAndGet();
    nodeManager.addNode(CONNECTOR_ID, new InternalNode(identifier, URI.create("localhost/" + identifier), new NodeVersion("1"), false));
}
Also used : NodeVersion(com.facebook.presto.client.NodeVersion) InternalNode(com.facebook.presto.metadata.InternalNode)

Example 52 with InternalNode

use of com.facebook.presto.metadata.InternalNode in project presto by prestodb.

the class TestNodeScheduler method testMemoryUsage.

@Test
public void testMemoryUsage() {
    MockRemoteTaskFactory remoteTaskFactory = new MockRemoteTaskFactory(remoteTaskExecutor, remoteTaskScheduledExecutor);
    InternalNode chosenNode = Iterables.get(nodeManager.getActiveConnectorNodes(CONNECTOR_ID), 0);
    TaskId taskId1 = new TaskId("test", 1, 0, 1);
    List<Split> splits = ImmutableList.of(new Split(CONNECTOR_ID, TestingTransactionHandle.create(), new TestSplitRemote()), new Split(CONNECTOR_ID, TestingTransactionHandle.create(), new TestSplitRemote()));
    RemoteTask remoteTask1 = remoteTaskFactory.createTableScanTask(taskId1, chosenNode, splits, nodeTaskMap.createTaskStatsTracker(chosenNode, taskId1));
    TaskId taskId2 = new TaskId("test", 1, 0, 2);
    RemoteTask remoteTask2 = remoteTaskFactory.createTableScanTask(taskId2, chosenNode, ImmutableList.of(new Split(CONNECTOR_ID, TestingTransactionHandle.create(), new TestSplitRemote())), nodeTaskMap.createTaskStatsTracker(chosenNode, taskId2));
    nodeTaskMap.addTask(chosenNode, remoteTask1);
    nodeTaskMap.addTask(chosenNode, remoteTask2);
    remoteTask2.addSplits(ImmutableMultimap.<PlanNodeId, Split>builder().putAll(new PlanNodeId("sourceId"), splits).build());
    assertEquals(nodeTaskMap.getNodeTotalMemoryUsageInBytes(chosenNode), 200);
    remoteTask1.addSplits(ImmutableMultimap.<PlanNodeId, Split>builder().putAll(new PlanNodeId("sourceId"), splits).build());
    assertEquals(nodeTaskMap.getNodeTotalMemoryUsageInBytes(chosenNode), 200);
    remoteTask1.abort();
    assertEquals(nodeTaskMap.getNodeTotalMemoryUsageInBytes(chosenNode), 100);
    remoteTask2.abort();
    assertEquals(nodeTaskMap.getNodeTotalMemoryUsageInBytes(chosenNode), 0);
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) InternalNode(com.facebook.presto.metadata.InternalNode) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit) Split(com.facebook.presto.metadata.Split) Test(org.testng.annotations.Test)

Example 53 with InternalNode

use of com.facebook.presto.metadata.InternalNode in project presto by prestodb.

the class DynamicLifespanScheduler method scheduleInitial.

@Override
public void scheduleInitial(SourceScheduler scheduler) {
    checkState(!initialScheduled, "Initial scheduling happened before scheduleInitial is called");
    int driverGroupsScheduledPerTask = 0;
    synchronized (this) {
        while (!noPreferenceDriverGroups.isEmpty() || !nodeToPreferredDriverGroups.isEmpty()) {
            for (int taskId = 0; taskId < nodeByTaskId.size() && (!noPreferenceDriverGroups.isEmpty() || !nodeToPreferredDriverGroups.isEmpty()); taskId++) {
                InternalNode node = nodeByTaskId.get(taskId);
                OptionalInt driverGroupId = getNextDriverGroup(node);
                if (!driverGroupId.isPresent()) {
                    continue;
                }
                scheduler.startLifespan(Lifespan.driverGroup(driverGroupId.getAsInt()), partitionHandles.get(driverGroupId.getAsInt()));
                taskByDriverGroup[driverGroupId.getAsInt()] = taskId;
                runningDriverGroupIdsByTask[taskId].add(driverGroupId.getAsInt());
            }
            driverGroupsScheduledPerTask++;
            if (concurrentLifespansPerTask.isPresent() && driverGroupsScheduledPerTask == concurrentLifespansPerTask.getAsInt()) {
                break;
            }
        }
        initialScheduled = true;
    }
}
Also used : InternalNode(com.facebook.presto.metadata.InternalNode) OptionalInt(java.util.OptionalInt)

Example 54 with InternalNode

use of com.facebook.presto.metadata.InternalNode in project presto by prestodb.

the class SimpleTtlNodeSelector method computeAssignments.

@Override
public SplitPlacementResult computeAssignments(Set<Split> splits, List<RemoteTask> existingTasks) {
    boolean isNodeSelectionStrategyNoPreference = splits.stream().allMatch(split -> split.getNodeSelectionStrategy() == NodeSelectionStrategy.NO_PREFERENCE);
    // Current NodeSelectionStrategy support is limited to NO_PREFERENCE
    if (!isNodeSelectionStrategyNoPreference) {
        return simpleNodeSelector.computeAssignments(splits, existingTasks);
    }
    ImmutableMultimap.Builder<InternalNode, Split> assignment = ImmutableMultimap.builder();
    NodeMap nodeMap = this.nodeMap.get().get();
    NodeAssignmentStats assignmentStats = new NodeAssignmentStats(nodeTaskMap, nodeMap, existingTasks);
    List<InternalNode> eligibleNodes = getEligibleNodes(maxTasksPerStage, nodeMap, existingTasks);
    NodeSelection randomNodeSelection = new RandomNodeSelection(eligibleNodes, minCandidates);
    boolean splitWaitingForAnyNode = false;
    OptionalInt preferredNodeCount = OptionalInt.empty();
    for (Split split : splits) {
        if (split.getNodeSelectionStrategy() != NodeSelectionStrategy.NO_PREFERENCE) {
            throw new PrestoException(NODE_SELECTION_NOT_SUPPORTED, format("Unsupported node selection strategy for TTL scheduling: %s", split.getNodeSelectionStrategy()));
        }
        List<InternalNode> candidateNodes = randomNodeSelection.pickNodes(split);
        if (candidateNodes.isEmpty()) {
            log.warn("No nodes available to schedule %s. Available nodes %s", split, nodeMap.getActiveNodes());
            throw new PrestoException(NO_NODES_AVAILABLE, "No nodes available to run query");
        }
        SplitWeight splitWeight = split.getSplitWeight();
        Optional<InternalNodeInfo> chosenNodeInfo = simpleNodeSelector.chooseLeastBusyNode(splitWeight, candidateNodes, assignmentStats::getTotalSplitsWeight, preferredNodeCount, maxSplitsWeightPerNode, assignmentStats);
        if (!chosenNodeInfo.isPresent()) {
            chosenNodeInfo = simpleNodeSelector.chooseLeastBusyNode(splitWeight, candidateNodes, assignmentStats::getQueuedSplitsWeightForStage, preferredNodeCount, maxPendingSplitsWeightPerTask, assignmentStats);
        }
        if (chosenNodeInfo.isPresent()) {
            split = new Split(split.getConnectorId(), split.getTransactionHandle(), split.getConnectorSplit(), split.getLifespan(), new SplitContext(chosenNodeInfo.get().isCacheable()));
            InternalNode chosenNode = chosenNodeInfo.get().getInternalNode();
            assignment.put(chosenNode, split);
            assignmentStats.addAssignedSplit(chosenNode, splitWeight);
        } else {
            splitWaitingForAnyNode = true;
        }
    }
    ListenableFuture<?> blocked = splitWaitingForAnyNode ? toWhenHasSplitQueueSpaceFuture(existingTasks, calculateLowWatermark(maxPendingSplitsWeightPerTask)) : immediateFuture(null);
    return new SplitPlacementResult(blocked, assignment.build());
}
Also used : NodeAssignmentStats(com.facebook.presto.execution.scheduler.NodeAssignmentStats) InternalNodeInfo(com.facebook.presto.execution.scheduler.InternalNodeInfo) PrestoException(com.facebook.presto.spi.PrestoException) OptionalInt(java.util.OptionalInt) SplitWeight(com.facebook.presto.spi.SplitWeight) SplitContext(com.facebook.presto.spi.SplitContext) BucketNodeMap(com.facebook.presto.execution.scheduler.BucketNodeMap) NodeMap(com.facebook.presto.execution.scheduler.NodeMap) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) InternalNode(com.facebook.presto.metadata.InternalNode) Split(com.facebook.presto.metadata.Split) SplitPlacementResult(com.facebook.presto.execution.scheduler.SplitPlacementResult)

Example 55 with InternalNode

use of com.facebook.presto.metadata.InternalNode in project presto by prestodb.

the class SimpleTtlNodeSelector method selectRandomNodes.

@Override
public List<InternalNode> selectRandomNodes(int limit, Set<InternalNode> excludedNodes) {
    Map<InternalNode, NodeTtl> nodeTtlInfo = nodeTtlFetcherManager.getAllTtls();
    Map<InternalNode, Optional<ConfidenceBasedTtlInfo>> ttlInfo = nodeTtlInfo.entrySet().stream().collect(toImmutableMap(Map.Entry::getKey, e -> e.getValue().getTtlInfo().stream().min(Comparator.comparing(ConfidenceBasedTtlInfo::getExpiryInstant))));
    NodeMap nodeMap = this.nodeMap.get().get();
    List<InternalNode> activeNodes = nodeMap.getActiveNodes();
    Duration estimatedExecutionTimeRemaining = getEstimatedExecutionTimeRemaining();
    List<InternalNode> eligibleNodes = filterNodesByTtl(activeNodes, excludedNodes, ttlInfo, estimatedExecutionTimeRemaining);
    return selectNodes(limit, new ResettableRandomizedIterator<>(eligibleNodes));
}
Also used : NodeTaskMap(com.facebook.presto.execution.NodeTaskMap) NodeScheduler.selectNodes(com.facebook.presto.execution.scheduler.NodeScheduler.selectNodes) Duration(io.airlift.units.Duration) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) SplitContext(com.facebook.presto.spi.SplitContext) BucketNodeMap(com.facebook.presto.execution.scheduler.BucketNodeMap) Map(java.util.Map) ConfidenceBasedTtlInfo(com.facebook.presto.spi.ttl.ConfidenceBasedTtlInfo) NODE_SELECTION_NOT_SUPPORTED(com.facebook.presto.spi.StandardErrorCode.NODE_SELECTION_NOT_SUPPORTED) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) NO_NODES_AVAILABLE(com.facebook.presto.spi.StandardErrorCode.NO_NODES_AVAILABLE) Instant(java.time.Instant) String.format(java.lang.String.format) Objects(java.util.Objects) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) NodeTtlFetcherManager(com.facebook.presto.ttl.nodettlfetchermanagers.NodeTtlFetcherManager) ResettableRandomizedIterator(com.facebook.presto.execution.scheduler.ResettableRandomizedIterator) NodeTtl(com.facebook.presto.spi.ttl.NodeTtl) Optional(java.util.Optional) NodeScheduler.calculateLowWatermark(com.facebook.presto.execution.scheduler.NodeScheduler.calculateLowWatermark) Logger(com.facebook.airlift.log.Logger) SplitPlacementResult(com.facebook.presto.execution.scheduler.SplitPlacementResult) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) InternalNodeInfo(com.facebook.presto.execution.scheduler.InternalNodeInfo) Supplier(com.google.common.base.Supplier) NodeMap(com.facebook.presto.execution.scheduler.NodeMap) QueryManager(com.facebook.presto.execution.QueryManager) PrestoException(com.facebook.presto.spi.PrestoException) OptionalInt(java.util.OptionalInt) AtomicReference(java.util.concurrent.atomic.AtomicReference) NodeScheduler.toWhenHasSplitQueueSpaceFuture(com.facebook.presto.execution.scheduler.NodeScheduler.toWhenHasSplitQueueSpaceFuture) Verify.verify(com.google.common.base.Verify.verify) Objects.requireNonNull(java.util.Objects.requireNonNull) Suppliers(com.google.common.base.Suppliers) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) SECONDS(java.time.temporal.ChronoUnit.SECONDS) Futures.immediateFuture(com.google.common.util.concurrent.Futures.immediateFuture) Session(com.facebook.presto.Session) NodeSelectionStrategy(com.facebook.presto.spi.schedule.NodeSelectionStrategy) NodeAssignmentStats(com.facebook.presto.execution.scheduler.NodeAssignmentStats) InternalNode(com.facebook.presto.metadata.InternalNode) TimeUnit(java.util.concurrent.TimeUnit) Collectors.toList(java.util.stream.Collectors.toList) RemoteTask(com.facebook.presto.execution.RemoteTask) Split(com.facebook.presto.metadata.Split) VisibleForTesting(com.google.common.annotations.VisibleForTesting) SplitWeight(com.facebook.presto.spi.SplitWeight) Comparator(java.util.Comparator) Optional(java.util.Optional) NodeTtl(com.facebook.presto.spi.ttl.NodeTtl) BucketNodeMap(com.facebook.presto.execution.scheduler.BucketNodeMap) NodeMap(com.facebook.presto.execution.scheduler.NodeMap) Duration(io.airlift.units.Duration) InternalNode(com.facebook.presto.metadata.InternalNode) NodeTaskMap(com.facebook.presto.execution.NodeTaskMap) BucketNodeMap(com.facebook.presto.execution.scheduler.BucketNodeMap) Map(java.util.Map) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) NodeMap(com.facebook.presto.execution.scheduler.NodeMap)

Aggregations

InternalNode (com.facebook.presto.metadata.InternalNode)74 Split (com.facebook.presto.metadata.Split)34 Test (org.testng.annotations.Test)34 ConnectorSplit (com.facebook.presto.spi.ConnectorSplit)25 HashSet (java.util.HashSet)24 ImmutableList (com.google.common.collect.ImmutableList)17 InMemoryNodeManager (com.facebook.presto.metadata.InMemoryNodeManager)14 SplitPlacementResult (com.facebook.presto.execution.scheduler.SplitPlacementResult)13 NodeSelectionStats (com.facebook.presto.execution.scheduler.nodeSelection.NodeSelectionStats)12 NodeSelector (com.facebook.presto.execution.scheduler.nodeSelection.NodeSelector)12 ImmutableSet (com.google.common.collect.ImmutableSet)12 SimpleTtlNodeSelectorConfig (com.facebook.presto.execution.scheduler.nodeSelection.SimpleTtlNodeSelectorConfig)11 ConnectorId (com.facebook.presto.spi.ConnectorId)11 TestingTransactionHandle (com.facebook.presto.testing.TestingTransactionHandle)11 Duration (io.airlift.units.Duration)11 URI (java.net.URI)11 Map (java.util.Map)11 RemoteTask (com.facebook.presto.execution.RemoteTask)10 NodeScheduler (com.facebook.presto.execution.scheduler.NodeScheduler)10 NodeSchedulerConfig (com.facebook.presto.execution.scheduler.NodeSchedulerConfig)9