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;
}
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);
}
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);
}
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");
}
}
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")));
}
Aggregations