Search in sources :

Example 1 with StartTransactionFailedException

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);
    }
}
Also used : TransactionFailedRetriableException(com.palantir.atlasdb.transaction.api.TransactionFailedRetriableException) TransactionService(com.palantir.atlasdb.transaction.service.TransactionService) Throwables(com.palantir.common.base.Throwables) TransactionConfig(com.palantir.atlasdb.transaction.TransactionConfig) MetricsManager(com.palantir.atlasdb.util.MetricsManager) Duration(java.time.Duration) Counter(com.codahale.metrics.Counter) ConditionAwareTransactionTask(com.palantir.atlasdb.transaction.api.ConditionAwareTransactionTask) TimestampService(com.palantir.timestamp.TimestampService) LockWatchManager(com.palantir.atlasdb.keyvalue.api.watch.LockWatchManager) ToplistDeltaFilteringTableLevelMetricsController(com.palantir.atlasdb.transaction.impl.metrics.ToplistDeltaFilteringTableLevelMetricsController) ImmutableSet(com.google.common.collect.ImmutableSet) TimestampManagementService(com.palantir.timestamp.TimestampManagementService) TransactionReadSentinelBehavior(com.palantir.atlasdb.transaction.api.TransactionReadSentinelBehavior) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException) Streams(com.google.common.collect.Streams) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) MemoizingTableLevelMetricsController(com.palantir.atlasdb.transaction.impl.metrics.MemoizingTableLevelMetricsController) List(java.util.List) MetricsFilterEvaluationContext(com.palantir.atlasdb.transaction.impl.metrics.MetricsFilterEvaluationContext) Transaction(com.palantir.atlasdb.transaction.api.Transaction) Timer(com.codahale.metrics.Timer) StartIdentifiedAtlasDbTransactionResponse(com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse) Optional(java.util.Optional) NoOpCleaner(com.palantir.atlasdb.cleaner.NoOpCleaner) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Iterables(com.google.common.collect.Iterables) SafeLoggerFactory(com.palantir.logsafe.logger.SafeLoggerFactory) Cleaner(com.palantir.atlasdb.cleaner.api.Cleaner) TransactionFailedRetriableException(com.palantir.atlasdb.transaction.api.TransactionFailedRetriableException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Callable(java.util.concurrent.Callable) SafeShutdownRunner(com.palantir.util.SafeShutdownRunner) Supplier(java.util.function.Supplier) SafeLogger(com.palantir.logsafe.logger.SafeLogger) ClusterAvailabilityStatus(com.palantir.atlasdb.keyvalue.api.ClusterAvailabilityStatus) AtlasDbConstraintCheckingMode(com.palantir.atlasdb.transaction.api.AtlasDbConstraintCheckingMode) OpenTransaction(com.palantir.atlasdb.transaction.api.OpenTransaction) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Suppliers(com.google.common.base.Suppliers) ExecutorService(java.util.concurrent.ExecutorService) NoOpLockWatchManager(com.palantir.atlasdb.keyvalue.api.watch.NoOpLockWatchManager) KeyValueServiceStatus(com.palantir.atlasdb.transaction.api.KeyValueServiceStatus) TableLevelMetricsController(com.palantir.atlasdb.transaction.impl.metrics.TableLevelMetricsController) PreCommitCondition(com.palantir.atlasdb.transaction.api.PreCommitCondition) LockToken(com.palantir.lock.v2.LockToken) TimestampTracker(com.palantir.atlasdb.monitoring.TimestampTracker) TimestampCache(com.palantir.atlasdb.cache.TimestampCache) LockWatchManagerInternal(com.palantir.atlasdb.keyvalue.api.watch.LockWatchManagerInternal) TimelockService(com.palantir.lock.v2.TimelockService) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) LockService(com.palantir.lock.LockService) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) TransactionTask(com.palantir.atlasdb.transaction.api.TransactionTask) MultiTableSweepQueueWriter(com.palantir.atlasdb.sweep.queue.MultiTableSweepQueueWriter) StartTransactionFailedException(com.palantir.lock.client.StartTransactionFailedException) ConflictTracer(com.palantir.atlasdb.debug.ConflictTracer) Preconditions(com.palantir.logsafe.Preconditions) TransactionType(com.palantir.atlasdb.transaction.api.Transaction.TransactionType) LockToken(com.palantir.lock.v2.LockToken) StartTransactionFailedException(com.palantir.lock.client.StartTransactionFailedException) StartIdentifiedAtlasDbTransactionResponse(com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse) Transaction(com.palantir.atlasdb.transaction.api.Transaction) OpenTransaction(com.palantir.atlasdb.transaction.api.OpenTransaction) Supplier(java.util.function.Supplier) OpenTransaction(com.palantir.atlasdb.transaction.api.OpenTransaction)

Aggregations

Counter (com.codahale.metrics.Counter)1 Timer (com.codahale.metrics.Timer)1 Suppliers (com.google.common.base.Suppliers)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 Streams (com.google.common.collect.Streams)1 TimestampCache (com.palantir.atlasdb.cache.TimestampCache)1 NoOpCleaner (com.palantir.atlasdb.cleaner.NoOpCleaner)1 Cleaner (com.palantir.atlasdb.cleaner.api.Cleaner)1 ConflictTracer (com.palantir.atlasdb.debug.ConflictTracer)1 ClusterAvailabilityStatus (com.palantir.atlasdb.keyvalue.api.ClusterAvailabilityStatus)1 KeyValueService (com.palantir.atlasdb.keyvalue.api.KeyValueService)1 LockWatchManager (com.palantir.atlasdb.keyvalue.api.watch.LockWatchManager)1 LockWatchManagerInternal (com.palantir.atlasdb.keyvalue.api.watch.LockWatchManagerInternal)1 NoOpLockWatchManager (com.palantir.atlasdb.keyvalue.api.watch.NoOpLockWatchManager)1 TimestampTracker (com.palantir.atlasdb.monitoring.TimestampTracker)1 MultiTableSweepQueueWriter (com.palantir.atlasdb.sweep.queue.MultiTableSweepQueueWriter)1 TransactionConfig (com.palantir.atlasdb.transaction.TransactionConfig)1