Search in sources :

Example 6 with LockService

use of com.palantir.lock.LockService 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 7 with LockService

use of com.palantir.lock.LockService 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 8 with LockService

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

the class TransactionManagers method createRawRemoteServices.

private static LockAndTimestampServices createRawRemoteServices(AtlasDbConfig config, String userAgent) {
    LockService lockService = new ServiceCreator<>(LockService.class, userAgent).apply(config.lock().get());
    TimestampService timeService = new ServiceCreator<>(TimestampService.class, userAgent).apply(config.timestamp().get());
    return ImmutableLockAndTimestampServices.builder().lock(lockService).timestamp(timeService).timelock(new LegacyTimelockService(timeService, lockService, LOCK_CLIENT)).build();
}
Also used : LegacyTimelockService(com.palantir.lock.impl.LegacyTimelockService) NoOpPersistentLockService(com.palantir.atlasdb.persistentlock.NoOpPersistentLockService) KvsBackedPersistentLockService(com.palantir.atlasdb.persistentlock.KvsBackedPersistentLockService) LockService(com.palantir.lock.LockService) LockRefreshingLockService(com.palantir.lock.client.LockRefreshingLockService) PersistentLockService(com.palantir.atlasdb.persistentlock.PersistentLockService) TimestampService(com.palantir.timestamp.TimestampService)

Example 9 with LockService

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

the class TransactionManagers method createRawEmbeddedServices.

private static LockAndTimestampServices createRawEmbeddedServices(Consumer<Object> env, com.google.common.base.Supplier<LockService> lock, com.google.common.base.Supplier<TimestampService> time) {
    LockService lockService = ServiceCreator.createInstrumentedService(lock.get(), LockService.class);
    TimestampService timeService = ServiceCreator.createInstrumentedService(time.get(), TimestampService.class);
    env.accept(lockService);
    env.accept(timeService);
    return ImmutableLockAndTimestampServices.builder().lock(lockService).timestamp(timeService).timelock(new LegacyTimelockService(timeService, lockService, LOCK_CLIENT)).build();
}
Also used : LegacyTimelockService(com.palantir.lock.impl.LegacyTimelockService) NoOpPersistentLockService(com.palantir.atlasdb.persistentlock.NoOpPersistentLockService) KvsBackedPersistentLockService(com.palantir.atlasdb.persistentlock.KvsBackedPersistentLockService) LockService(com.palantir.lock.LockService) LockRefreshingLockService(com.palantir.lock.client.LockRefreshingLockService) PersistentLockService(com.palantir.atlasdb.persistentlock.PersistentLockService) TimestampService(com.palantir.timestamp.TimestampService)

Example 10 with LockService

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

the class LockRemotingTest method testLock.

@Test
public void testLock() throws InterruptedException, IOException {
    ObjectMapper mapper = new ObjectMapper();
    LockDescriptor desc = StringLockDescriptor.of("1234");
    String writeValueAsString = mapper.writeValueAsString(desc);
    LockDescriptor desc2 = mapper.readValue(writeValueAsString, LockDescriptor.class);
    long minVersion = 123;
    LockRequest request = LockRequest.builder(ImmutableSortedMap.of(desc, LockMode.WRITE)).doNotBlock().withLockedInVersionId(minVersion).build();
    writeValueAsString = mapper.writeValueAsString(request);
    LockRequest request2 = mapper.readValue(writeValueAsString, LockRequest.class);
    LockRefreshToken lockResponse = rawLock.lock(LockClient.ANONYMOUS.getClientId(), request);
    rawLock.unlock(lockResponse);
    writeValueAsString = mapper.writeValueAsString(lockResponse);
    LockRefreshToken lockResponse2 = mapper.readValue(writeValueAsString, LockRefreshToken.class);
    LockService lock = AtlasDbFeignTargetFactory.createProxy(Optional.empty(), lockService.baseUri().toString(), LockService.class, UserAgents.DEFAULT_USER_AGENT);
    String lockClient = "23234";
    LockRefreshToken token = lock.lock(lockClient, request);
    long minLockedInVersionId = lock.getMinLockedInVersionId(lockClient);
    Assert.assertEquals(minVersion, minLockedInVersionId);
    lock.unlock(token);
    token = lock.lock(LockClient.ANONYMOUS.getClientId(), request);
    Set<LockRefreshToken> refreshed = lock.refreshLockRefreshTokens(ImmutableList.of(token));
    Assert.assertEquals(1, refreshed.size());
    lock.unlock(token);
    try {
        lock.logCurrentState();
    } finally {
        LockServiceTestUtils.cleanUpLogStateDir();
    }
    lock.currentTimeMillis();
    HeldLocksToken token1 = lock.lockAndGetHeldLocks(LockClient.ANONYMOUS.getClientId(), request);
    HeldLocksToken token2 = lock.lockAndGetHeldLocks(LockClient.ANONYMOUS.getClientId(), request2);
    Assert.assertNull(token2);
    lock.unlock(token1.getLockRefreshToken());
    token2 = lock.lockAndGetHeldLocks(LockClient.ANONYMOUS.getClientId(), request2);
    Assert.assertNotNull(token2);
    lock.unlock(token2.getLockRefreshToken());
}
Also used : StringLockDescriptor(com.palantir.lock.StringLockDescriptor) LockDescriptor(com.palantir.lock.LockDescriptor) LockService(com.palantir.lock.LockService) HeldLocksToken(com.palantir.lock.HeldLocksToken) LockRequest(com.palantir.lock.LockRequest) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LockRefreshToken(com.palantir.lock.LockRefreshToken) Test(org.junit.Test)

Aggregations

LockService (com.palantir.lock.LockService)22 Test (org.junit.Test)11 LockRefreshToken (com.palantir.lock.LockRefreshToken)7 LegacyTimelockService (com.palantir.lock.impl.LegacyTimelockService)7 TimestampService (com.palantir.timestamp.TimestampService)6 KvsBackedPersistentLockService (com.palantir.atlasdb.persistentlock.KvsBackedPersistentLockService)5 NoOpPersistentLockService (com.palantir.atlasdb.persistentlock.NoOpPersistentLockService)5 PersistentLockService (com.palantir.atlasdb.persistentlock.PersistentLockService)5 LockRefreshingLockService (com.palantir.lock.client.LockRefreshingLockService)5 TimelockService (com.palantir.lock.v2.TimelockService)5 LockClient (com.palantir.lock.LockClient)4 LockRequest (com.palantir.lock.LockRequest)4 KeyValueService (com.palantir.atlasdb.keyvalue.api.KeyValueService)3 TransactionManager (com.palantir.atlasdb.transaction.api.TransactionManager)3 Cleaner (com.palantir.atlasdb.cleaner.Cleaner)2 NoOpCleaner (com.palantir.atlasdb.cleaner.NoOpCleaner)2 Cell (com.palantir.atlasdb.keyvalue.api.Cell)2 ForwardingKeyValueService (com.palantir.atlasdb.keyvalue.impl.ForwardingKeyValueService)2 TrackingKeyValueService (com.palantir.atlasdb.keyvalue.impl.TrackingKeyValueService)2 ManagedTimestampService (com.palantir.atlasdb.timelock.paxos.ManagedTimestampService)2