Search in sources :

Example 1 with TransactionLockAcquisitionTimeoutException

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

the class SnapshotTransaction method waitForCommitToComplete.

/**
 * We will block here until the passed transactions have released their lock.  This means that
 * the committing transaction is either complete or it has failed and we are allowed to roll
 * it back.
 */
private void waitForCommitToComplete(Iterable<Long> startTimestamps) {
    boolean isEmpty = true;
    Set<LockDescriptor> lockDescriptors = Sets.newHashSet();
    for (long start : startTimestamps) {
        if (start < immutableTimestamp) {
            // We don't need to block in this case because this transaction is already complete
            continue;
        }
        isEmpty = false;
        lockDescriptors.add(AtlasRowLockDescriptor.of(TransactionConstants.TRANSACTION_TABLE.getQualifiedName(), TransactionConstants.getValueForTimestamp(start)));
    }
    if (isEmpty) {
        return;
    }
    WaitForLocksRequest request = WaitForLocksRequest.of(lockDescriptors, lockAcquireTimeoutMs);
    WaitForLocksResponse response = timelockService.waitForLocks(request);
    if (!response.wasSuccessful()) {
        log.error("Timed out waiting for commits to complete. Timeout was {} ms. First ten locks were {}.", SafeArg.of("requestId", request.getRequestId()), SafeArg.of("acquireTimeoutMs", lockAcquireTimeoutMs), UnsafeArg.of("firstTenLockDescriptors", Iterables.limit(lockDescriptors, 10)));
        throw new TransactionLockAcquisitionTimeoutException("Timed out waiting for commits to complete.");
    }
}
Also used : WaitForLocksRequest(com.palantir.lock.v2.WaitForLocksRequest) AtlasCellLockDescriptor(com.palantir.lock.AtlasCellLockDescriptor) AtlasRowLockDescriptor(com.palantir.lock.AtlasRowLockDescriptor) LockDescriptor(com.palantir.lock.LockDescriptor) WaitForLocksResponse(com.palantir.lock.v2.WaitForLocksResponse) TransactionLockAcquisitionTimeoutException(com.palantir.atlasdb.transaction.api.TransactionLockAcquisitionTimeoutException)

Example 2 with TransactionLockAcquisitionTimeoutException

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

the class SnapshotTransaction method acquireLocksForCommit.

// /////////////////////////////////////////////////////////////////////////
// / Locking
// /////////////////////////////////////////////////////////////////////////
/**
 * This method should acquire any locks needed to do proper concurrency control at commit time.
 */
protected LockToken acquireLocksForCommit() {
    Set<LockDescriptor> lockDescriptors = getLocksForWrites();
    LockRequest request = LockRequest.of(lockDescriptors, lockAcquireTimeoutMs);
    LockResponse lockResponse = timelockService.lock(request);
    if (!lockResponse.wasSuccessful()) {
        log.error("Timed out waiting while acquiring commit locks. Request id was {}. Timeout was {} ms. " + "First ten required locks were {}.", SafeArg.of("requestId", request.getRequestId()), SafeArg.of("acquireTimeoutMs", lockAcquireTimeoutMs), UnsafeArg.of("firstTenLockDescriptors", Iterables.limit(lockDescriptors, 10)));
        throw new TransactionLockAcquisitionTimeoutException("Timed out while acquiring commit locks.");
    }
    return lockResponse.getToken();
}
Also used : AtlasCellLockDescriptor(com.palantir.lock.AtlasCellLockDescriptor) AtlasRowLockDescriptor(com.palantir.lock.AtlasRowLockDescriptor) LockDescriptor(com.palantir.lock.LockDescriptor) LockResponse(com.palantir.lock.v2.LockResponse) TransactionLockAcquisitionTimeoutException(com.palantir.atlasdb.transaction.api.TransactionLockAcquisitionTimeoutException) LockRequest(com.palantir.lock.v2.LockRequest)

Aggregations

TransactionLockAcquisitionTimeoutException (com.palantir.atlasdb.transaction.api.TransactionLockAcquisitionTimeoutException)2 AtlasCellLockDescriptor (com.palantir.lock.AtlasCellLockDescriptor)2 AtlasRowLockDescriptor (com.palantir.lock.AtlasRowLockDescriptor)2 LockDescriptor (com.palantir.lock.LockDescriptor)2 LockRequest (com.palantir.lock.v2.LockRequest)1 LockResponse (com.palantir.lock.v2.LockResponse)1 WaitForLocksRequest (com.palantir.lock.v2.WaitForLocksRequest)1 WaitForLocksResponse (com.palantir.lock.v2.WaitForLocksResponse)1