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); } }
@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); } }
@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; }