Search in sources :

Example 1 with WaitForLocksRequest

use of com.palantir.lock.v2.WaitForLocksRequest in project atlasdb by palantir.

the class AsyncTimelockServiceIntegrationTest method waitForLockRequestsAreIdempotent.

@Test
public void waitForLockRequestsAreIdempotent() {
    if (isUsingSyncAdapter(cluster)) {
        // legacy API does not support idempotence
        return;
    }
    LockToken token = cluster.lock(requestFor(LOCK_A)).getToken();
    WaitForLocksRequest request = waitRequestFor(LOCK_A);
    CompletableFuture<WaitForLocksResponse> response = cluster.waitForLocksAsync(request);
    CompletableFuture<WaitForLocksResponse> duplicateResponse = cluster.waitForLocksAsync(request);
    cluster.unlock(token);
    assertThat(response.join()).isEqualTo(duplicateResponse.join());
}
Also used : WaitForLocksRequest(com.palantir.lock.v2.WaitForLocksRequest) WaitForLocksResponse(com.palantir.lock.v2.WaitForLocksResponse) LockToken(com.palantir.lock.v2.LockToken) Test(org.junit.Test)

Example 2 with WaitForLocksRequest

use of com.palantir.lock.v2.WaitForLocksRequest 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 3 with WaitForLocksRequest

use of com.palantir.lock.v2.WaitForLocksRequest in project atlasdb by palantir.

the class TimeLockClientTest method waitForLocksDelegates.

@Test
public void waitForLocksDelegates() {
    WaitForLocksRequest request = WaitForLocksRequest.of(LOCKS, TIMEOUT);
    timelock.waitForLocks(request);
    verify(delegate).waitForLocks(request);
    verifyNoMoreInteractions(refresher);
}
Also used : WaitForLocksRequest(com.palantir.lock.v2.WaitForLocksRequest) Test(org.junit.Test)

Aggregations

WaitForLocksRequest (com.palantir.lock.v2.WaitForLocksRequest)3 WaitForLocksResponse (com.palantir.lock.v2.WaitForLocksResponse)2 Test (org.junit.Test)2 TransactionLockAcquisitionTimeoutException (com.palantir.atlasdb.transaction.api.TransactionLockAcquisitionTimeoutException)1 AtlasCellLockDescriptor (com.palantir.lock.AtlasCellLockDescriptor)1 AtlasRowLockDescriptor (com.palantir.lock.AtlasRowLockDescriptor)1 LockDescriptor (com.palantir.lock.LockDescriptor)1 LockToken (com.palantir.lock.v2.LockToken)1