Search in sources :

Example 1 with LockRequest

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

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

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

the class TimeLockClientTest method registersLocks.

@Test
public void registersLocks() {
    LockRequest request = LockRequest.of(LOCKS, TIMEOUT);
    when(delegate.lock(request)).thenReturn(LockResponse.successful(TOKEN_1));
    timelock.lock(request);
    verify(refresher).registerLock(TOKEN_1);
}
Also used : LockRequest(com.palantir.lock.v2.LockRequest) Test(org.junit.Test)

Example 4 with LockRequest

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

Aggregations

LockRequest (com.palantir.lock.v2.LockRequest)4 LockResponse (com.palantir.lock.v2.LockResponse)3 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