Search in sources :

Example 26 with TransactionManager

use of io.trino.transaction.TransactionManager in project trino by trinodb.

the class TestIcebergMaterializedViews method getStorageTable.

private SchemaTableName getStorageTable(String catalogName, String schemaName, String objectName) {
    TransactionManager transactionManager = getQueryRunner().getTransactionManager();
    TransactionId transactionId = transactionManager.beginTransaction(false);
    Session session = getSession().beginTransactionId(transactionId, transactionManager, getQueryRunner().getAccessControl());
    Optional<MaterializedViewDefinition> materializedView = getQueryRunner().getMetadata().getMaterializedView(session, new QualifiedObjectName(catalogName, schemaName, objectName));
    assertThat(materializedView).isPresent();
    return materializedView.get().getStorageTable().get().getSchemaTableName();
}
Also used : MaterializedViewDefinition(io.trino.metadata.MaterializedViewDefinition) TransactionManager(io.trino.transaction.TransactionManager) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) TransactionId(io.trino.transaction.TransactionId) Session(io.trino.Session)

Example 27 with TransactionManager

use of io.trino.transaction.TransactionManager in project trino by trinodb.

the class TestRollbackTask method testUnknownTransactionRollback.

@Test
public void testUnknownTransactionRollback() {
    TransactionManager transactionManager = createTestTransactionManager();
    Session session = sessionBuilder().setTransactionId(// Use a random transaction ID that is unknown to the system
    TransactionId.create()).build();
    QueryStateMachine stateMachine = createQueryStateMachine("ROLLBACK", session, transactionManager);
    getFutureValue(new RollbackTask(transactionManager).execute(new Rollback(), stateMachine, emptyList(), WarningCollector.NOOP));
    // Still issue clear signal
    assertTrue(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId());
    assertFalse(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent());
    assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
}
Also used : TransactionManager(io.trino.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(io.trino.transaction.InMemoryTransactionManager.createTestTransactionManager) Rollback(io.trino.sql.tree.Rollback) Session(io.trino.Session) Test(org.testng.annotations.Test)

Example 28 with TransactionManager

use of io.trino.transaction.TransactionManager in project trino by trinodb.

the class TestRollbackTask method testRollback.

@Test
public void testRollback() {
    TransactionManager transactionManager = createTestTransactionManager();
    Session session = sessionBuilder().setTransactionId(transactionManager.beginTransaction(false)).build();
    QueryStateMachine stateMachine = createQueryStateMachine("ROLLBACK", session, transactionManager);
    assertTrue(stateMachine.getSession().getTransactionId().isPresent());
    assertEquals(transactionManager.getAllTransactionInfos().size(), 1);
    getFutureValue(new RollbackTask(transactionManager).execute(new Rollback(), stateMachine, emptyList(), WarningCollector.NOOP));
    assertTrue(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId());
    assertFalse(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent());
    assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
}
Also used : TransactionManager(io.trino.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(io.trino.transaction.InMemoryTransactionManager.createTestTransactionManager) Rollback(io.trino.sql.tree.Rollback) Session(io.trino.Session) Test(org.testng.annotations.Test)

Example 29 with TransactionManager

use of io.trino.transaction.TransactionManager in project trino by trinodb.

the class TestStartTransactionTask method testStartTransaction.

@Test
public void testStartTransaction() {
    Session session = sessionBuilder().setClientTransactionSupport().build();
    TransactionManager transactionManager = createTestTransactionManager();
    QueryStateMachine stateMachine = createQueryStateMachine("START TRANSACTION", session, transactionManager);
    assertFalse(stateMachine.getSession().getTransactionId().isPresent());
    getFutureValue(new StartTransactionTask(transactionManager).execute(new StartTransaction(ImmutableList.of()), stateMachine, emptyList(), WarningCollector.NOOP));
    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 : TransactionManager(io.trino.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(io.trino.transaction.InMemoryTransactionManager.createTestTransactionManager) InMemoryTransactionManager(io.trino.transaction.InMemoryTransactionManager) TransactionInfo(io.trino.transaction.TransactionInfo) StartTransaction(io.trino.sql.tree.StartTransaction) Session(io.trino.Session) Test(org.testng.annotations.Test)

Example 30 with TransactionManager

use of io.trino.transaction.TransactionManager in project trino by trinodb.

the class TestStartTransactionTask method testStartTransactionIdleExpiration.

@Test
public void testStartTransactionIdleExpiration() throws Exception {
    Session session = sessionBuilder().setClientTransactionSupport().build();
    TransactionManager transactionManager = InMemoryTransactionManager.create(new TransactionManagerConfig().setIdleTimeout(// Fast idle timeout
    new Duration(1, TimeUnit.MICROSECONDS)).setIdleCheckInterval(new Duration(10, TimeUnit.MILLISECONDS)), scheduledExecutor, new CatalogManager(), executor);
    QueryStateMachine stateMachine = createQueryStateMachine("START TRANSACTION", session, transactionManager);
    assertFalse(stateMachine.getSession().getTransactionId().isPresent());
    getFutureValue(new StartTransactionTask(transactionManager).execute(new StartTransaction(ImmutableList.of()), stateMachine, emptyList(), WarningCollector.NOOP));
    assertFalse(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId());
    assertTrue(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent());
    long start = System.nanoTime();
    while (!transactionManager.getAllTransactionInfos().isEmpty()) {
        if (Duration.nanosSince(start).toMillis() > 10_000) {
            fail("Transaction did not expire in the allotted time");
        }
        TimeUnit.MILLISECONDS.sleep(10);
    }
}
Also used : TransactionManagerConfig(io.trino.transaction.TransactionManagerConfig) TransactionManager(io.trino.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(io.trino.transaction.InMemoryTransactionManager.createTestTransactionManager) InMemoryTransactionManager(io.trino.transaction.InMemoryTransactionManager) Duration(io.airlift.units.Duration) CatalogManager(io.trino.metadata.CatalogManager) StartTransaction(io.trino.sql.tree.StartTransaction) Session(io.trino.Session) Test(org.testng.annotations.Test)

Aggregations

TransactionManager (io.trino.transaction.TransactionManager)48 InMemoryTransactionManager.createTestTransactionManager (io.trino.transaction.InMemoryTransactionManager.createTestTransactionManager)42 Test (org.testng.annotations.Test)40 AccessDeniedException (io.trino.spi.security.AccessDeniedException)17 Session (io.trino.Session)16 QualifiedObjectName (io.trino.metadata.QualifiedObjectName)16 Optional (java.util.Optional)13 ImmutableSet (com.google.common.collect.ImmutableSet)12 SchemaTableName (io.trino.spi.connector.SchemaTableName)12 Map (java.util.Map)12 ImmutableMap (com.google.common.collect.ImmutableMap)11 DefaultSystemAccessControl (io.trino.plugin.base.security.DefaultSystemAccessControl)11 Identity (io.trino.spi.security.Identity)11 Set (java.util.Set)11 Assert.assertEquals (org.testng.Assert.assertEquals)11 QueryId (io.trino.spi.QueryId)10 CatalogSchemaName (io.trino.spi.connector.CatalogSchemaName)10 TestingEventListenerManager.emptyEventListenerManager (io.trino.testing.TestingEventListenerManager.emptyEventListenerManager)10 TransactionBuilder.transaction (io.trino.transaction.TransactionBuilder.transaction)10 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)10