Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
maybe better?
Browse files Browse the repository at this point in the history
  • Loading branch information
fsamuel-bs committed Nov 1, 2024
1 parent 85f78cb commit f306d38
Showing 1 changed file with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,26 +200,12 @@ public <T, C extends PreCommitCondition, E extends Exception> T runTaskWithCondi
throw e;
}
try {
TransactionTask<T, E> wrappedTask = wrapTaskIfNecessary(
transaction -> task.execute(transaction, condition), openTransaction.getImmutableTsLock());
return runTimed(() -> runTaskThrowOnConflict(wrappedTask, openTransaction), "runTaskThrowOnConflict");
return openTransaction.execute(txn -> task.execute(txn, condition));
} finally {
openTransaction.close();
}
}

private <T, E extends Exception> TransactionTask<T, E> wrapTaskIfNecessary(
TransactionTask<T, E> task, LockToken immutableTsLock) {
if (taskWrappingIsNecessary()) {
return new LockCheckingTransactionTask<>(task, timelockService, immutableTsLock);
}
return task;
}

private boolean taskWrappingIsNecessary() {
return !validateLocksOnReads;
}

@Override
public List<OpenTransactionImpl> startTransactions(List<? extends PreCommitCondition> conditions) {
if (conditions.isEmpty()) {
Expand Down Expand Up @@ -278,8 +264,9 @@ private OpenTransactionImpl(ExpectationsAwareTransaction delegate, LockToken imm
this.immutableTsLock = immutableTsLock;
}

LockToken getImmutableTsLock() {
return immutableTsLock;
<T, E extends Exception> T execute(TransactionTask<T, E> task) {
TransactionTask<T, E> wrappedTask = wrapTaskIfNecessary(task, immutableTsLock);
return runTimed(() -> runTaskThrowOnConflict(wrappedTask, delegate), "runTaskThrowOnConflict");
}

@Override
Expand Down Expand Up @@ -311,6 +298,18 @@ public synchronized void close() {
}
}

private <T, E extends Exception> TransactionTask<T, E> wrapTaskIfNecessary(
TransactionTask<T, E> task, LockToken immutableTsLock) {
if (taskWrappingIsNecessary()) {
return new LockCheckingTransactionTask<>(task, timelockService, immutableTsLock);
}
return task;
}

private boolean taskWrappingIsNecessary() {
return !validateLocksOnReads;
}

private void scrubForAggressiveHardDelete(SnapshotTransaction tx) {
if ((tx.getTransactionType() == TransactionType.AGGRESSIVE_HARD_DELETE) && !tx.isAborted()) {
// t.getCellsToScrubImmediately() checks that t has been committed
Expand Down

0 comments on commit f306d38

Please sign in to comment.