use of com.palantir.lock.client.StartTransactionFailedException 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);
}
}
Aggregations