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