Search in sources :

Example 1 with LockAcquisitionException

use of com.palantir.atlasdb.transaction.api.LockAcquisitionException in project atlasdb by palantir.

the class AdvisoryLockConditionSuppliers method acquireLock.

private static HeldLocksToken acquireLock(LockService lockService, LockRequest lockRequest) {
    int failureCount = 0;
    while (true) {
        HeldLocksToken response;
        try {
            response = lockService.lockAndGetHeldLocks(LockClient.ANONYMOUS.getClientId(), lockRequest);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new RuntimeException(e);
        }
        if (response == null) {
            RuntimeException ex = new LockAcquisitionException("Failed to lock using the provided lock request: " + lockRequest);
            log.warn("Count not lock successfully", ex);
            ++failureCount;
            if (failureCount >= NUM_RETRIES) {
                log.warn("Failing after {} tries", failureCount, ex);
                throw ex;
            }
            AbstractTransactionManager.sleepForBackoff(failureCount);
        } else {
            return response;
        }
    }
}
Also used : HeldLocksToken(com.palantir.lock.HeldLocksToken) LockAcquisitionException(com.palantir.atlasdb.transaction.api.LockAcquisitionException)

Aggregations

LockAcquisitionException (com.palantir.atlasdb.transaction.api.LockAcquisitionException)1 HeldLocksToken (com.palantir.lock.HeldLocksToken)1