private static void registerBogusConnector(TransactionManager transactionManager, String connectorId) { transactionManager.addConnector(connectorId, new Connector() { @Override public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly) { // Just return something return new ConnectorTransactionHandle() {}; } @Override public ConnectorMetadata getMetadata(ConnectorTransactionHandle transactionHandle) { throw new UnsupportedOperationException(); } @Override public ConnectorSplitManager getSplitManager() { throw new UnsupportedOperationException(); } }); }
@Test public void testStartTransactionExplicitModes() throws Exception { Session session = sessionBuilder() .setClientTransactionSupport() .build(); TransactionManager transactionManager = createTestTransactionManager(); QueryStateMachine stateMachine = QueryStateMachine.begin(new QueryId("query"), "START TRANSACTION", session, URI.create("fake://uri"), true, transactionManager, executor); Assert.assertFalse(stateMachine.getSession().getTransactionId().isPresent()); new StartTransactionTask().execute(new StartTransaction(ImmutableList.of(new Isolation(Isolation.Level.SERIALIZABLE), new TransactionAccessMode(true))), transactionManager, metadata, new AllowAllAccessControl(), stateMachine).join(); Assert.assertFalse(stateMachine.getQueryInfoWithoutDetails().isClearTransactionId()); Assert.assertTrue(stateMachine.getQueryInfoWithoutDetails().getStartedTransactionId().isPresent()); Assert.assertEquals(transactionManager.getAllTransactionInfos().size(), 1); TransactionInfo transactionInfo = transactionManager.getTransactionInfo(stateMachine.getQueryInfoWithoutDetails().getStartedTransactionId().get()); Assert.assertEquals(transactionInfo.getIsolationLevel(), IsolationLevel.SERIALIZABLE); Assert.assertTrue(transactionInfo.isReadOnly()); Assert.assertFalse(transactionInfo.isAutoCommitContext()); }
@Inject public ExpressionCompiler() { TransactionManager transactionManager = TransactionManager.createTestTransactionManager(); Metadata metadata = MetadataManager.createTestMetadataManager(); this.serde = metadata.getBlockEncodingSerde(); this.metadata = metadata; this.featuresConfig = new FeaturesConfig(); this.typeManager = metadata.getTypeManager(); this.session = Session.builder(new SessionPropertyManager()) .setIdentity(new Identity("user", Optional.empty())) .setTimeZoneKey(TimeZoneKey.UTC_KEY) .setLocale(Locale.ENGLISH) .setQueryId(QueryId.valueOf("row_expression_compiler")) .setTransactionId(transactionManager.beginTransaction(IsolationLevel.REPEATABLE_READ, true, true)) .build(); this.expressionOptimizer = new ExpressionOptimizer(metadata.getFunctionRegistry(), metadata.getTypeManager(), session); }
@Override public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly) { checkConnectorSupports(READ_UNCOMMITTED, isolationLevel); HDFSTransactionHandle transaction = new HDFSTransactionHandle(); transactions.putIfAbsent(transaction, hdfsMetadataFactory.create()); return transaction; }
@Override public Connector create(String connectorId, Map<String, String> properties) { return new Connector() { @Override public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly) { checkConnectorSupports(READ_COMMITTED, isolationLevel); return JmxTransactionHandle.INSTANCE; } @Override public ConnectorMetadata getMetadata(ConnectorTransactionHandle transactionHandle) { return new JmxMetadata(connectorId, mbeanServer); } @Override public ConnectorSplitManager getSplitManager() { return new JmxSplitManager(connectorId, nodeManager); } @Override public ConnectorRecordSetProvider getRecordSetProvider() { return new JmxRecordSetProvider(mbeanServer, nodeManager.getCurrentNode().getNodeIdentifier()); } }; }
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, executor); checkState(transactions.put(transactionId, transactionMetadata) == null, "Duplicate transaction ID: %s", transactionId); return transactionId; }
public TransactionMetadata(TransactionId transactionId, IsolationLevel isolationLevel, boolean readOnly, boolean autoCommitContext, Executor finishingExecutor) { this.transactionId = requireNonNull(transactionId, "transactionId is null"); this.isolationLevel = requireNonNull(isolationLevel, "isolationLevel is null"); this.readOnly = readOnly; this.autoCommitContext = autoCommitContext; this.finishingExecutor = requireNonNull(finishingExecutor, "finishingExecutor is null"); }
public TransactionInfo(TransactionId transactionId, IsolationLevel isolationLevel, boolean readOnly, boolean autoCommitContext, DateTime createTime, Duration idleTime, List<String> connectorIds, Optional<String> 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.connectorIds = ImmutableList.copyOf(requireNonNull(connectorIds, "connectorIds is null")); this.writtenConnectorId = requireNonNull(writtenConnectorId, "writtenConnectorId is null"); }
@Override public CompletableFuture<?> execute(StartTransaction statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine) { 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 completedFuture(null); }
private Optional<IsolationLevel> extractIsolationLevel(StartTransaction startTransaction) { if (startTransaction.getTransactionModes().stream() .filter(Isolation.class::isInstance) .count() > 1) { throw new SemanticException(INVALID_TRANSACTION_MODE, 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(); }
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); } }
@Override public Connector create(String connectorId, Map<String, String> properties) { int splitsPerNode = getSplitsPerNode(properties); return new Connector() { @Override public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly) { return TpchTransactionHandle.INSTANCE; } @Override public ConnectorMetadata getMetadata(ConnectorTransactionHandle transaction) { return new TpchMetadata(connectorId); } @Override public ConnectorSplitManager getSplitManager() { return new TpchSplitManager(connectorId, nodeManager, splitsPerNode); } @Override public ConnectorRecordSetProvider getRecordSetProvider() { return new TpchRecordSetProvider(); } }; }
@Override public Connector create(String connectorId, Map<String, String> properties) { requireNonNull(properties, "properties is null"); int splitsPerNode = getSplitsPerNode(properties); return new Connector() { @Override public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly) { return TpchTransactionHandle.INSTANCE; } @Override public ConnectorMetadata getMetadata(ConnectorTransactionHandle transaction) { return new SampledTpchMetadata(connectorId); } @Override public ConnectorSplitManager getSplitManager() { return new TpchSplitManager(connectorId, nodeManager, splitsPerNode); } @Override public ConnectorRecordSetProvider getRecordSetProvider() { return new SampledTpchRecordSetProvider(connectorId, sampleWeight); } }; }
@Override public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly) { return new RestTransactionHandle(0); }
@Override public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly) { checkConnectorSupports(READ_COMMITTED, isolationLevel); return EthereumTransactionHandle.INSTANCE; }
@Override public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean b) { log.info("INFORMATION: AmpoolConnector beginTransaction() called."); return INSTANCE; }
@Override public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly) { checkConnectorSupports(READ_COMMITTED, isolationLevel); return KuduTransactionHandle.INSTANCE; }
@Override public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly) { checkConnectorSupports(READ_COMMITTED, isolationLevel); return KafkaTransactionHandle.INSTANCE; }
@Override public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly) { checkConnectorSupports(READ_COMMITTED, isolationLevel); return new RaptorTransactionHandle(); }
@Override public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly) { return BlackHoleTransactionHandle.INSTANCE; }
@Override public Connector create(String connectorId, Map<String, String> properties) { int splitsPerNode = getSplitsPerNode(properties); TpchIndexedData indexedData = new TpchIndexedData(connectorId, indexSpec); return new Connector() { @Override public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly) { return TpchTransactionHandle.INSTANCE; } @Override public ConnectorMetadata getMetadata(ConnectorTransactionHandle transactionHandle) { return new TpchIndexMetadata(connectorId, indexedData); } @Override public ConnectorSplitManager getSplitManager() { return new TpchSplitManager(connectorId, 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 ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly) { checkConnectorSupports(connector.getIsolationLevel(), isolationLevel); return LegacyTransactionHandle.create(connectorId); }
public TransactionBuilder withIsolationLevel(IsolationLevel isolationLevel) { this.isolationLevel = requireNonNull(isolationLevel, "isolationLevel is null"); return this; }
public TransactionBuilder readUncommitted() { return withIsolationLevel(IsolationLevel.READ_UNCOMMITTED); }
public TransactionBuilder readCommitted() { return withIsolationLevel(IsolationLevel.READ_COMMITTED); }
public TransactionBuilder repeatableRead() { return withIsolationLevel(IsolationLevel.REPEATABLE_READ); }
public TransactionBuilder serializable() { return withIsolationLevel(IsolationLevel.SERIALIZABLE); }
public IsolationLevel getIsolationLevel() { return isolationLevel; }
default ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly) { throw new UnsupportedOperationException(); }
@Override public ConnectorTransactionHandle beginTransaction(TransactionId transactionId, IsolationLevel isolationLevel, boolean readOnly) { return new InformationSchemaTransactionHandle(transactionId); }
@Override public ConnectorTransactionHandle beginTransaction(TransactionId transactionId, IsolationLevel isolationLevel, boolean readOnly) { return new SystemTransactionHandle(connectorId, transactionHandleFunction.apply(transactionId)); }
@Override public ConnectorTransactionHandle beginTransaction(TransactionId transactionId, IsolationLevel isolationLevel, boolean readOnly) { return new GlobalSystemTransactionHandle(connectorId, transactionId); }
/** * Get the transaction read isolation level supported by this connector. */ default IsolationLevel getIsolationLevel() { return IsolationLevel.READ_UNCOMMITTED; }
@Override public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly) { checkConnectorSupports(READ_UNCOMMITTED, isolationLevel); return CassandraTransactionHandle.INSTANCE; }
@Override public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly) { return SpreadsheetTransactionHandle.INSTANCE; }
@Override public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean b) { checkConnectorSupports(READ_COMMITTED, isolationLevel); return KinesisTransactionHandle.INSTANCE; }
ConnectorTransactionHandle beginTransaction(TransactionId transactionId, IsolationLevel isolationLevel, boolean readOnly);
ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly);