Search in sources :

Example 6 with LockRefreshToken

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);
    }
}
Also used : BigInteger(java.math.BigInteger) LockRefreshToken(com.palantir.lock.LockRefreshToken) Test(org.junit.Test)

Example 7 with 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);
    }
}
Also used : BigInteger(java.math.BigInteger) LockRefreshToken(com.palantir.lock.LockRefreshToken) Test(org.junit.Test)

Example 8 with 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);
        }
    }
}
Also used : LockRefreshToken(com.palantir.lock.LockRefreshToken)

Example 9 with LockRefreshToken

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);
    }
}
Also used : LockRequest(com.palantir.lock.LockRequest) LockRefreshToken(com.palantir.lock.LockRefreshToken)

Example 10 with LockRefreshToken

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);
        }
    }
}
Also used : LockRefreshToken(com.palantir.lock.LockRefreshToken)

Aggregations

LockRefreshToken (com.palantir.lock.LockRefreshToken)22 Test (org.junit.Test)12 LockService (com.palantir.lock.LockService)6 LockDescriptor (com.palantir.lock.LockDescriptor)5 HeldLocksToken (com.palantir.lock.HeldLocksToken)4 LockRequest (com.palantir.lock.LockRequest)4 SimpleHeldLocksToken (com.palantir.lock.SimpleHeldLocksToken)3 StringLockDescriptor (com.palantir.lock.StringLockDescriptor)3 BigInteger (java.math.BigInteger)3 AtlasTimestampLockDescriptor (com.palantir.lock.AtlasTimestampLockDescriptor)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 GlobalClock (com.palantir.atlasdb.cleaner.GlobalClock)1 SingleBackendCliTestRunner (com.palantir.atlasdb.cli.runner.SingleBackendCliTestRunner)1 Cell (com.palantir.atlasdb.keyvalue.api.Cell)1 DaggerTestAtlasDbServices (com.palantir.atlasdb.services.test.DaggerTestAtlasDbServices)1 TestAtlasDbServices (com.palantir.atlasdb.services.test.TestAtlasDbServices)1 ExceptionMatchers (com.palantir.atlasdb.timelock.util.ExceptionMatchers)1 Clock (com.palantir.common.time.Clock)1 AtlasRowLockDescriptor (com.palantir.lock.AtlasRowLockDescriptor)1 LockClient (com.palantir.lock.LockClient)1