Search in sources :

Example 1 with LockResponse

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

the class AsyncTimelockServiceIntegrationTest method locksAreExclusive.

@Test
public void locksAreExclusive() {
    LockToken token = cluster.lock(requestFor(LOCK_A)).getToken();
    Future<LockToken> futureToken = cluster.lockAsync(requestFor(LOCK_A)).thenApply(LockResponse::getToken);
    assertNotYetLocked(futureToken);
    cluster.unlock(token);
    assertLockedAndUnlock(futureToken);
}
Also used : LockResponse(com.palantir.lock.v2.LockResponse) LockToken(com.palantir.lock.v2.LockToken) Test(org.junit.Test)

Example 2 with LockResponse

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

the class AsyncLockClient method lock.

@Override
public LockToken lock(String client, String lockName) throws InterruptedException {
    LockRequest lockRequest = LockRequest.of(ImmutableSet.of(StringLockDescriptor.of(lockName)), Long.MAX_VALUE, client);
    LockResponse lockResponse = timelockService.lock(lockRequest);
    Preconditions.checkState(lockResponse.wasSuccessful(), "Jepsen failed to lock a lock, but it would wait for Long.MAX_VALUE, so this is unexpected.");
    return lockResponse.getToken();
}
Also used : LockResponse(com.palantir.lock.v2.LockResponse) LockRequest(com.palantir.lock.v2.LockRequest)

Example 3 with LockResponse

use of com.palantir.lock.v2.LockResponse 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)

Example 4 with LockResponse

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

the class AsyncTimelockServiceIntegrationTest method lockRequestsAreIdempotent.

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

Example 5 with LockResponse

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

the class AsyncTimelockServiceIntegrationTest method lockRequestCanTimeOut.

@Test
public void lockRequestCanTimeOut() {
    LockToken token = cluster.lock(requestFor(LOCK_A)).getToken();
    LockResponse token2 = cluster.lock(requestFor(SHORT_TIMEOUT, LOCK_A));
    assertThat(token2.wasSuccessful()).isFalse();
    cluster.unlock(token);
}
Also used : LockResponse(com.palantir.lock.v2.LockResponse) LockToken(com.palantir.lock.v2.LockToken) Test(org.junit.Test)

Aggregations

LockResponse (com.palantir.lock.v2.LockResponse)5 LockRequest (com.palantir.lock.v2.LockRequest)3 LockToken (com.palantir.lock.v2.LockToken)3 Test (org.junit.Test)3 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