@Override public <T, E extends Exception> T finishRunTaskWithLockThrowOnConflict(TransactionAndImmutableTsLock txAndLock, TransactionTask<T, E> task) throws E, TransactionFailedRetriableException { Timer postTaskTimer = getTimer("finishTask"); Timer.Context postTaskContext; TransactionTask<T, E> wrappedTask = wrapTaskIfNecessary(task, txAndLock.immutableTsLock()); SnapshotTransaction tx = (SnapshotTransaction) txAndLock.transaction(); T result; try { result = runTaskThrowOnConflict(wrappedTask, tx); } finally { postTaskContext = postTaskTimer.time(); timelockService.tryUnlock(ImmutableSet.of(txAndLock.immutableTsLock())); } scrubForAggressiveHardDelete(tx); postTaskContext.stop(); return result; }
private <T> T runWithRetry(TransactionToken token, RuntimeTransactionTask<T> task) { if (token.shouldAutoCommit()) { return txManager.runTaskWithRetry(task); } else { Transaction tx = transactions.getIfPresent(token).transaction(); Preconditions.checkNotNull(tx, "The given transaction does not exist."); return task.execute(tx); } }
@Override public TransactionAndImmutableTsLock setupRunTaskWithConditionThrowOnConflict(PreCommitCondition condition) { StartIdentifiedAtlasDbTransactionResponse transactionResponse = timelockService.startIdentifiedAtlasDbTransaction( StartIdentifiedAtlasDbTransactionRequest.createForRequestor(clientId)); try { LockToken immutableTsLock = transactionResponse.immutableTimestamp().getLock(); long immutableTs = transactionResponse.immutableTimestamp().getImmutableTimestamp(); recordImmutableTimestamp(immutableTs); cleaner.punch(transactionResponse.startTimestampAndPartition().timestamp()); Supplier<Long> startTimestampSupplier = Suppliers.ofInstance( transactionResponse.startTimestampAndPartition().timestamp()); SnapshotTransaction transaction = createTransaction(immutableTs, startTimestampSupplier, immutableTsLock, condition); return TransactionAndImmutableTsLock.of(transaction, immutableTsLock); } catch (Throwable e) { timelockService.tryUnlock(ImmutableSet.of(transactionResponse.immutableTimestamp().getLock())); throw Throwables.rewrapAndThrowUncheckedException(e); } }
private <T> T runReadOnly(TransactionToken token, RuntimeTransactionTask<T> task) { if (token.shouldAutoCommit()) { return txManager.runTaskWithRetry(task); } else { Transaction tx = transactions.getIfPresent(token).transaction(); Preconditions.checkNotNull(tx, "The given transaction does not exist."); return task.execute(tx); } }
@Override public TransactionAndImmutableTsLock setupRunTaskWithConditionThrowOnConflict(PreCommitCondition condition) { StartIdentifiedAtlasDbTransactionResponse transactionResponse = timelockService.startIdentifiedAtlasDbTransaction( StartIdentifiedAtlasDbTransactionRequest.createForRequestor(clientId)); try { LockToken immutableTsLock = transactionResponse.immutableTimestamp().getLock(); long immutableTs = transactionResponse.immutableTimestamp().getImmutableTimestamp(); recordImmutableTimestamp(immutableTs); cleaner.punch(transactionResponse.startTimestampAndPartition().timestamp()); Supplier<Long> startTimestampSupplier = Suppliers.ofInstance( transactionResponse.startTimestampAndPartition().timestamp()); SnapshotTransaction transaction = createTransaction(immutableTs, startTimestampSupplier, immutableTsLock, condition); return TransactionAndImmutableTsLock.of(transaction, immutableTsLock); } catch (Throwable e) { timelockService.tryUnlock(ImmutableSet.of(transactionResponse.immutableTimestamp().getLock())); throw Throwables.rewrapAndThrowUncheckedException(e); } }
@Override public <T, E extends Exception> T finishRunTaskWithLockThrowOnConflict(TransactionAndImmutableTsLock txAndLock, TransactionTask<T, E> task) throws E, TransactionFailedRetriableException { Timer postTaskTimer = getTimer("finishTask"); Timer.Context postTaskContext; TransactionTask<T, E> wrappedTask = wrapTaskIfNecessary(task, txAndLock.immutableTsLock()); SnapshotTransaction tx = (SnapshotTransaction) txAndLock.transaction(); T result; try { result = runTaskThrowOnConflict(wrappedTask, tx); } finally { postTaskContext = postTaskTimer.time(); timelockService.tryUnlock(ImmutableSet.of(txAndLock.immutableTsLock())); } scrubForAggressiveHardDelete(tx); postTaskContext.stop(); return result; }
private <T> T runWithRetry(TransactionToken token, RuntimeTransactionTask<T> task) { if (token.shouldAutoCommit()) { return txManager.runTaskWithRetry(task); } else { Transaction tx = transactions.getIfPresent(token).transaction(); Preconditions.checkNotNull(tx, "The given transaction does not exist."); return task.execute(tx); } }
private <T> T runReadOnly(TransactionToken token, RuntimeTransactionTask<T> task) { if (token.shouldAutoCommit()) { return txManager.runTaskWithRetry(task); } else { Transaction tx = transactions.getIfPresent(token).transaction(); Preconditions.checkNotNull(tx, "The given transaction does not exist."); return task.execute(tx); } }