Search in sources :

Example 1 with LockClient

use of com.palantir.lock.LockClient in project atlasdb by palantir.

the class SweepTestUtils method setupTxManager.

public static SerializableTransactionManager setupTxManager(KeyValueService kvs, TimestampService tsService, SweepStrategyManager ssm, TransactionService txService) {
    LockClient lockClient = LockClient.of("sweep client");
    LockService lockService = LockServiceImpl.create(LockServerOptions.builder().isStandaloneServer(false).build());
    Supplier<AtlasDbConstraintCheckingMode> constraints = () -> AtlasDbConstraintCheckingMode.NO_CONSTRAINT_CHECKING;
    ConflictDetectionManager cdm = ConflictDetectionManagers.createWithoutWarmingCache(kvs);
    Cleaner cleaner = new NoOpCleaner();
    SerializableTransactionManager txManager = SerializableTransactionManager.createForTest(kvs, tsService, lockClient, lockService, txService, constraints, cdm, ssm, cleaner, AbstractTransactionTest.GET_RANGES_THREAD_POOL_SIZE, AbstractTransactionTest.DEFAULT_GET_RANGES_CONCURRENCY, () -> AtlasDbConstants.DEFAULT_TIMESTAMP_CACHE_SIZE, InMemorySweepQueue.writer());
    setupTables(kvs);
    return txManager;
}
Also used : AtlasDbConstraintCheckingMode(com.palantir.atlasdb.transaction.api.AtlasDbConstraintCheckingMode) KvsBackedPersistentLockService(com.palantir.atlasdb.persistentlock.KvsBackedPersistentLockService) NoOpPersistentLockService(com.palantir.atlasdb.persistentlock.NoOpPersistentLockService) PersistentLockService(com.palantir.atlasdb.persistentlock.PersistentLockService) LockService(com.palantir.lock.LockService) LockClient(com.palantir.lock.LockClient) NoOpCleaner(com.palantir.atlasdb.cleaner.NoOpCleaner) SerializableTransactionManager(com.palantir.atlasdb.transaction.impl.SerializableTransactionManager) ConflictDetectionManager(com.palantir.atlasdb.transaction.impl.ConflictDetectionManager) Cleaner(com.palantir.atlasdb.cleaner.Cleaner) NoOpCleaner(com.palantir.atlasdb.cleaner.NoOpCleaner)

Example 2 with LockClient

use of com.palantir.lock.LockClient in project atlasdb by palantir.

the class TableTasksTest method setup.

@Before
public void setup() {
    kvs = new InMemoryKeyValueService(true);
    TimestampService tsService = new InMemoryTimestampService();
    LockClient lockClient = LockClient.of("sweep client");
    lockService = LockServiceImpl.create(LockServerOptions.builder().isStandaloneServer(false).build());
    TransactionService txService = TransactionServices.createTransactionService(kvs);
    Supplier<AtlasDbConstraintCheckingMode> constraints = Suppliers.ofInstance(AtlasDbConstraintCheckingMode.NO_CONSTRAINT_CHECKING);
    ConflictDetectionManager cdm = ConflictDetectionManagers.createWithoutWarmingCache(kvs);
    SweepStrategyManager ssm = SweepStrategyManagers.createDefault(kvs);
    Cleaner cleaner = new NoOpCleaner();
    SerializableTransactionManager transactionManager = SerializableTransactionManager.createForTest(kvs, tsService, lockClient, lockService, txService, constraints, cdm, ssm, cleaner, AbstractTransactionTest.GET_RANGES_THREAD_POOL_SIZE, AbstractTransactionTest.DEFAULT_GET_RANGES_CONCURRENCY, () -> AtlasDbConstants.DEFAULT_TIMESTAMP_CACHE_SIZE, MultiTableSweepQueueWriter.NO_OP);
    txManager = transactionManager;
}
Also used : SweepStrategyManager(com.palantir.atlasdb.transaction.impl.SweepStrategyManager) AtlasDbConstraintCheckingMode(com.palantir.atlasdb.transaction.api.AtlasDbConstraintCheckingMode) TransactionService(com.palantir.atlasdb.transaction.service.TransactionService) LockClient(com.palantir.lock.LockClient) NoOpCleaner(com.palantir.atlasdb.cleaner.NoOpCleaner) SerializableTransactionManager(com.palantir.atlasdb.transaction.impl.SerializableTransactionManager) ConflictDetectionManager(com.palantir.atlasdb.transaction.impl.ConflictDetectionManager) InMemoryTimestampService(com.palantir.timestamp.InMemoryTimestampService) InMemoryTimestampService(com.palantir.timestamp.InMemoryTimestampService) TimestampService(com.palantir.timestamp.TimestampService) Cleaner(com.palantir.atlasdb.cleaner.Cleaner) NoOpCleaner(com.palantir.atlasdb.cleaner.NoOpCleaner) Before(org.junit.Before)

Example 3 with LockClient

use of com.palantir.lock.LockClient in project atlasdb by palantir.

the class TestTimestampCommand method runAndVerifyCli.

private void runAndVerifyCli(Verifier verifier) throws Exception {
    try (SingleBackendCliTestRunner runner = makeRunner(cliArgs.toArray(new String[0]))) {
        TestAtlasDbServices services = runner.connect(moduleFactory);
        LockService lockService = services.getLockService();
        TimestampService tss = services.getTimestampService();
        LockClient client = services.getTestLockClient();
        Clock clock = GlobalClock.create(lockService);
        long prePunch = clock.getTimeMillis();
        punch(services, tss, clock);
        long postPunch = clock.getTimeMillis();
        long immutableTs = tss.getFreshTimestamp();
        LockRequest request = LockRequest.builder(ImmutableSortedMap.of(lock, LockMode.WRITE)).withLockedInVersionId(immutableTs).doNotBlock().build();
        LockRefreshToken token = lockService.lock(client.getClientId(), request);
        long lastFreshTs = tss.getFreshTimestamps(1000).getUpperBound();
        verifier.verify(runner, tss, immutableTs, prePunch, postPunch, lastFreshTs, true);
        lockService.unlock(token);
        lastFreshTs = tss.getFreshTimestamps(1000).getUpperBound();
        // there are no locks so we now expect immutable to just be a fresh
        runner.freshCommand();
        verifier.verify(runner, tss, immutableTs, prePunch, postPunch, lastFreshTs, false);
    }
}
Also used : LockService(com.palantir.lock.LockService) LockClient(com.palantir.lock.LockClient) SingleBackendCliTestRunner(com.palantir.atlasdb.cli.runner.SingleBackendCliTestRunner) DaggerTestAtlasDbServices(com.palantir.atlasdb.services.test.DaggerTestAtlasDbServices) TestAtlasDbServices(com.palantir.atlasdb.services.test.TestAtlasDbServices) GlobalClock(com.palantir.atlasdb.cleaner.GlobalClock) Clock(com.palantir.common.time.Clock) LockRequest(com.palantir.lock.LockRequest) TimestampService(com.palantir.timestamp.TimestampService) LockRefreshToken(com.palantir.lock.LockRefreshToken)

Example 4 with LockClient

use of com.palantir.lock.LockClient in project atlasdb by palantir.

the class LockServiceImpl method unlockAndFreeze.

@Override
public boolean unlockAndFreeze(HeldLocksToken token) {
    Preconditions.checkNotNull(token);
    @Nullable HeldLocks<HeldLocksToken> heldLocks = heldLocksTokenMap.remove(token);
    if (heldLocks == null) {
        if (log.isTraceEnabled()) {
            log.trace(".unlockAndFreeze({}) returns false", token);
        }
        return false;
    }
    LockClient client = heldLocks.realToken.getClient();
    if (client.isAnonymous()) {
        heldLocksTokenMap.put(token, heldLocks);
        lockTokenReaperQueue.add(token);
        log.warn(UNLOCK_AND_FREEZE_FROM_ANONYMOUS_CLIENT, heldLocks.realToken);
        throw new IllegalArgumentException(MessageFormatter.format(UNLOCK_AND_FREEZE_FROM_ANONYMOUS_CLIENT, heldLocks.realToken).getMessage());
    }
    if (heldLocks.locks.hasReadLock()) {
        heldLocksTokenMap.put(token, heldLocks);
        lockTokenReaperQueue.add(token);
        log.warn(UNLOCK_AND_FREEZE, heldLocks.realToken);
        throw new IllegalArgumentException(MessageFormatter.format(UNLOCK_AND_FREEZE, heldLocks.realToken).getMessage());
    }
    for (ClientAwareReadWriteLock lock : heldLocks.locks.getKeys()) {
        lock.get(client, LockMode.WRITE).unlockAndFreeze();
    }
    lockClientMultimap.remove(client, token);
    if (heldLocks.realToken.getVersionId() != null) {
        versionIdMap.remove(client, heldLocks.realToken.getVersionId());
    }
    if (log.isTraceEnabled()) {
        log.trace(".unlockAndFreeze({}) returns true", token);
    }
    return true;
}
Also used : HeldLocksToken(com.palantir.lock.HeldLocksToken) SimpleHeldLocksToken(com.palantir.lock.SimpleHeldLocksToken) LockClient(com.palantir.lock.LockClient) Nullable(javax.annotation.Nullable)

Example 5 with LockClient

use of com.palantir.lock.LockClient in project atlasdb by palantir.

the class LockServiceSerDeTest method testPathParamSerDeOfLockClient.

@Test
public void testPathParamSerDeOfLockClient() throws Exception {
    LockClient lockClient = LockClient.of("xyz");
    String serializedForm = lockClient.toString();
    LockClient lockClient1 = new LockClient(serializedForm);
    assertEquals(lockClient, lockClient1);
}
Also used : LockClient(com.palantir.lock.LockClient) Test(org.junit.Test)

Aggregations

LockClient (com.palantir.lock.LockClient)13 HeldLocksToken (com.palantir.lock.HeldLocksToken)5 LockDescriptor (com.palantir.lock.LockDescriptor)5 LockMode (com.palantir.lock.LockMode)4 LockService (com.palantir.lock.LockService)4 StringLockDescriptor (com.palantir.lock.StringLockDescriptor)4 Nullable (javax.annotation.Nullable)4 Test (org.junit.Test)4 Cleaner (com.palantir.atlasdb.cleaner.Cleaner)3 NoOpCleaner (com.palantir.atlasdb.cleaner.NoOpCleaner)3 LockRequest (com.palantir.lock.LockRequest)3 BigInteger (java.math.BigInteger)3 KeyValueService (com.palantir.atlasdb.keyvalue.api.KeyValueService)2 AtlasDbConstraintCheckingMode (com.palantir.atlasdb.transaction.api.AtlasDbConstraintCheckingMode)2 ConflictDetectionManager (com.palantir.atlasdb.transaction.impl.ConflictDetectionManager)2 SerializableTransactionManager (com.palantir.atlasdb.transaction.impl.SerializableTransactionManager)2 LockResponse (com.palantir.lock.LockResponse)2 TimestampService (com.palantir.timestamp.TimestampService)2 ExecutionException (java.util.concurrent.ExecutionException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1