use of com.palantir.atlasdb.transaction.api.OpenTransaction in project atlasdb by palantir.
the class AtlasDbServiceImpl method startTransaction.
@Override
public TransactionToken startTransaction() {
String id = UUID.randomUUID().toString();
TransactionToken token = new TransactionToken(id);
OpenTransaction openTxn = Iterables.getOnlyElement(txManager.startTransactions(ImmutableList.of(PreCommitConditions.NO_OP)));
transactions.put(token, openTxn);
return token;
}
use of com.palantir.atlasdb.transaction.api.OpenTransaction in project atlasdb by palantir.
the class SnapshotTransactionManagerTest method startEmptyBatchOfTransactionsDoesNotCallTimelockService.
@Test
public void startEmptyBatchOfTransactionsDoesNotCallTimelockService() {
TimelockService timelockService = spy(services.getLegacyTimelockService());
SnapshotTransactionManager transactionManager = createSnapshotTransactionManager(timelockService, false);
List<OpenTransaction> transactions = transactionManager.startTransactions(ImmutableList.of());
assertThat(transactions).isEmpty();
verify(timelockService, never()).startIdentifiedAtlasDbTransactionBatch(anyInt());
}
use of com.palantir.atlasdb.transaction.api.OpenTransaction in project atlasdb by palantir.
the class SnapshotTransactionManager method startTransactions.
@Override
public List<OpenTransaction> startTransactions(List<? extends PreCommitCondition> conditions) {
if (conditions.isEmpty()) {
return ImmutableList.of();
}
final List<StartIdentifiedAtlasDbTransactionResponse> responses;
try {
responses = timelockService.startIdentifiedAtlasDbTransactionBatch(conditions.size());
} catch (StartTransactionFailedException e) {
throw new TransactionFailedRetriableException("Failed to start a batch of transactions", e);
}
Preconditions.checkState(conditions.size() == responses.size(), "Different number of responses and conditions");
try {
long immutableTs = responses.stream().mapToLong(response -> response.immutableTimestamp().getImmutableTimestamp()).max().getAsLong();
recordImmutableTimestamp(immutableTs);
cleaner.punch(responses.get(0).startTimestampAndPartition().timestamp());
List<OpenTransaction> transactions = Streams.zip(responses.stream(), conditions.stream(), (response, condition) -> {
LockToken immutableTsLock = response.immutableTimestamp().getLock();
Supplier<Long> startTimestampSupplier = Suppliers.ofInstance(response.startTimestampAndPartition().timestamp());
Transaction transaction = createTransaction(immutableTs, startTimestampSupplier, immutableTsLock, condition);
transaction.onSuccess(() -> lockWatchManager.onTransactionCommit(transaction.getTimestamp()));
return new OpenTransactionImpl(transaction, immutableTsLock);
}).collect(Collectors.toList());
openTransactionCounter.inc(transactions.size());
return transactions;
} catch (Throwable t) {
responses.forEach(response -> lockWatchManager.removeTransactionStateFromCache(response.startTimestampAndPartition().timestamp()));
timelockService.tryUnlock(responses.stream().map(response -> response.immutableTimestamp().getLock()).collect(Collectors.toSet()));
throw Throwables.rewrapAndThrowUncheckedException(t);
}
}
use of com.palantir.atlasdb.transaction.api.OpenTransaction in project atlasdb by palantir.
the class AtlasDbServiceImpl method commit.
@Override
public void commit(TransactionToken token) {
OpenTransaction openTxn = transactions.getIfPresent(token);
if (openTxn != null) {
openTxn.finish((TxTask) transaction -> null);
transactions.invalidate(token);
}
}
use of com.palantir.atlasdb.transaction.api.OpenTransaction in project atlasdb by palantir.
the class AtlasDbServiceImpl method abort.
@Override
public void abort(TransactionToken token) {
OpenTransaction openTxn = transactions.getIfPresent(token);
if (openTxn != null) {
openTxn.finish((TxTask) transaction -> {
transaction.abort();
return null;
});
transactions.invalidate(token);
}
}
Aggregations