checkForPendingLocks = txTable.getMinTopologyId() < transactionTopologyId;
}
}
}
Log log = getLog();
boolean trace = log.isTraceEnabled();
if (checkForPendingLocks) {
if (trace)
log.tracef("Checking for pending locks and then locking key %s", toStr(key));
final long expectedEndTime = timeService.expectedEndTime(cacheConfiguration.locking().lockAcquisitionTimeout(),
TimeUnit.MILLISECONDS);
// Check local transactions first
waitForTransactionsToComplete(txContext, txTable.getLocalTransactions(), key, transactionTopologyId, expectedEndTime);
// ... then remote ones
waitForTransactionsToComplete(txContext, txTable.getRemoteTransactions(), key, transactionTopologyId, expectedEndTime);
// Then try to acquire a lock
final long remaining = timeService.remainingTime(expectedEndTime, TimeUnit.MILLISECONDS);
if (remaining <= 0) {
throw newTimeoutException(key, txContext);
} else {
if (trace)
log.tracef("Finished waiting for other potential lockers, trying to acquire the lock on %s", toStr(key));
lockManager.acquireLock(ctx, key, remaining, skipLocking);
}
} else {
if (trace)
log.tracef("Locking key %s, no need to check for pending locks.", toStr(key));
lockManager.acquireLock(ctx, key, lockTimeout, skipLocking);
}
}