Search in sources :

Example 1 with QUEUED

use of com.facebook.presto.execution.QueryState.QUEUED in project presto by prestodb.

the class ResourceManagerClusterStateProvider method getClusterResourceGroups.

public List<ResourceGroupRuntimeInfo> getClusterResourceGroups(String excludingNode) throws ResourceManagerInconsistentException {
    requireNonNull(excludingNode, "excludingNode is null");
    validateCoordinatorConsistency();
    Map<ResourceGroupId, ResourceGroupRuntimeInfo.Builder> resourceGroupBuilders = new HashMap<>();
    nodeQueryStates.values().stream().filter(state -> !state.getNodeId().equals(excludingNode)).map(CoordinatorQueriesState::getActiveQueries).flatMap(Collection::stream).map(Query::getBasicQueryInfo).filter(info -> info.getResourceGroupId().isPresent()).forEach(info -> {
        ResourceGroupId resourceGroupId = info.getResourceGroupId().get();
        ResourceGroupRuntimeInfo.Builder builder = resourceGroupBuilders.computeIfAbsent(resourceGroupId, ResourceGroupRuntimeInfo::builder);
        if (info.getState() == QUEUED) {
            builder.addQueuedQueries(1);
        } else if (!info.getState().isDone()) {
            builder.addRunningQueries(1);
        }
        builder.addUserMemoryReservationBytes(info.getQueryStats().getUserMemoryReservation().toBytes());
        while (resourceGroupId.getParent().isPresent()) {
            resourceGroupId = resourceGroupId.getParent().get();
            ResourceGroupRuntimeInfo.Builder parentBuilder = resourceGroupBuilders.computeIfAbsent(resourceGroupId, ResourceGroupRuntimeInfo::builder);
            if (info.getState() == QUEUED) {
                parentBuilder.addDescendantQueuedQueries(1);
            } else if (!info.getState().isDone()) {
                parentBuilder.addDescendantRunningQueries(1);
            }
        }
    });
    return resourceGroupBuilders.values().stream().map(ResourceGroupRuntimeInfo.Builder::build).collect(toImmutableList());
}
Also used : NodeStatus(com.facebook.presto.server.NodeStatus) QUEUED(com.facebook.presto.execution.QueryState.QUEUED) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) ClusterMemoryPool(com.facebook.presto.memory.ClusterMemoryPool) MemoryInfo(com.facebook.presto.memory.MemoryInfo) Duration(io.airlift.units.Duration) Inject(javax.inject.Inject) LinkedHashMap(java.util.LinkedHashMap) RESERVED_POOL(com.facebook.presto.memory.LocalMemoryManager.RESERVED_POOL) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) InternalNodeManager(com.facebook.presto.metadata.InternalNodeManager) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) GENERAL_POOL(com.facebook.presto.memory.LocalMemoryManager.GENERAL_POOL) Suppliers(com.google.common.base.Suppliers) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Stream.concat(java.util.stream.Stream.concat) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) URI(java.net.URI) SessionPropertyManager(com.facebook.presto.metadata.SessionPropertyManager) NodeMemoryConfig(com.facebook.presto.memory.NodeMemoryConfig) Iterator(java.util.Iterator) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) Set(java.util.Set) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) GuardedBy(javax.annotation.concurrent.GuardedBy) ResourceGroupRuntimeInfo(com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo) Sets(com.google.common.collect.Sets) String.format(java.lang.String.format) InternalNode(com.facebook.presto.metadata.InternalNode) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Stream(java.util.stream.Stream) ClusterMemoryPoolInfo(com.facebook.presto.spi.memory.ClusterMemoryPoolInfo) QueryId(com.facebook.presto.spi.QueryId) Optional(java.util.Optional) SystemSessionProperties.resourceOvercommit(com.facebook.presto.SystemSessionProperties.resourceOvercommit) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ResourceGroupRuntimeInfo(com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo)

Example 2 with QUEUED

use of com.facebook.presto.execution.QueryState.QUEUED in project presto by prestodb.

the class TestResourceManagerClusterStateProvider method assertResourceGroup.

private void assertResourceGroup(ResourceManagerClusterStateProvider provider, String excludingNode, String resourceGroupId, int queuedQueries, int runningQueries, DataSize userMemoryReservation) throws ResourceManagerInconsistentException {
    ResourceGroupId currResourceGroupId = new ResourceGroupId(Arrays.asList(resourceGroupId.split("\\.")));
    List<ResourceGroupRuntimeInfo> list = provider.getClusterResourceGroups(excludingNode);
    Optional<ResourceGroupRuntimeInfo> resourceGroupRuntimeInfo = list.stream().filter(resourceGroupInfo -> currResourceGroupId.equals(resourceGroupInfo.getResourceGroupId())).findFirst();
    assertTrue(resourceGroupRuntimeInfo.isPresent(), "Resource group " + resourceGroupId + " not found");
    ResourceGroupRuntimeInfo info = resourceGroupRuntimeInfo.get();
    ResourceGroupId rg = new ResourceGroupId(Arrays.asList(resourceGroupId.split("\\.")));
    assertEquals(info.getQueuedQueries(), queuedQueries, format("Expected %s queued queries, found %s", queuedQueries, info.getQueuedQueries()));
    assertEquals(info.getRunningQueries(), runningQueries, format("Expected %s running queries, found %s", runningQueries, info.getRunningQueries()));
    assertEquals(info.getResourceGroupId(), rg, format("Expected resource group id %s, found %s", resourceGroupId, info.getResourceGroupId()));
    assertEquals(info.getMemoryUsageBytes(), userMemoryReservation.toBytes(), format("Expected %s user memory reservation found %s", userMemoryReservation, DataSize.succinctBytes(info.getMemoryUsageBytes())));
}
Also used : Arrays(java.util.Arrays) Test(org.testng.annotations.Test) NodeVersion(com.facebook.presto.client.NodeVersion) FINISHING(com.facebook.presto.execution.QueryState.FINISHING) Duration(io.airlift.units.Duration) PLANNING(com.facebook.presto.execution.QueryState.PLANNING) RESERVED_POOL(com.facebook.presto.memory.LocalMemoryManager.RESERVED_POOL) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) WAITING_FOR_MEMORY(com.facebook.presto.operator.BlockedReason.WAITING_FOR_MEMORY) Map(java.util.Map) FAILED(com.facebook.presto.execution.QueryState.FAILED) GENERAL_POOL(com.facebook.presto.memory.LocalMemoryManager.GENERAL_POOL) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) URI(java.net.URI) BasicQueryStats(com.facebook.presto.server.BasicQueryStats) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) DISPATCHING(com.facebook.presto.execution.QueryState.DISPATCHING) WAITING_FOR_RESOURCES(com.facebook.presto.execution.QueryState.WAITING_FOR_RESOURCES) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) Assert.assertNotNull(org.testng.Assert.assertNotNull) ResourceGroupRuntimeInfo(com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo) String.format(java.lang.String.format) DataSize(io.airlift.units.DataSize) List(java.util.List) Optional(java.util.Optional) ConnectorId(com.facebook.presto.spi.ConnectorId) NodeStatus(com.facebook.presto.server.NodeStatus) QUEUED(com.facebook.presto.execution.QueryState.QUEUED) MEGABYTE(io.airlift.units.DataSize.Unit.MEGABYTE) OptionalDouble(java.util.OptionalDouble) Assert.assertEquals(org.testng.Assert.assertEquals) MemoryInfo(com.facebook.presto.memory.MemoryInfo) TEST_SESSION(com.facebook.presto.SessionTestUtils.TEST_SESSION) ImmutableList(com.google.common.collect.ImmutableList) MemoryPoolInfo(com.facebook.presto.spi.memory.MemoryPoolInfo) SessionPropertyManager(com.facebook.presto.metadata.SessionPropertyManager) InMemoryNodeManager(com.facebook.presto.metadata.InMemoryNodeManager) RUNNING(com.facebook.presto.execution.QueryState.RUNNING) DateTime(org.joda.time.DateTime) FINISHED(com.facebook.presto.execution.QueryState.FINISHED) InternalNode(com.facebook.presto.metadata.InternalNode) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId) ClusterMemoryPoolInfo(com.facebook.presto.spi.memory.ClusterMemoryPoolInfo) QueryId(com.facebook.presto.spi.QueryId) Assert.assertTrue(org.testng.Assert.assertTrue) STARTING(com.facebook.presto.execution.QueryState.STARTING) QueryState(com.facebook.presto.execution.QueryState) SECONDS(java.util.concurrent.TimeUnit.SECONDS) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) ResourceGroupRuntimeInfo(com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo)

Example 3 with QUEUED

use of com.facebook.presto.execution.QueryState.QUEUED in project presto by prestodb.

the class TestResourceManagerClusterStateProvider method assertNonLeafResourceGroup.

private void assertNonLeafResourceGroup(ResourceManagerClusterStateProvider provider, String excludingNode, String resourceGroupId, int queuedQueries, int runningQueries, int descendantQueuedQueries, int descendantRunningQueries) throws ResourceManagerInconsistentException {
    List<ResourceGroupRuntimeInfo> resourceGroupRuntimeInfos = provider.getClusterResourceGroups(excludingNode);
    Optional<ResourceGroupRuntimeInfo> resourceGroupRuntimeInfo = provider.getClusterResourceGroups(excludingNode).stream().filter(resourceGroupInfo -> new ResourceGroupId(resourceGroupId).equals(resourceGroupInfo.getResourceGroupId())).findFirst();
    assertTrue(resourceGroupRuntimeInfo.isPresent(), "Resource group " + resourceGroupId + " not found");
    ResourceGroupRuntimeInfo info = resourceGroupRuntimeInfo.get();
    assertEquals(info.getQueuedQueries(), queuedQueries, format("Expected %s queued queries, found %s", queuedQueries, info.getQueuedQueries()));
    assertEquals(info.getRunningQueries(), runningQueries, format("Expected %s running queries, found %s", runningQueries, info.getRunningQueries()));
    assertEquals(info.getDescendantQueuedQueries(), descendantQueuedQueries, format("Expected %s descendant queued queries, found %s", descendantQueuedQueries, info.getDescendantQueuedQueries()));
    assertEquals(info.getDescendantRunningQueries(), descendantRunningQueries, format("Expected %s descendant running queries, found %s", descendantRunningQueries, info.getDescendantRunningQueries()));
    assertEquals(info.getResourceGroupId(), new ResourceGroupId(resourceGroupId), format("Expected resource group id %s, found %s", resourceGroupId, info.getResourceGroupId()));
}
Also used : Arrays(java.util.Arrays) Test(org.testng.annotations.Test) NodeVersion(com.facebook.presto.client.NodeVersion) FINISHING(com.facebook.presto.execution.QueryState.FINISHING) Duration(io.airlift.units.Duration) PLANNING(com.facebook.presto.execution.QueryState.PLANNING) RESERVED_POOL(com.facebook.presto.memory.LocalMemoryManager.RESERVED_POOL) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) WAITING_FOR_MEMORY(com.facebook.presto.operator.BlockedReason.WAITING_FOR_MEMORY) Map(java.util.Map) FAILED(com.facebook.presto.execution.QueryState.FAILED) GENERAL_POOL(com.facebook.presto.memory.LocalMemoryManager.GENERAL_POOL) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) URI(java.net.URI) BasicQueryStats(com.facebook.presto.server.BasicQueryStats) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) DISPATCHING(com.facebook.presto.execution.QueryState.DISPATCHING) WAITING_FOR_RESOURCES(com.facebook.presto.execution.QueryState.WAITING_FOR_RESOURCES) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) Assert.assertNotNull(org.testng.Assert.assertNotNull) ResourceGroupRuntimeInfo(com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo) String.format(java.lang.String.format) DataSize(io.airlift.units.DataSize) List(java.util.List) Optional(java.util.Optional) ConnectorId(com.facebook.presto.spi.ConnectorId) NodeStatus(com.facebook.presto.server.NodeStatus) QUEUED(com.facebook.presto.execution.QueryState.QUEUED) MEGABYTE(io.airlift.units.DataSize.Unit.MEGABYTE) OptionalDouble(java.util.OptionalDouble) Assert.assertEquals(org.testng.Assert.assertEquals) MemoryInfo(com.facebook.presto.memory.MemoryInfo) TEST_SESSION(com.facebook.presto.SessionTestUtils.TEST_SESSION) ImmutableList(com.google.common.collect.ImmutableList) MemoryPoolInfo(com.facebook.presto.spi.memory.MemoryPoolInfo) SessionPropertyManager(com.facebook.presto.metadata.SessionPropertyManager) InMemoryNodeManager(com.facebook.presto.metadata.InMemoryNodeManager) RUNNING(com.facebook.presto.execution.QueryState.RUNNING) DateTime(org.joda.time.DateTime) FINISHED(com.facebook.presto.execution.QueryState.FINISHED) InternalNode(com.facebook.presto.metadata.InternalNode) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId) ClusterMemoryPoolInfo(com.facebook.presto.spi.memory.ClusterMemoryPoolInfo) QueryId(com.facebook.presto.spi.QueryId) Assert.assertTrue(org.testng.Assert.assertTrue) STARTING(com.facebook.presto.execution.QueryState.STARTING) QueryState(com.facebook.presto.execution.QueryState) SECONDS(java.util.concurrent.TimeUnit.SECONDS) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) ResourceGroupRuntimeInfo(com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo)

Aggregations

QUEUED (com.facebook.presto.execution.QueryState.QUEUED)3 ResourceGroupRuntimeInfo (com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo)3 GENERAL_POOL (com.facebook.presto.memory.LocalMemoryManager.GENERAL_POOL)3 RESERVED_POOL (com.facebook.presto.memory.LocalMemoryManager.RESERVED_POOL)3 MemoryInfo (com.facebook.presto.memory.MemoryInfo)3 InternalNode (com.facebook.presto.metadata.InternalNode)3 SessionPropertyManager (com.facebook.presto.metadata.SessionPropertyManager)3 BasicQueryInfo (com.facebook.presto.server.BasicQueryInfo)3 NodeStatus (com.facebook.presto.server.NodeStatus)3 QueryId (com.facebook.presto.spi.QueryId)3 ClusterMemoryPoolInfo (com.facebook.presto.spi.memory.ClusterMemoryPoolInfo)3 MemoryPoolId (com.facebook.presto.spi.memory.MemoryPoolId)3 ResourceGroupId (com.facebook.presto.spi.resourceGroups.ResourceGroupId)3 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Duration (io.airlift.units.Duration)3 String.format (java.lang.String.format)3 URI (java.net.URI)3 List (java.util.List)3 Map (java.util.Map)3