Search in sources :

Example 66 with InternalNode

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

the class LowMemoryKillerTestingUtils method toNodeMemoryInfoList.

static List<MemoryInfo> toNodeMemoryInfoList(long maxReservedPoolBytes, long maxGeneralPoolBytes, String reservedQuery, Map<String, Map<String, Long>> queries) {
    Map<InternalNode, NodeReservation> nodeReservations = new HashMap<>();
    for (Map.Entry<String, Map<String, Long>> entry : queries.entrySet()) {
        QueryId queryId = new QueryId(entry.getKey());
        Map<String, Long> reservationByNode = entry.getValue();
        for (Map.Entry<String, Long> nodeEntry : reservationByNode.entrySet()) {
            InternalNode node = new InternalNode(nodeEntry.getKey(), URI.create("http://localhost"), new NodeVersion("version"), false);
            long bytes = nodeEntry.getValue();
            if (bytes == 0) {
                continue;
            }
            if (reservedQuery.equals(entry.getKey())) {
                nodeReservations.computeIfAbsent(node, ignored -> new NodeReservation()).getReserved().add(queryId, bytes);
            } else {
                nodeReservations.computeIfAbsent(node, ignored -> new NodeReservation()).getGeneral().add(queryId, bytes);
            }
        }
    }
    ImmutableList.Builder<MemoryInfo> result = ImmutableList.builder();
    for (Map.Entry<InternalNode, NodeReservation> entry : nodeReservations.entrySet()) {
        NodeReservation nodeReservation = entry.getValue();
        ImmutableMap.Builder<MemoryPoolId, MemoryPoolInfo> pools = ImmutableMap.builder();
        if (nodeReservation.getGeneral().getTotalReservedBytes() > 0) {
            pools.put(GENERAL_POOL, new MemoryPoolInfo(maxGeneralPoolBytes, nodeReservation.getGeneral().getTotalReservedBytes(), 0, nodeReservation.getGeneral().getReservationByQuery(), ImmutableMap.of(), ImmutableMap.of()));
        }
        if (nodeReservation.getReserved().getTotalReservedBytes() > 0) {
            pools.put(RESERVED_POOL, new MemoryPoolInfo(maxReservedPoolBytes, nodeReservation.getReserved().getTotalReservedBytes(), 0, nodeReservation.getReserved().getReservationByQuery(), ImmutableMap.of(), ImmutableMap.of()));
        }
        result.add(new MemoryInfo(new DataSize(maxReservedPoolBytes + maxGeneralPoolBytes, BYTE), pools.build()));
    }
    return result.build();
}
Also used : HashMap(java.util.HashMap) ImmutableList(com.google.common.collect.ImmutableList) QueryId(com.facebook.presto.spi.QueryId) ImmutableMap(com.google.common.collect.ImmutableMap) NodeVersion(com.facebook.presto.client.NodeVersion) DataSize(io.airlift.units.DataSize) MemoryPoolInfo(com.facebook.presto.spi.memory.MemoryPoolInfo) InternalNode(com.facebook.presto.metadata.InternalNode) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId)

Example 67 with InternalNode

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

the class QueryStateInfoResource method proxyQueryStateInfo.

// TODO the pattern of this function is similar with ClusterStatsResource and QueryResource, we can move it to a common place and re-use.
private void proxyQueryStateInfo(HttpServletRequest servletRequest, AsyncResponse asyncResponse, String xForwardedProto, UriInfo uriInfo) {
    try {
        checkState(proxyHelper.isPresent());
        Iterator<InternalNode> resourceManagers = internalNodeManager.getResourceManagers().iterator();
        if (!resourceManagers.hasNext()) {
            asyncResponse.resume(Response.status(SERVICE_UNAVAILABLE).build());
            return;
        }
        InternalNode resourceManagerNode = resourceManagers.next();
        URI uri = uriInfo.getRequestUriBuilder().scheme(resourceManagerNode.getInternalUri().getScheme()).host(resourceManagerNode.getHostAndPort().toInetAddress().getHostName()).port(resourceManagerNode.getInternalUri().getPort()).build();
        proxyHelper.get().performRequest(servletRequest, asyncResponse, uri);
    } catch (Exception e) {
        asyncResponse.resume(e);
    }
}
Also used : InternalNode(com.facebook.presto.metadata.InternalNode) URI(java.net.URI) NoSuchElementException(java.util.NoSuchElementException) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 68 with InternalNode

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

the class ResourceGroupStateInfoResource method proxyResourceGroupInfoResponse.

// TODO move this to a common place and reuse in all resource
private void proxyResourceGroupInfoResponse(HttpServletRequest servletRequest, AsyncResponse asyncResponse, String xForwardedProto, UriInfo uriInfo) {
    try {
        checkState(proxyHelper.isPresent());
        Iterator<InternalNode> resourceManagers = internalNodeManager.getResourceManagers().iterator();
        if (!resourceManagers.hasNext()) {
            asyncResponse.resume(Response.status(SERVICE_UNAVAILABLE).build());
            return;
        }
        InternalNode resourceManagerNode = resourceManagers.next();
        URI uri = uriInfo.getRequestUriBuilder().scheme(resourceManagerNode.getInternalUri().getScheme()).host(resourceManagerNode.getHostAndPort().toInetAddress().getHostName()).port(resourceManagerNode.getInternalUri().getPort()).build();
        proxyHelper.get().performRequest(servletRequest, asyncResponse, uri);
    } catch (Exception e) {
        asyncResponse.resume(e);
    }
}
Also used : InternalNode(com.facebook.presto.metadata.InternalNode) URI(java.net.URI) NoSuchElementException(java.util.NoSuchElementException) WebApplicationException(javax.ws.rs.WebApplicationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 69 with InternalNode

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

the class TestResourceManagerClusterStatusSender method setup.

@BeforeTest
public void setup() {
    resourceManagerClient = new TestingResourceManagerClient();
    InMemoryNodeManager nodeManager = new InMemoryNodeManager();
    nodeManager.addNode(CONNECTOR_ID, new InternalNode("identifier", URI.create("http://localhost:80/identifier"), OptionalInt.of(1), "1", false, true));
    sender = new ResourceManagerClusterStatusSender((addressSelectionContext, headers) -> resourceManagerClient, nodeManager, () -> NODE_STATUS, newSingleThreadScheduledExecutor(), new ResourceManagerConfig().setNodeHeartbeatInterval(new Duration(HEARTBEAT_INTERVAL, MILLISECONDS)).setQueryHeartbeatInterval(new Duration(HEARTBEAT_INTERVAL, MILLISECONDS)));
}
Also used : NodeStatus(com.facebook.presto.server.NodeStatus) ImmutableMap(com.google.common.collect.ImmutableMap) MockManagedQueryExecution(com.facebook.presto.execution.MockManagedQueryExecution) MEGABYTE(io.airlift.units.DataSize.Unit.MEGABYTE) Test(org.testng.annotations.Test) NodeVersion(com.facebook.presto.client.NodeVersion) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) OptionalInt(java.util.OptionalInt) MemoryInfo(com.facebook.presto.memory.MemoryInfo) String.format(java.lang.String.format) Duration(io.airlift.units.Duration) AfterTest(org.testng.annotations.AfterTest) InternalNode(com.facebook.presto.metadata.InternalNode) DataSize(io.airlift.units.DataSize) BeforeTest(org.testng.annotations.BeforeTest) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) Assert.assertTrue(org.testng.Assert.assertTrue) URI(java.net.URI) ConnectorId(com.facebook.presto.spi.ConnectorId) InMemoryNodeManager(com.facebook.presto.metadata.InMemoryNodeManager) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Duration(io.airlift.units.Duration) InternalNode(com.facebook.presto.metadata.InternalNode) InMemoryNodeManager(com.facebook.presto.metadata.InMemoryNodeManager) BeforeTest(org.testng.annotations.BeforeTest)

Example 70 with InternalNode

use of com.facebook.presto.metadata.InternalNode 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

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