use of com.palantir.lock.LockRefreshToken in project atlasdb by palantir.
the class LockTokenConverterTest method convertsNegativeBigIntegersCorrectly.
@Test
public void convertsNegativeBigIntegersCorrectly() {
int iterations = 100_000;
int bitLength = LockServiceImpl.RANDOM_BIT_COUNT;
for (int i = 0; i < iterations; i++) {
BigInteger randomBigInteger = new BigInteger(bitLength, RANDOM).negate();
LockRefreshToken lockRefreshToken = new LockRefreshToken(randomBigInteger, Long.MIN_VALUE);
assertConversionFromAndToLegacyPreservesId(lockRefreshToken);
}
}
use of com.palantir.lock.LockRefreshToken in project atlasdb by palantir.
the class LockTokenConverterTest method convertsBigIntegersCorrectly.
@Test
public void convertsBigIntegersCorrectly() {
int iterations = 100_000;
int bitLength = LockServiceImpl.RANDOM_BIT_COUNT;
for (int i = 0; i < iterations; i++) {
BigInteger randomBigInteger = new BigInteger(bitLength, RANDOM);
LockRefreshToken lockRefreshToken = new LockRefreshToken(randomBigInteger, Long.MIN_VALUE);
assertConversionFromAndToLegacyPreservesId(lockRefreshToken);
}
}
use of com.palantir.lock.LockRefreshToken in project atlasdb by palantir.
the class LockRefreshingRemoteLockService method refreshLocks.
private void refreshLocks() {
ImmutableSet<LockRefreshToken> refreshCopy = ImmutableSet.copyOf(toRefresh);
if (refreshCopy.isEmpty()) {
return;
}
Set<LockRefreshToken> refreshedTokens = delegate().refreshLockRefreshTokens(refreshCopy);
for (LockRefreshToken token : refreshCopy) {
if (!refreshedTokens.contains(token) && toRefresh.contains(token)) {
log.error("failed to refresh lock: {}", token);
toRefresh.remove(token);
}
}
}
use of com.palantir.lock.LockRefreshToken in project atlasdb by palantir.
the class ClientSplitLockService method lock.
private LockRefreshToken lock(LockClient client, LockRequest request) throws InterruptedException {
if (request.getBlockingMode() == BlockingMode.DO_NOT_BLOCK) {
if (client == LockClient.ANONYMOUS) {
return nonBlockingClient.lock(LockClient.ANONYMOUS.getClientId(), request);
} else {
return nonBlockingClient.lock(client.getClientId(), request);
}
}
// Let's try sending this request as a non-blocking request.
if ((request.getLockGroupBehavior() == LockGroupBehavior.LOCK_ALL_OR_NONE) && (request.getBlockingMode() != BlockingMode.BLOCK_INDEFINITELY_THEN_RELEASE)) {
LockRequest.Builder newRequest = LockRequest.builder(request.getLockDescriptors());
newRequest.doNotBlock();
newRequest.timeoutAfter(request.getLockTimeout());
if (request.getVersionId() != null) {
newRequest.withLockedInVersionId(request.getVersionId());
}
final LockRefreshToken response;
if (client == LockClient.ANONYMOUS) {
response = nonBlockingClient.lock(LockClient.ANONYMOUS.getClientId(), request);
} else {
response = nonBlockingClient.lock(client.getClientId(), request);
}
if (response != null) {
return response;
}
}
// No choice but to send it as a blocking request.
if (client == LockClient.ANONYMOUS) {
return blockingClient.lock(LockClient.ANONYMOUS.getClientId(), request);
} else {
return blockingClient.lock(client.getClientId(), request);
}
}
use of com.palantir.lock.LockRefreshToken in project atlasdb by palantir.
the class LockRefreshingLockService method refreshLocks.
private void refreshLocks() {
ImmutableSet<LockRefreshToken> refreshCopy = ImmutableSet.copyOf(toRefresh);
if (refreshCopy.isEmpty()) {
return;
}
Set<LockRefreshToken> refreshedTokens = delegate().refreshLockRefreshTokens(refreshCopy);
for (LockRefreshToken token : refreshCopy) {
if (!refreshedTokens.contains(token) && toRefresh.contains(token)) {
log.error("failed to refresh lock: {}", token);
toRefresh.remove(token);
}
}
}
Aggregations