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);
}
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();
}
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();
}
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());
}
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);
}
Aggregations