Search in sources :

Example 1 with TransactionId

use of io.prestosql.transaction.TransactionId in project hetu-core by openlookeng.

the class StartTransactionTask method execute.

@Override
public ListenableFuture<?> execute(StartTransaction statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
    Session session = stateMachine.getSession();
    if (!session.isClientTransactionSupport()) {
        throw new PrestoException(StandardErrorCode.INCOMPATIBLE_CLIENT, "Client does not support transactions");
    }
    if (session.getTransactionId().isPresent()) {
        throw new PrestoException(StandardErrorCode.NOT_SUPPORTED, "Nested transactions not supported");
    }
    Optional<IsolationLevel> isolationLevel = extractIsolationLevel(statement);
    Optional<Boolean> readOnly = extractReadOnly(statement);
    TransactionId transactionId = transactionManager.beginTransaction(isolationLevel.orElse(TransactionManager.DEFAULT_ISOLATION), readOnly.orElse(TransactionManager.DEFAULT_READ_ONLY), false);
    stateMachine.setStartedTransactionId(transactionId);
    // Since the current session does not contain this new transaction ID, we need to manually mark it as inactive
    // when this statement completes.
    transactionManager.trySetInactive(transactionId);
    return immediateFuture(null);
}
Also used : IsolationLevel(io.prestosql.spi.transaction.IsolationLevel) PrestoException(io.prestosql.spi.PrestoException) Session(io.prestosql.Session) TransactionId(io.prestosql.transaction.TransactionId)

Example 2 with TransactionId

use of io.prestosql.transaction.TransactionId in project hetu-core by openlookeng.

the class AbstractPropertiesSystemTable method cursor.

@Override
public final RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession session, TupleDomain<Integer> constraint) {
    TransactionId transactionId = ((GlobalSystemTransactionHandle) transactionHandle).getTransactionId();
    InMemoryRecordSet.Builder table = InMemoryRecordSet.builder(tableMetadata);
    Map<CatalogName, Map<String, PropertyMetadata<?>>> connectorProperties = propertySupplier.get();
    for (Entry<String, CatalogName> entry : new TreeMap<>(transactionManager.getCatalogNames(transactionId)).entrySet()) {
        String catalog = entry.getKey();
        Map<String, PropertyMetadata<?>> properties = new TreeMap<>(connectorProperties.getOrDefault(entry.getValue(), ImmutableMap.of()));
        for (PropertyMetadata<?> propertyMetadata : properties.values()) {
            table.addRow(catalog, propertyMetadata.getName(), firstNonNull(propertyMetadata.getDefaultValue(), "").toString(), propertyMetadata.getSqlType().toString(), propertyMetadata.getDescription());
        }
    }
    return table.build().cursor();
}
Also used : TreeMap(java.util.TreeMap) InMemoryRecordSet(io.prestosql.spi.connector.InMemoryRecordSet) TransactionId(io.prestosql.transaction.TransactionId) PropertyMetadata(io.prestosql.spi.session.PropertyMetadata) CatalogName(io.prestosql.spi.connector.CatalogName) ImmutableMap(com.google.common.collect.ImmutableMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 3 with TransactionId

use of io.prestosql.transaction.TransactionId in project hetu-core by openlookeng.

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, 0, elapsed, 0, 0, 0, 0, 0, 0, 0, 0, queryStartTime, queryEndTime, 0, 0);
}
Also used : DateTime(org.joda.time.DateTime) TransactionId(io.prestosql.transaction.TransactionId)

Example 4 with TransactionId

use of io.prestosql.transaction.TransactionId in project hetu-core by openlookeng.

the class QueryMonitor method logQueryTimeline.

private static void logQueryTimeline(QueryInfo queryInfo) {
    try {
        QueryStats queryStats = queryInfo.getQueryStats();
        StageInfo outputStage = queryInfo.isRunningAsync() ? null : queryInfo.getOutputStage().orElse(null);
        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();
        long logicalPlanning = queryStats.getTotalLogicalPlanningTime().toMillis();
        long distributedPlanning = queryStats.getDistributedPlanningTime().toMillis();
        long physicalPlanning = queryStats.getAnalysisTime().toMillis() - logicalPlanning;
        long syntaxAnalysisTime = queryStats.getTotalSyntaxAnalysisTime().toMillis();
        // Time spent waiting for required no. of worker nodes to be present
        long waiting = queryStats.getResourceWaitingTime().toMillis();
        List<StageInfo> stages = StageInfo.getAllStages(queryInfo.getOutputStage());
        long firstTaskStartTime = queryEndTime.getMillis();
        long firstStageFirstTaskStartTime = queryEndTime.getMillis();
        long lastTaskStartTime = queryStartTime.getMillis() + planning;
        long lastTaskEndTime = queryStartTime.getMillis() + planning;
        for (StageInfo stage : stages) {
            for (TaskInfo taskInfo : stage.getTasks()) {
                TaskStats taskStats = taskInfo.getStats();
                DateTime firstStartTime = taskStats.getFirstStartTime();
                if (firstStartTime != null) {
                    firstStageFirstTaskStartTime = Math.min(firstStartTime.getMillis(), firstStageFirstTaskStartTime);
                }
                // only consider leaf stages for other stats.
                if (!stage.getSubStages().isEmpty()) {
                    continue;
                }
                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);
        // scheduling time is starting from end of plan time to  start of first task execution corresponding to any first stage.
        long scheduling = max(firstStageFirstTaskStartTime - queryStartTime.getMillis() - planning, 0);
        // executionInitializationTime is starting from first task of first stage to first task of leaf stage.
        long executionInitializationTime = max(firstTaskStartTime - firstStageFirstTaskStartTime, 0);
        long running = max(lastTaskEndTime - firstTaskStartTime, 0);
        long finishing = max(queryEndTime.getMillis() - lastTaskEndTime, 0);
        int spilledNodes = globalUniqueNodes(outputStage, true).size();
        long spilledWriteTimeMillisPerNode = spilledNodes > 0 ? (queryStats.getSpilledWriteTime().toMillis() / spilledNodes) : 0;
        long spilledReadTimeMillisPerNode = spilledNodes > 0 ? (queryStats.getSpilledReadTime().toMillis() / spilledNodes) : 0;
        logQueryTimeline(queryInfo.getQueryId(), queryInfo.getSession().getTransactionId().map(TransactionId::toString).orElse(""), elapsed, syntaxAnalysisTime, planning, logicalPlanning, physicalPlanning, distributedPlanning, waiting, scheduling, executionInitializationTime, running, finishing, queryStartTime, queryEndTime, spilledWriteTimeMillisPerNode, spilledReadTimeMillisPerNode);
    } catch (Exception e) {
        log.error(e, "Error logging query timeline");
    }
}
Also used : TaskInfo(io.prestosql.execution.TaskInfo) QueryStats(io.prestosql.execution.QueryStats) StageInfo(io.prestosql.execution.StageInfo) TaskStats(io.prestosql.operator.TaskStats) DateTime(org.joda.time.DateTime) TransactionId(io.prestosql.transaction.TransactionId)

Example 5 with TransactionId

use of io.prestosql.transaction.TransactionId in project hetu-core by openlookeng.

the class CommitTask method execute.

@Override
public ListenableFuture<?> execute(Commit statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
    Session session = stateMachine.getSession();
    if (!session.getTransactionId().isPresent()) {
        throw new PrestoException(NOT_IN_TRANSACTION, "No transaction in progress");
    }
    TransactionId transactionId = session.getTransactionId().get();
    stateMachine.clearTransactionId();
    return transactionManager.asyncCommit(transactionId);
}
Also used : PrestoException(io.prestosql.spi.PrestoException) Session(io.prestosql.Session) TransactionId(io.prestosql.transaction.TransactionId)

Aggregations

TransactionId (io.prestosql.transaction.TransactionId)12 Session (io.prestosql.Session)5 PrestoException (io.prestosql.spi.PrestoException)3 ConnectorMetadata (io.prestosql.spi.connector.ConnectorMetadata)3 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 InformationSchemaColumnHandle (io.prestosql.connector.informationschema.InformationSchemaColumnHandle)2 InformationSchemaMetadata (io.prestosql.connector.informationschema.InformationSchemaMetadata)2 InformationSchemaTableHandle (io.prestosql.connector.informationschema.InformationSchemaTableHandle)2 Catalog (io.prestosql.metadata.Catalog)2 CatalogManager (io.prestosql.metadata.CatalogManager)2 SessionPropertyManager (io.prestosql.metadata.SessionPropertyManager)2 AccessControlManager (io.prestosql.security.AccessControlManager)2 CatalogName (io.prestosql.spi.connector.CatalogName)2 ColumnMetadata (io.prestosql.spi.connector.ColumnMetadata)2 ConnectorSession (io.prestosql.spi.connector.ConnectorSession)2 ConnectorTableMetadata (io.prestosql.spi.connector.ConnectorTableMetadata)2 Constraint (io.prestosql.spi.connector.Constraint)2 PropertyMetadata (io.prestosql.spi.session.PropertyMetadata)2 IsolationLevel (io.prestosql.spi.transaction.IsolationLevel)2