Java Code Examples for io.prestosql.spi.transaction.IsolationLevel

The following examples show how to use io.prestosql.spi.transaction.IsolationLevel. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: presto   Source File: TransactionInfo.java    License: Apache License 2.0 6 votes vote down vote up
public TransactionInfo(
        TransactionId transactionId,
        IsolationLevel isolationLevel,
        boolean readOnly,
        boolean autoCommitContext,
        DateTime createTime,
        Duration idleTime,
        List<CatalogName> catalogNames,
        Optional<CatalogName> writtenConnectorId)
{
    this.transactionId = requireNonNull(transactionId, "transactionId is null");
    this.isolationLevel = requireNonNull(isolationLevel, "isolationLevel is null");
    this.readOnly = readOnly;
    this.autoCommitContext = autoCommitContext;
    this.createTime = requireNonNull(createTime, "createTime is null");
    this.idleTime = requireNonNull(idleTime, "idleTime is null");
    this.catalogNames = ImmutableList.copyOf(requireNonNull(catalogNames, "connectorIds is null"));
    this.writtenConnectorId = requireNonNull(writtenConnectorId, "writtenConnectorId is null");
}
 
Example 2
Source Project: presto   Source File: TestingSession.java    License: Apache License 2.0 6 votes vote down vote up
private static Connector createTestSessionConnector()
{
    return new Connector()
    {
        @Override
        public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly)
        {
            return new ConnectorTransactionHandle() {};
        }

        @Override
        public ConnectorMetadata getMetadata(ConnectorTransactionHandle transaction)
        {
            return new SystemTablesMetadata(new StaticSystemTablesProvider(ImmutableSet.of()));
        }
    };
}
 
Example 3
Source Project: presto   Source File: TestStartTransactionTask.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testStartTransactionExplicitModes()
{
    Session session = sessionBuilder()
            .setClientTransactionSupport()
            .build();
    TransactionManager transactionManager = createTestTransactionManager();
    QueryStateMachine stateMachine = createQueryStateMachine("START TRANSACTION", session, transactionManager);
    assertFalse(stateMachine.getSession().getTransactionId().isPresent());

    getFutureValue(new 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());
}
 
Example 4
Source Project: presto   Source File: AccumuloConnector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly)
{
    checkConnectorSupports(READ_UNCOMMITTED, isolationLevel);
    ConnectorTransactionHandle transaction = new AccumuloTransactionHandle();
    transactions.put(transaction, metadataFactory.create());
    return transaction;
}
 
Example 5
Source Project: presto   Source File: JdbcConnector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly)
{
    checkConnectorSupports(READ_COMMITTED, isolationLevel);
    JdbcTransactionHandle transaction = new JdbcTransactionHandle();
    transactions.put(transaction, jdbcMetadataFactory.create());
    return transaction;
}
 
Example 6
Source Project: presto   Source File: TpcdsConnectorFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
    int splitsPerNode = getSplitsPerNode(config);
    NodeManager nodeManager = context.getNodeManager();
    return new Connector()
    {
        @Override
        public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly)
        {
            return TpcdsTransactionHandle.INSTANCE;
        }

        @Override
        public ConnectorMetadata getMetadata(ConnectorTransactionHandle transactionHandle)
        {
            return new TpcdsMetadata();
        }

        @Override
        public ConnectorSplitManager getSplitManager()
        {
            return new TpcdsSplitManager(nodeManager, splitsPerNode, isWithNoSexism(config));
        }

        @Override
        public ConnectorRecordSetProvider getRecordSetProvider()
        {
            return new TpcdsRecordSetProvider();
        }

        @Override
        public ConnectorNodePartitioningProvider getNodePartitioningProvider()
        {
            return new TpcdsNodePartitioningProvider(nodeManager, splitsPerNode);
        }
    };
}
 
Example 7
Source Project: presto   Source File: InMemoryTransactionManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public TransactionId beginTransaction(IsolationLevel isolationLevel, boolean readOnly, boolean autoCommitContext)
{
    TransactionId transactionId = TransactionId.create();
    BoundedExecutor executor = new BoundedExecutor(finishingExecutor, maxFinishingConcurrency);
    TransactionMetadata transactionMetadata = new TransactionMetadata(transactionId, isolationLevel, readOnly, autoCommitContext, catalogManager, executor);
    checkState(transactions.put(transactionId, transactionMetadata) == null, "Duplicate transaction ID: %s", transactionId);
    return transactionId;
}
 
Example 8
Source Project: presto   Source File: InMemoryTransactionManager.java    License: Apache License 2.0 5 votes vote down vote up
public TransactionMetadata(
        TransactionId transactionId,
        IsolationLevel isolationLevel,
        boolean readOnly,
        boolean autoCommitContext,
        CatalogManager catalogManager,
        Executor finishingExecutor)
{
    this.transactionId = requireNonNull(transactionId, "transactionId is null");
    this.isolationLevel = requireNonNull(isolationLevel, "isolationLevel is null");
    this.readOnly = readOnly;
    this.autoCommitContext = autoCommitContext;
    this.catalogManager = requireNonNull(catalogManager, "catalogManager is null");
    this.finishingExecutor = listeningDecorator(ExecutorServiceAdapter.from(requireNonNull(finishingExecutor, "finishingExecutor is null")));
}
 
Example 9
Source Project: presto   Source File: StartTransactionTask.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ListenableFuture<?> execute(StartTransaction statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters)
{
    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);
}
 
Example 10
Source Project: presto   Source File: StartTransactionTask.java    License: Apache License 2.0 5 votes vote down vote up
private static Optional<IsolationLevel> extractIsolationLevel(StartTransaction startTransaction)
{
    if (startTransaction.getTransactionModes().stream()
            .filter(Isolation.class::isInstance)
            .count() > 1) {
        throw semanticException(SYNTAX_ERROR, startTransaction, "Multiple transaction isolation levels specified");
    }

    return startTransaction.getTransactionModes().stream()
            .filter(Isolation.class::isInstance)
            .map(Isolation.class::cast)
            .map(Isolation::getLevel)
            .map(StartTransactionTask::convertLevel)
            .findFirst();
}
 
Example 11
Source Project: presto   Source File: StartTransactionTask.java    License: Apache License 2.0 5 votes vote down vote up
private static IsolationLevel convertLevel(Isolation.Level level)
{
    switch (level) {
        case SERIALIZABLE:
            return IsolationLevel.SERIALIZABLE;
        case REPEATABLE_READ:
            return IsolationLevel.REPEATABLE_READ;
        case READ_COMMITTED:
            return IsolationLevel.READ_COMMITTED;
        case READ_UNCOMMITTED:
            return IsolationLevel.READ_UNCOMMITTED;
        default:
            throw new AssertionError("Unhandled isolation level: " + level);
    }
}
 
Example 12
Source Project: presto   Source File: TestingTransactionManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public TransactionInfo getTransactionInfo(TransactionId transactionId)
{
    checkArgument(transactions.containsKey(transactionId), "Unknown transaction");
    return new TransactionInfo(
            transactionId,
            IsolationLevel.READ_UNCOMMITTED,
            false, //read only
            false, // auto commit
            DateTime.now(), // created
            Duration.succinctNanos(0), // idle
            ImmutableList.of(), // catalogs
            Optional.empty()); // write catalog
}
 
Example 13
Source Project: presto   Source File: TestAnalyzer.java    License: Apache License 2.0 5 votes vote down vote up
private static Connector createTestingConnector()
{
    return new Connector()
    {
        private final ConnectorMetadata metadata = new TestingMetadata();

        @Override
        public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly)
        {
            return new ConnectorTransactionHandle() {};
        }

        @Override
        public ConnectorMetadata getMetadata(ConnectorTransactionHandle transaction)
        {
            return metadata;
        }

        @Override
        public List<PropertyMetadata<?>> getAnalyzeProperties()
        {
            return ImmutableList.of(
                    stringProperty("p1", "test string property", "", false),
                    integerProperty("p2", "test integer property", 0, false));
        }
    };
}
 
Example 14
Source Project: presto   Source File: MongoConnector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly)
{
    checkConnectorSupports(READ_UNCOMMITTED, isolationLevel);
    MongoTransactionHandle transaction = new MongoTransactionHandle();
    transactions.put(transaction, new MongoMetadata(mongoSession));
    return transaction;
}
 
Example 15
Source Project: presto   Source File: RaptorConnector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly)
{
    checkConnectorSupports(READ_COMMITTED, isolationLevel);
    RaptorTransactionHandle transaction = new RaptorTransactionHandle();
    transactions.put(transaction, metadataFactory.create(tableId -> beginDelete(tableId, transaction.getUuid())));
    return transaction;
}
 
Example 16
Source Project: presto   Source File: IcebergConnector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly)
{
    checkConnectorSupports(READ_COMMITTED, isolationLevel);
    ConnectorTransactionHandle transaction = new HiveTransactionHandle();
    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(getClass().getClassLoader())) {
        transactionManager.put(transaction, metadataFactory.create());
    }
    return transaction;
}
 
Example 17
Source Project: presto   Source File: BigQueryConnector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly)
{
    log.debug("beginTransaction(isolationLevel=%s, readOnly=%s)", isolationLevel, readOnly);
    checkConnectorSupports(READ_COMMITTED, isolationLevel);
    return BigQueryTransactionHandle.INSTANCE;
}
 
Example 18
Source Project: presto   Source File: HiveConnector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly)
{
    checkConnectorSupports(READ_UNCOMMITTED, isolationLevel);
    ConnectorTransactionHandle transaction = new HiveTransactionHandle();
    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(classLoader)) {
        transactionManager.put(transaction, metadataFactory.create());
    }
    return transaction;
}
 
Example 19
Source Project: presto   Source File: KafkaConnector.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly)
{
    checkConnectorSupports(READ_COMMITTED, isolationLevel);
    return KafkaTransactionHandle.INSTANCE;
}
 
Example 20
Source Project: presto   Source File: PrometheusConnector.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly)
{
    return INSTANCE;
}
 
Example 21
Source Project: presto   Source File: ExampleConnector.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly)
{
    return INSTANCE;
}
 
Example 22
Source Project: presto   Source File: RedisConnector.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly)
{
    checkConnectorSupports(READ_COMMITTED, isolationLevel);
    return RedisTransactionHandle.INSTANCE;
}
 
Example 23
Source Project: presto   Source File: BlackHoleConnector.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly)
{
    return BlackHoleTransactionHandle.INSTANCE;
}
 
Example 24
Source Project: presto   Source File: TestCoordinatorDynamicFiltering.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly)
{
    return TestingTransactionHandle.create();
}
 
Example 25
Source Project: presto   Source File: TestBeginQuery.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly)
{
    return TestingTransactionHandle.create();
}
 
Example 26
Source Project: presto   Source File: JmxConnector.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly)
{
    checkConnectorSupports(READ_COMMITTED, isolationLevel);
    return JmxTransactionHandle.INSTANCE;
}
 
Example 27
Source Project: presto   Source File: IndexedTpchConnectorFactory.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> properties, ConnectorContext context)
{
    int splitsPerNode = getSplitsPerNode(properties);
    TpchIndexedData indexedData = new TpchIndexedData(indexSpec);
    NodeManager nodeManager = context.getNodeManager();

    return new Connector()
    {
        @Override
        public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly)
        {
            return TpchTransactionHandle.INSTANCE;
        }

        @Override
        public ConnectorMetadata getMetadata(ConnectorTransactionHandle transactionHandle)
        {
            return new TpchIndexMetadata(indexedData);
        }

        @Override
        public ConnectorSplitManager getSplitManager()
        {
            return new TpchSplitManager(nodeManager, splitsPerNode);
        }

        @Override
        public ConnectorRecordSetProvider getRecordSetProvider()
        {
            return new TpchRecordSetProvider();
        }

        @Override
        public ConnectorIndexProvider getIndexProvider()
        {
            return new TpchIndexProvider(indexedData);
        }

        @Override
        public Set<SystemTable> getSystemTables()
        {
            return ImmutableSet.of(new ExampleSystemTable());
        }

        @Override
        public ConnectorNodePartitioningProvider getNodePartitioningProvider()
        {
            return new TpchNodePartitioningProvider(nodeManager, splitsPerNode);
        }
    };
}
 
Example 28
Source Project: presto   Source File: PhoenixConnector.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly)
{
    return new JdbcTransactionHandle();
}
 
Example 29
Source Project: presto   Source File: TransactionBuilder.java    License: Apache License 2.0 4 votes vote down vote up
public TransactionBuilder withIsolationLevel(IsolationLevel isolationLevel)
{
    this.isolationLevel = requireNonNull(isolationLevel, "isolationLevel is null");
    return this;
}
 
Example 30
Source Project: presto   Source File: TransactionBuilder.java    License: Apache License 2.0 4 votes vote down vote up
public TransactionBuilder readUncommitted()
{
    return withIsolationLevel(IsolationLevel.READ_UNCOMMITTED);
}