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