Search in sources :

Example 16 with ResourceGroupId

use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.

the class TestStaticSelector method testClientTags.

@Test
public void testClientTags() {
    ResourceGroupId resourceGroupId = new ResourceGroupId(new ResourceGroupId("global"), "foo");
    StaticSelector selector = new StaticSelector(Optional.empty(), Optional.empty(), Optional.of(ImmutableList.of("tag1", "tag2")), Optional.empty(), Optional.empty(), new ResourceGroupIdTemplate("global.foo"));
    assertEquals(selector.match(newSelectionCriteria("userA", null, ImmutableSet.of("tag1", "tag2"), EMPTY_RESOURCE_ESTIMATES)).map(SelectionContext::getResourceGroupId), Optional.of(resourceGroupId));
    assertEquals(selector.match(newSelectionCriteria("userB", "source", ImmutableSet.of(), EMPTY_RESOURCE_ESTIMATES)), Optional.empty());
    assertEquals(selector.match(newSelectionCriteria("A.user", "a source b", ImmutableSet.of("tag1"), EMPTY_RESOURCE_ESTIMATES)), Optional.empty());
    assertEquals(selector.match(newSelectionCriteria("A.user", "a source b", ImmutableSet.of("tag1", "tag2", "tag3"), EMPTY_RESOURCE_ESTIMATES)).map(SelectionContext::getResourceGroupId), Optional.of(resourceGroupId));
}
Also used : ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) Test(org.testng.annotations.Test)

Example 17 with ResourceGroupId

use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.

the class TestStaticSelector method testUserRegex.

@Test
public void testUserRegex() {
    ResourceGroupId resourceGroupId = new ResourceGroupId(new ResourceGroupId("global"), "foo");
    StaticSelector selector = new StaticSelector(Optional.of(Pattern.compile("user.*")), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), new ResourceGroupIdTemplate("global.foo"));
    assertEquals(selector.match(newSelectionCriteria("userA", null, ImmutableSet.of("tag1"), EMPTY_RESOURCE_ESTIMATES)).map(SelectionContext::getResourceGroupId), Optional.of(resourceGroupId));
    assertEquals(selector.match(newSelectionCriteria("userB", "source", ImmutableSet.of(), EMPTY_RESOURCE_ESTIMATES)).map(SelectionContext::getResourceGroupId), Optional.of(resourceGroupId));
    assertEquals(selector.match(newSelectionCriteria("A.user", null, ImmutableSet.of("tag1"), EMPTY_RESOURCE_ESTIMATES)), Optional.empty());
}
Also used : ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) Test(org.testng.annotations.Test)

Example 18 with ResourceGroupId

use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.

the class TestQueryStateMachine method createQueryStateMachineWithTicker.

private QueryStateMachine createQueryStateMachineWithTicker(Ticker ticker, TransactionManager transactionManager) {
    Metadata metadata = MetadataManager.createTestMetadataManager();
    AccessControl accessControl = new AccessControlManager(transactionManager);
    QueryStateMachine stateMachine = QueryStateMachine.beginWithTicker(QUERY, Optional.empty(), TEST_SESSION, LOCATION, new ResourceGroupId("test"), QUERY_TYPE, false, transactionManager, accessControl, executor, ticker, metadata, WarningCollector.NOOP);
    stateMachine.setInputs(INPUTS);
    stateMachine.setOutput(OUTPUT);
    stateMachine.setColumns(OUTPUT_FIELD_NAMES, OUTPUT_FIELD_TYPES);
    stateMachine.setUpdateType(UPDATE_TYPE);
    stateMachine.setMemoryPool(MEMORY_POOL);
    for (Entry<String, String> entry : SET_SESSION_PROPERTIES.entrySet()) {
        stateMachine.addSetSessionProperties(entry.getKey(), entry.getValue());
    }
    RESET_SESSION_PROPERTIES.forEach(stateMachine::addResetSessionProperties);
    return stateMachine;
}
Also used : AccessControlManager(com.facebook.presto.security.AccessControlManager) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) Metadata(com.facebook.presto.metadata.Metadata) AccessControl(com.facebook.presto.security.AccessControl)

Example 19 with ResourceGroupId

use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.

the class InternalResourceGroupManager method createGroupIfNecessary.

private synchronized void createGroupIfNecessary(SelectionContext<C> context, Executor executor) {
    ResourceGroupId id = context.getResourceGroupId();
    if (!groups.containsKey(id)) {
        InternalResourceGroup group;
        if (id.getParent().isPresent()) {
            createGroupIfNecessary(new SelectionContext<>(id.getParent().get(), context.getContext()), executor);
            InternalResourceGroup parent = groups.get(id.getParent().get());
            requireNonNull(parent, "parent is null");
            // parent segments size equals to subgroup segment index
            int subGroupSegmentIndex = parent.getId().getSegments().size();
            group = parent.getOrCreateSubGroup(id.getLastSegment(), !context.getFirstDynamicSegmentPosition().equals(OptionalInt.of(subGroupSegmentIndex)));
        } else {
            RootInternalResourceGroup root;
            if (!isResourceManagerEnabled) {
                root = new RootInternalResourceGroup(id.getSegments().get(0), this::exportGroup, executor, ignored -> Optional.empty(), rg -> false);
            } else {
                root = new RootInternalResourceGroup(id.getSegments().get(0), this::exportGroup, executor, resourceGroupId -> Optional.ofNullable(resourceGroupRuntimeInfosSnapshot.get().get(resourceGroupId)), rg -> shouldWaitForResourceManagerUpdate(rg, resourceGroupRuntimeInfosSnapshot::get, lastUpdatedResourceGroupRuntimeInfo::get, concurrencyThreshold));
            }
            group = root;
            rootGroups.add(root);
        }
        configurationManager.get().configure(group, context);
        checkState(groups.put(id, group) == null, "Unexpected existing resource group");
    }
}
Also used : LongSupplier(java.util.function.LongSupplier) QUERY_REJECTED(com.facebook.presto.spi.StandardErrorCode.QUERY_REJECTED) Duration(io.airlift.units.Duration) PreDestroy(javax.annotation.PreDestroy) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Executors.newScheduledThreadPool(java.util.concurrent.Executors.newScheduledThreadPool) ManagedQueryExecution(com.facebook.presto.execution.ManagedQueryExecution) Map(java.util.Map) QueryManagerConfig(com.facebook.presto.execution.QueryManagerConfig) ResourceGroupConfigurationManager(com.facebook.presto.spi.resourceGroups.ResourceGroupConfigurationManager) ServerConfig(com.facebook.presto.server.ServerConfig) ObjectNames(org.weakref.jmx.ObjectNames) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) ThreadSafe(javax.annotation.concurrent.ThreadSafe) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) RootInternalResourceGroup(com.facebook.presto.execution.resourceGroups.InternalResourceGroup.RootInternalResourceGroup) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Threads.daemonThreadsNamed(com.facebook.airlift.concurrent.Threads.daemonThreadsNamed) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) JmxException(org.weakref.jmx.JmxException) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Logger(com.facebook.airlift.log.Logger) ResourceGroupConfigurationManagerFactory(com.facebook.presto.spi.resourceGroups.ResourceGroupConfigurationManagerFactory) System.currentTimeMillis(java.lang.System.currentTimeMillis) PeriodicTaskExecutor(com.facebook.presto.util.PeriodicTaskExecutor) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) NodeInfo(com.facebook.airlift.node.NodeInfo) ResourceGroupInfo(com.facebook.presto.server.ResourceGroupInfo) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) HashMap(java.util.HashMap) PrestoException(com.facebook.presto.spi.PrestoException) ResourceGroupService(com.facebook.presto.resourcemanager.ResourceGroupService) OptionalInt(java.util.OptionalInt) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) ConcurrentMap(java.util.concurrent.ConcurrentMap) Inject(javax.inject.Inject) Managed(org.weakref.jmx.Managed) SelectionContext(com.facebook.presto.spi.resourceGroups.SelectionContext) Objects.requireNonNull(java.util.Objects.requireNonNull) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) PropertiesUtil.loadProperties(com.facebook.presto.util.PropertiesUtil.loadProperties) ClusterMemoryPoolManager(com.facebook.presto.spi.memory.ClusterMemoryPoolManager) ResourceGroupConfigurationManagerContext(com.facebook.presto.spi.resourceGroups.ResourceGroupConfigurationManagerContext) Executor(java.util.concurrent.Executor) SelectionCriteria(com.facebook.presto.spi.resourceGroups.SelectionCriteria) File(java.io.File) AtomicLong(java.util.concurrent.atomic.AtomicLong) VisibleForTesting(com.google.common.annotations.VisibleForTesting) MBeanExporter(org.weakref.jmx.MBeanExporter) Statement(com.facebook.presto.sql.tree.Statement) RootInternalResourceGroup(com.facebook.presto.execution.resourceGroups.InternalResourceGroup.RootInternalResourceGroup) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) RootInternalResourceGroup(com.facebook.presto.execution.resourceGroups.InternalResourceGroup.RootInternalResourceGroup)

Example 20 with ResourceGroupId

use of com.facebook.presto.spi.resourceGroups.ResourceGroupId 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)

Aggregations

ResourceGroupId (com.facebook.presto.spi.resourceGroups.ResourceGroupId)41 Test (org.testng.annotations.Test)31 QueryId (com.facebook.presto.spi.QueryId)12 ResourceGroupRuntimeInfo (com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo)9 ResourceGroupInfo (com.facebook.presto.server.ResourceGroupInfo)5 DistributedQueryRunner (com.facebook.presto.tests.DistributedQueryRunner)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 Duration (io.airlift.units.Duration)5 String.format (java.lang.String.format)5 Optional (java.util.Optional)5 TestQueues.createResourceGroupId (com.facebook.presto.execution.TestQueues.createResourceGroupId)4 BasicQueryInfo (com.facebook.presto.server.BasicQueryInfo)4 InMemoryNodeManager (com.facebook.presto.metadata.InMemoryNodeManager)3 DataSize (io.airlift.units.DataSize)3 HashMap (java.util.HashMap)3 SECONDS (java.util.concurrent.TimeUnit.SECONDS)3 Assert.assertEquals (org.testng.Assert.assertEquals)3 Assert.assertTrue (org.testng.Assert.assertTrue)3 Session (com.facebook.presto.Session)2 TEST_SESSION (com.facebook.presto.SessionTestUtils.TEST_SESSION)2