Search in sources :

Example 86 with QueryId

use of com.facebook.presto.spi.QueryId in project presto by prestodb.

the class TestMemoryPools method testMoveQuery.

@Test
public void testMoveQuery() {
    QueryId testQuery = new QueryId("test_query");
    MemoryPool pool1 = new MemoryPool(new MemoryPoolId("test"), new DataSize(1000, BYTE));
    MemoryPool pool2 = new MemoryPool(new MemoryPoolId("test"), new DataSize(1000, BYTE));
    pool1.reserve(testQuery, "test_tag", 10);
    Map<String, Long> allocations = pool1.getTaggedMemoryAllocations(testQuery);
    assertEquals(allocations, ImmutableMap.of("test_tag", 10L));
    pool1.moveQuery(testQuery, pool2);
    assertNull(pool1.getTaggedMemoryAllocations(testQuery));
    allocations = pool2.getTaggedMemoryAllocations(testQuery);
    assertEquals(allocations, ImmutableMap.of("test_tag", 10L));
    assertEquals(pool1.getFreeBytes(), 1000);
    assertEquals(pool2.getFreeBytes(), 990);
    pool2.free(testQuery, "test", 10);
    assertEquals(pool2.getFreeBytes(), 1000);
}
Also used : QueryId(com.facebook.presto.spi.QueryId) DataSize(io.airlift.units.DataSize) AtomicLong(java.util.concurrent.atomic.AtomicLong) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId) Test(org.testng.annotations.Test)

Example 87 with QueryId

use of com.facebook.presto.spi.QueryId in project presto by prestodb.

the class LocalQueryProvider method getQuery.

public Query getQuery(QueryId queryId, String slug) {
    Query query = queries.get(queryId);
    if (query != null) {
        if (!query.isSlugValid(slug)) {
            throw notFound("Query not found");
        }
        return query;
    }
    // this is the first time the query has been accessed on this coordinator
    Session session;
    try {
        if (!queryManager.isQuerySlugValid(queryId, slug)) {
            throw notFound("Query not found");
        }
        session = queryManager.getQuerySession(queryId);
    } catch (NoSuchElementException e) {
        throw notFound("Query not found");
    }
    query = queries.computeIfAbsent(queryId, id -> {
        ExchangeClient exchangeClient = exchangeClientSupplier.get(new SimpleLocalMemoryContext(newSimpleAggregatedMemoryContext(), LocalQueryProvider.class.getSimpleName()));
        return Query.create(session, slug, queryManager, transactionManager, exchangeClient, responseExecutor, timeoutExecutor, blockEncodingSerde, retryCircuitBreaker);
    });
    return query;
}
Also used : Logger(com.facebook.airlift.log.Logger) QueryManager(com.facebook.presto.execution.QueryManager) BlockEncodingSerde(com.facebook.presto.common.block.BlockEncodingSerde) ConcurrentMap(java.util.concurrent.ConcurrentMap) Inject(javax.inject.Inject) PreDestroy(javax.annotation.PreDestroy) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) BoundedExecutor(com.facebook.airlift.concurrent.BoundedExecutor) SimpleLocalMemoryContext(com.facebook.presto.memory.context.SimpleLocalMemoryContext) Objects.requireNonNull(java.util.Objects.requireNonNull) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) NoSuchElementException(java.util.NoSuchElementException) AggregatedMemoryContext.newSimpleAggregatedMemoryContext(com.facebook.presto.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext) TransactionManager(com.facebook.presto.transaction.TransactionManager) Status(javax.ws.rs.core.Response.Status) Threads.threadsNamed(com.facebook.airlift.concurrent.Threads.threadsNamed) Session(com.facebook.presto.Session) ExchangeClient(com.facebook.presto.operator.ExchangeClient) ExchangeClientSupplier(com.facebook.presto.operator.ExchangeClientSupplier) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) TEXT_PLAIN_TYPE(javax.ws.rs.core.MediaType.TEXT_PLAIN_TYPE) Response(javax.ws.rs.core.Response) QueryId(com.facebook.presto.spi.QueryId) PostConstruct(javax.annotation.PostConstruct) Entry(java.util.Map.Entry) ForStatementResource(com.facebook.presto.server.ForStatementResource) WebApplicationException(javax.ws.rs.WebApplicationException) ExchangeClient(com.facebook.presto.operator.ExchangeClient) SimpleLocalMemoryContext(com.facebook.presto.memory.context.SimpleLocalMemoryContext) NoSuchElementException(java.util.NoSuchElementException) Session(com.facebook.presto.Session)

Example 88 with QueryId

use of com.facebook.presto.spi.QueryId in project presto by prestodb.

the class TestSourcePartitionedScheduler method createSqlStageExecution.

private SqlStageExecution createSqlStageExecution(SubPlan tableScanPlan, NodeTaskMap nodeTaskMap) {
    StageId stageId = new StageId(new QueryId("query"), 0);
    SqlStageExecution stage = SqlStageExecution.createSqlStageExecution(new StageExecutionId(stageId, 0), tableScanPlan.getFragment(), new MockRemoteTaskFactory(queryExecutor, scheduledExecutor), TEST_SESSION, true, nodeTaskMap, queryExecutor, new NoOpFailureDetector(), new SplitSchedulerStats(), new TableWriteInfo(Optional.empty(), Optional.empty(), Optional.empty()));
    stage.setOutputBuffers(createInitialEmptyOutputBuffers(PARTITIONED).withBuffer(OUT, 0).withNoMoreBufferIds());
    return stage;
}
Also used : NoOpFailureDetector(com.facebook.presto.failureDetector.NoOpFailureDetector) StageId(com.facebook.presto.execution.StageId) QueryId(com.facebook.presto.spi.QueryId) SqlStageExecution(com.facebook.presto.execution.SqlStageExecution) StageExecutionId(com.facebook.presto.execution.StageExecutionId) MockRemoteTaskFactory(com.facebook.presto.execution.MockRemoteTaskFactory)

Example 89 with QueryId

use of com.facebook.presto.spi.QueryId in project presto by prestodb.

the class TestQueryContext method testSetMemoryPool.

@Test(dataProvider = "testSetMemoryPoolOptions")
public void testSetMemoryPool(boolean useReservedPool) {
    QueryId secondQuery = new QueryId("second");
    MemoryPool reservedPool = new MemoryPool(RESERVED_POOL, new DataSize(10, BYTE));
    long secondQueryMemory = reservedPool.getMaxBytes() - 1;
    if (useReservedPool) {
        assertTrue(reservedPool.reserve(secondQuery, "test", secondQueryMemory).isDone());
    }
    try (LocalQueryRunner localQueryRunner = new LocalQueryRunner(TEST_SESSION)) {
        QueryContext queryContext = new QueryContext(new QueryId("query"), new DataSize(10, BYTE), new DataSize(20, BYTE), new DataSize(10, BYTE), new DataSize(1, GIGABYTE), new MemoryPool(GENERAL_POOL, new DataSize(10, BYTE)), new TestingGcMonitor(), localQueryRunner.getExecutor(), localQueryRunner.getScheduler(), new DataSize(0, BYTE), new SpillSpaceTracker(new DataSize(0, BYTE)), listJsonCodec(TaskMemoryReservationSummary.class));
        // Use memory
        queryContext.getQueryMemoryContext().initializeLocalMemoryContexts("test");
        LocalMemoryContext userMemoryContext = queryContext.getQueryMemoryContext().localUserMemoryContext();
        LocalMemoryContext revocableMemoryContext = queryContext.getQueryMemoryContext().localRevocableMemoryContext();
        assertTrue(userMemoryContext.setBytes(3).isDone());
        assertTrue(revocableMemoryContext.setBytes(5).isDone());
        queryContext.setMemoryPool(reservedPool);
        if (useReservedPool) {
            reservedPool.free(secondQuery, "test", secondQueryMemory);
        }
        // Free memory
        userMemoryContext.close();
        revocableMemoryContext.close();
    }
}
Also used : TaskMemoryReservationSummary(com.facebook.presto.operator.TaskMemoryReservationSummary) LocalMemoryContext(com.facebook.presto.memory.context.LocalMemoryContext) SpillSpaceTracker(com.facebook.presto.spiller.SpillSpaceTracker) QueryId(com.facebook.presto.spi.QueryId) DataSize(io.airlift.units.DataSize) TestingGcMonitor(com.facebook.airlift.stats.TestingGcMonitor) LocalQueryRunner(com.facebook.presto.testing.LocalQueryRunner) Test(org.testng.annotations.Test)

Example 90 with QueryId

use of com.facebook.presto.spi.QueryId in project presto by prestodb.

the class TestQueryContext method testMoveTaggedAllocations.

@Test
public void testMoveTaggedAllocations() {
    MemoryPool generalPool = new MemoryPool(GENERAL_POOL, new DataSize(10_000, BYTE));
    MemoryPool reservedPool = new MemoryPool(RESERVED_POOL, new DataSize(10_000, BYTE));
    QueryId queryId = new QueryId("query");
    QueryContext queryContext = createQueryContext(queryId, generalPool);
    TaskStateMachine taskStateMachine = new TaskStateMachine(TaskId.valueOf("queryid.0.0.0"), TEST_EXECUTOR);
    TaskContext taskContext = queryContext.addTaskContext(taskStateMachine, TEST_SESSION, Optional.of(PLAN_FRAGMENT.getRoot()), false, false, false, false, false);
    DriverContext driverContext = taskContext.addPipelineContext(0, false, false, false).addDriverContext();
    OperatorContext operatorContext = driverContext.addOperatorContext(0, new PlanNodeId("test"), "test");
    // allocate some memory in the general pool
    LocalMemoryContext memoryContext = operatorContext.aggregateUserMemoryContext().newLocalMemoryContext("test_context");
    memoryContext.setBytes(1_000);
    Map<String, Long> allocations = generalPool.getTaggedMemoryAllocations(queryId);
    assertEquals(allocations, ImmutableMap.of("test_context", 1_000L));
    queryContext.setMemoryPool(reservedPool);
    assertNull(generalPool.getTaggedMemoryAllocations(queryId));
    allocations = reservedPool.getTaggedMemoryAllocations(queryId);
    assertEquals(allocations, ImmutableMap.of("test_context", 1_000L));
    assertEquals(generalPool.getFreeBytes(), 10_000);
    assertEquals(reservedPool.getFreeBytes(), 9_000);
    memoryContext.close();
    assertEquals(generalPool.getFreeBytes(), 10_000);
    assertEquals(reservedPool.getFreeBytes(), 10_000);
}
Also used : DriverContext(com.facebook.presto.operator.DriverContext) LocalMemoryContext(com.facebook.presto.memory.context.LocalMemoryContext) TaskContext(com.facebook.presto.operator.TaskContext) QueryId(com.facebook.presto.spi.QueryId) TaskStateMachine(com.facebook.presto.execution.TaskStateMachine) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) DataSize(io.airlift.units.DataSize) OperatorContext(com.facebook.presto.operator.OperatorContext) Test(org.testng.annotations.Test)

Aggregations

QueryId (com.facebook.presto.spi.QueryId)121 Test (org.testng.annotations.Test)79 DistributedQueryRunner (com.facebook.presto.tests.DistributedQueryRunner)19 DataSize (io.airlift.units.DataSize)18 MemoryPoolId (com.facebook.presto.spi.memory.MemoryPoolId)17 Session (com.facebook.presto.Session)16 BasicQueryInfo (com.facebook.presto.server.BasicQueryInfo)16 QueryManager (com.facebook.presto.execution.QueryManager)15 Identity (com.facebook.presto.spi.security.Identity)11 ImmutableMap (com.google.common.collect.ImmutableMap)11 ArrayList (java.util.ArrayList)11 ResourceGroupManagerPlugin (com.facebook.presto.resourceGroups.ResourceGroupManagerPlugin)10 PrestoException (com.facebook.presto.spi.PrestoException)10 ConnectorIdentity (com.facebook.presto.spi.security.ConnectorIdentity)10 List (java.util.List)10 SqlTask.createSqlTask (com.facebook.presto.execution.SqlTask.createSqlTask)9 MemoryPool (com.facebook.presto.memory.MemoryPool)9 ImmutableList (com.google.common.collect.ImmutableList)9 ResourceGroupId (com.facebook.presto.spi.resourceGroups.ResourceGroupId)8 DispatchManager (com.facebook.presto.dispatcher.DispatchManager)7