Search in sources :

Example 1 with TransactionInfo

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

the class TestBrutalShutdown method testTransactionalQueryRetryOnShutdown.

@Test(timeOut = SHUTDOWN_TIMEOUT_MILLIS)
public void testTransactionalQueryRetryOnShutdown() throws Exception {
    try (DistributedQueryRunner queryRunner = createQueryRunner(ImmutableMap.of())) {
        executor.submit(() -> queryRunner.execute(TINY_SESSION, "START TRANSACTION")).get();
        TransactionInfo transactionInfo = queryRunner.getCoordinator().getTransactionManager().getAllTransactionInfos().get(0);
        Session session = testSessionBuilder().setCatalog("tpch").setSchema("tiny").setTransactionId(transactionInfo.getTransactionId()).build();
        // only send 1 query as the first failed query will abort the transaction
        queryRetryOnShutdown(session, queryRunner, executor, 1);
        List<BasicQueryInfo> queryInfos = queryRunner.getCoordinator().getQueryManager().getQueries();
        for (BasicQueryInfo info : queryInfos) {
            if (info.getQuery().contains("-- retry query")) {
                fail("no retry query is allowed within a transaction");
            }
        }
    }
}
Also used : BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) TransactionInfo(com.facebook.presto.transaction.TransactionInfo) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 2 with TransactionInfo

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

the class TestStartTransactionTask method testStartTransaction.

@Test
public void testStartTransaction() {
    Session session = sessionBuilder().setClientTransactionSupport().build();
    TransactionManager transactionManager = createTestTransactionManager();
    QueryStateMachine stateMachine = createQueryStateMachine("START TRANSACTION", session, true, transactionManager, executor, metadata);
    assertFalse(stateMachine.getSession().getTransactionId().isPresent());
    StartTransactionTask startTransactionTask = new StartTransactionTask();
    getFutureValue(startTransactionTask.execute(new StartTransaction(ImmutableList.of()), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList()));
    assertFalse(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId());
    assertTrue(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent());
    assertEquals(transactionManager.getAllTransactionInfos().size(), 1);
    TransactionInfo transactionInfo = transactionManager.getTransactionInfo(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().get());
    assertFalse(transactionInfo.isAutoCommitContext());
}
Also used : TaskTestUtils.createQueryStateMachine(com.facebook.presto.execution.TaskTestUtils.createQueryStateMachine) TransactionManager(com.facebook.presto.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager.createTestTransactionManager) InMemoryTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) TransactionInfo(com.facebook.presto.transaction.TransactionInfo) StartTransaction(com.facebook.presto.sql.tree.StartTransaction) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 3 with TransactionInfo

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

the class TestStartTransactionTask method testStartTransactionExplicitModes.

@Test
public void testStartTransactionExplicitModes() {
    Session session = sessionBuilder().setClientTransactionSupport().build();
    TransactionManager transactionManager = createTestTransactionManager();
    QueryStateMachine stateMachine = createQueryStateMachine("START TRANSACTION", session, true, transactionManager, executor, metadata);
    assertFalse(stateMachine.getSession().getTransactionId().isPresent());
    StartTransactionTask startTransactionTask = new StartTransactionTask();
    getFutureValue(startTransactionTask.execute(new StartTransaction(ImmutableList.of(new Isolation(Isolation.Level.SERIALIZABLE), new TransactionAccessMode(true))), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList()));
    assertFalse(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId());
    assertTrue(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent());
    assertEquals(transactionManager.getAllTransactionInfos().size(), 1);
    TransactionInfo transactionInfo = transactionManager.getTransactionInfo(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().get());
    assertEquals(transactionInfo.getIsolationLevel(), IsolationLevel.SERIALIZABLE);
    assertTrue(transactionInfo.isReadOnly());
    assertFalse(transactionInfo.isAutoCommitContext());
}
Also used : TaskTestUtils.createQueryStateMachine(com.facebook.presto.execution.TaskTestUtils.createQueryStateMachine) TransactionManager(com.facebook.presto.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager.createTestTransactionManager) InMemoryTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager) TransactionAccessMode(com.facebook.presto.sql.tree.TransactionAccessMode) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) Isolation(com.facebook.presto.sql.tree.Isolation) TransactionInfo(com.facebook.presto.transaction.TransactionInfo) StartTransaction(com.facebook.presto.sql.tree.StartTransaction) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Aggregations

Session (com.facebook.presto.Session)3 TransactionInfo (com.facebook.presto.transaction.TransactionInfo)3 Test (org.testng.annotations.Test)3 TaskTestUtils.createQueryStateMachine (com.facebook.presto.execution.TaskTestUtils.createQueryStateMachine)2 AllowAllAccessControl (com.facebook.presto.security.AllowAllAccessControl)2 StartTransaction (com.facebook.presto.sql.tree.StartTransaction)2 InMemoryTransactionManager (com.facebook.presto.transaction.InMemoryTransactionManager)2 InMemoryTransactionManager.createTestTransactionManager (com.facebook.presto.transaction.InMemoryTransactionManager.createTestTransactionManager)2 TransactionManager (com.facebook.presto.transaction.TransactionManager)2 BasicQueryInfo (com.facebook.presto.server.BasicQueryInfo)1 Isolation (com.facebook.presto.sql.tree.Isolation)1 TransactionAccessMode (com.facebook.presto.sql.tree.TransactionAccessMode)1