Search in sources :

Example 11 with TransactionId

use of com.facebook.presto.transaction.TransactionId in project presto by prestodb.

the class QueryStateMachine method beginWithTicker.

static QueryStateMachine beginWithTicker(QueryId queryId, String query, Session session, URI self, boolean transactionControl, TransactionManager transactionManager, AccessControl accessControl, Executor executor, Ticker ticker, Metadata metadata) {
    session.getTransactionId().ifPresent(transactionControl ? transactionManager::trySetActive : transactionManager::checkAndSetActive);
    Session querySession;
    boolean autoCommit = !session.getTransactionId().isPresent() && !transactionControl;
    if (autoCommit) {
        // TODO: make autocommit isolation level a session parameter
        TransactionId transactionId = transactionManager.beginTransaction(true);
        querySession = session.beginTransactionId(transactionId, transactionManager, accessControl);
    } else {
        querySession = session;
    }
    QueryStateMachine queryStateMachine = new QueryStateMachine(queryId, query, querySession, self, autoCommit, transactionManager, executor, ticker, metadata);
    queryStateMachine.addStateChangeListener(newState -> log.debug("Query %s is %s", queryId, newState));
    queryStateMachine.addStateChangeListener(newState -> {
        if (newState.isDone()) {
            session.getTransactionId().ifPresent(transactionManager::trySetInactive);
        }
    });
    return queryStateMachine;
}
Also used : Session(com.facebook.presto.Session) TransactionId(com.facebook.presto.transaction.TransactionId)

Example 12 with TransactionId

use of com.facebook.presto.transaction.TransactionId in project presto by prestodb.

the class TestQueryStateMachine method testTransitionToFailedAfterTransitionToFinishing.

@Test
public void testTransitionToFailedAfterTransitionToFinishing() {
    SettableFuture<?> commitFuture = SettableFuture.create();
    TransactionManager transactionManager = new DelegatingTransactionManager(createTestTransactionManager()) {

        @Override
        public ListenableFuture<?> asyncCommit(TransactionId transactionId) {
            return allAsList(commitFuture, super.asyncCommit(transactionId));
        }
    };
    QueryStateMachine stateMachine = createQueryStateMachine(transactionManager);
    stateMachine.transitionToFinishing();
    assertEquals(stateMachine.getQueryState(), FINISHING);
    assertFalse(stateMachine.transitionToFailed(new RuntimeException("failed")));
    assertEquals(stateMachine.getQueryState(), FINISHING);
    commitFuture.set(null);
    tryGetFutureValue(stateMachine.getStateChange(FINISHED), 2, SECONDS);
    assertEquals(stateMachine.getQueryState(), FINISHED);
}
Also used : DelegatingTransactionManager(com.facebook.presto.transaction.DelegatingTransactionManager) InMemoryTransactionManager.createTestTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager.createTestTransactionManager) TransactionManager(com.facebook.presto.transaction.TransactionManager) DelegatingTransactionManager(com.facebook.presto.transaction.DelegatingTransactionManager) TransactionId(com.facebook.presto.transaction.TransactionId) Test(org.testng.annotations.Test)

Example 13 with TransactionId

use of com.facebook.presto.transaction.TransactionId in project presto by prestodb.

the class QueryMonitor method logQueryTimeline.

private static void logQueryTimeline(BasicQueryInfo queryInfo) {
    DateTime queryStartTime = queryInfo.getQueryStats().getCreateTime();
    DateTime queryEndTime = queryInfo.getQueryStats().getEndTime();
    // query didn't finish cleanly
    if (queryStartTime == null || queryEndTime == null) {
        return;
    }
    long elapsed = max(queryEndTime.getMillis() - queryStartTime.getMillis(), 0);
    logQueryTimeline(queryInfo.getQueryId(), queryInfo.getSession().getTransactionId().map(TransactionId::toString).orElse(""), elapsed, elapsed, 0, 0, 0, queryStartTime, queryEndTime);
}
Also used : DateTime(org.joda.time.DateTime) TransactionId(com.facebook.presto.transaction.TransactionId)

Example 14 with TransactionId

use of com.facebook.presto.transaction.TransactionId in project presto by prestodb.

the class QueryMonitor method logQueryTimeline.

private static void logQueryTimeline(QueryInfo queryInfo) {
    try {
        QueryStats queryStats = queryInfo.getQueryStats();
        DateTime queryStartTime = queryStats.getCreateTime();
        DateTime queryEndTime = queryStats.getEndTime();
        // query didn't finish cleanly
        if (queryStartTime == null || queryEndTime == null) {
            return;
        }
        // planning duration -- start to end of planning
        long planning = queryStats.getTotalPlanningTime().toMillis();
        List<StageInfo> stages = getAllStages(queryInfo.getOutputStage());
        // long lastSchedulingCompletion = 0;
        long firstTaskStartTime = queryEndTime.getMillis();
        long lastTaskStartTime = queryStartTime.getMillis() + planning;
        long lastTaskEndTime = queryStartTime.getMillis() + planning;
        for (StageInfo stage : stages) {
            // only consider leaf stages
            if (!stage.getSubStages().isEmpty()) {
                continue;
            }
            for (TaskInfo taskInfo : stage.getLatestAttemptExecutionInfo().getTasks()) {
                TaskStats taskStats = taskInfo.getStats();
                DateTime firstStartTime = taskStats.getFirstStartTime();
                if (firstStartTime != null) {
                    firstTaskStartTime = Math.min(firstStartTime.getMillis(), firstTaskStartTime);
                }
                DateTime lastStartTime = taskStats.getLastStartTime();
                if (lastStartTime != null) {
                    lastTaskStartTime = max(lastStartTime.getMillis(), lastTaskStartTime);
                }
                DateTime endTime = taskStats.getEndTime();
                if (endTime != null) {
                    lastTaskEndTime = max(endTime.getMillis(), lastTaskEndTime);
                }
            }
        }
        long elapsed = max(queryEndTime.getMillis() - queryStartTime.getMillis(), 0);
        long scheduling = max(firstTaskStartTime - queryStartTime.getMillis() - planning, 0);
        long running = max(lastTaskEndTime - firstTaskStartTime, 0);
        long finishing = max(queryEndTime.getMillis() - lastTaskEndTime, 0);
        logQueryTimeline(queryInfo.getQueryId(), queryInfo.getSession().getTransactionId().map(TransactionId::toString).orElse(""), elapsed, planning, scheduling, running, finishing, queryStartTime, queryEndTime);
    } catch (Exception e) {
        log.error(e, "Error logging query timeline");
    }
}
Also used : TaskInfo(com.facebook.presto.execution.TaskInfo) QueryStats(com.facebook.presto.execution.QueryStats) StageInfo(com.facebook.presto.execution.StageInfo) TaskStats(com.facebook.presto.operator.TaskStats) DateTime(org.joda.time.DateTime) TransactionId(com.facebook.presto.transaction.TransactionId)

Example 15 with TransactionId

use of com.facebook.presto.transaction.TransactionId in project presto by prestodb.

the class TestInformationSchemaMetadata method testInformationSchemaPredicatePushdownWithConstraintPredicate.

@Test
public void testInformationSchemaPredicatePushdownWithConstraintPredicate() {
    TransactionId transactionId = transactionManager.beginTransaction(false);
    Constraint<ColumnHandle> constraint = new Constraint<>(TupleDomain.all(), // test_schema has a table named "another_table" and we filter that out in this predicate
    bindings -> {
        NullableValue catalog = bindings.get(new InformationSchemaColumnHandle("table_catalog"));
        NullableValue schema = bindings.get(new InformationSchemaColumnHandle("table_schema"));
        NullableValue table = bindings.get(new InformationSchemaColumnHandle("table_name"));
        boolean isValid = true;
        if (catalog != null) {
            isValid = ((Slice) catalog.getValue()).toStringUtf8().equals("test_catalog");
        }
        if (schema != null) {
            isValid &= ((Slice) schema.getValue()).toStringUtf8().equals("test_schema");
        }
        if (table != null) {
            isValid &= ((Slice) table.getValue()).toStringUtf8().equals("test_view");
        }
        return isValid;
    });
    InformationSchemaMetadata informationSchemaMetadata = new InformationSchemaMetadata("test_catalog", metadata);
    List<ConnectorTableLayoutResult> layoutResults = informationSchemaMetadata.getTableLayouts(createNewSession(transactionId), new InformationSchemaTableHandle("test_catalog", "information_schema", "views"), constraint, Optional.empty());
    assertEquals(layoutResults.size(), 1);
    ConnectorTableLayoutHandle handle = layoutResults.get(0).getTableLayout().getHandle();
    assertTrue(handle instanceof InformationSchemaTableLayoutHandle);
    InformationSchemaTableLayoutHandle tableHandle = (InformationSchemaTableLayoutHandle) handle;
    assertEquals(tableHandle.getPrefixes(), ImmutableSet.of(new QualifiedTablePrefix("test_catalog", "test_schema", "test_view")));
}
Also used : InformationSchemaColumnHandle(com.facebook.presto.connector.informationSchema.InformationSchemaColumnHandle) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ConnectorTableLayoutHandle(com.facebook.presto.spi.ConnectorTableLayoutHandle) Constraint(com.facebook.presto.spi.Constraint) NullableValue(com.facebook.presto.common.predicate.NullableValue) TransactionId(com.facebook.presto.transaction.TransactionId) InformationSchemaTableHandle(com.facebook.presto.connector.informationSchema.InformationSchemaTableHandle) ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult) Slice(io.airlift.slice.Slice) InformationSchemaColumnHandle(com.facebook.presto.connector.informationSchema.InformationSchemaColumnHandle) InformationSchemaTableLayoutHandle(com.facebook.presto.connector.informationSchema.InformationSchemaTableLayoutHandle) InformationSchemaMetadata(com.facebook.presto.connector.informationSchema.InformationSchemaMetadata) Test(org.testng.annotations.Test)

Aggregations

TransactionId (com.facebook.presto.transaction.TransactionId)17 Session (com.facebook.presto.Session)5 Test (org.testng.annotations.Test)5 PrestoException (com.facebook.presto.spi.PrestoException)4 DateTime (org.joda.time.DateTime)4 QueryStats (com.facebook.presto.execution.QueryStats)3 StageInfo (com.facebook.presto.execution.StageInfo)3 TaskInfo (com.facebook.presto.execution.TaskInfo)3 TaskStats (com.facebook.presto.operator.TaskStats)3 InformationSchemaColumnHandle (com.facebook.presto.connector.informationSchema.InformationSchemaColumnHandle)2 InformationSchemaMetadata (com.facebook.presto.connector.informationSchema.InformationSchemaMetadata)2 InformationSchemaTableHandle (com.facebook.presto.connector.informationSchema.InformationSchemaTableHandle)2 InformationSchemaTableLayoutHandle (com.facebook.presto.connector.informationSchema.InformationSchemaTableLayoutHandle)2 QueryInfo (com.facebook.presto.execution.QueryInfo)2 ColumnHandle (com.facebook.presto.spi.ColumnHandle)2 ConnectorTableLayoutHandle (com.facebook.presto.spi.ConnectorTableLayoutHandle)2 ConnectorTableLayoutResult (com.facebook.presto.spi.ConnectorTableLayoutResult)2 Constraint (com.facebook.presto.spi.Constraint)2 QueryId (com.facebook.presto.spi.QueryId)2 DelegatingTransactionManager (com.facebook.presto.transaction.DelegatingTransactionManager)2