Search in sources :

Example 1 with LegacyTimelockService

use of com.palantir.lock.impl.LegacyTimelockService in project atlasdb by palantir.

the class SnapshotTransactionTest method testPutCleanup.

@Ignore("Until we know what we want to do with GC this will be ignored.")
// This tests that uncommitted values are deleted and cleaned up
@SuppressWarnings("unchecked")
@Test
public void testPutCleanup() throws Exception {
    byte[] rowName = PtBytes.toBytes("1");
    Mockery m = new Mockery();
    final KeyValueService kvMock = m.mock(KeyValueService.class);
    KeyValueService kv = MultiDelegateProxy.newProxyInstance(KeyValueService.class, keyValueService, kvMock);
    final Cell cell = Cell.create(rowName, rowName);
    timestampService.getFreshTimestamp();
    final long startTs = timestampService.getFreshTimestamp();
    final long transactionTs = timestampService.getFreshTimestamp();
    keyValueService.put(TABLE, ImmutableMap.of(cell, PtBytes.EMPTY_BYTE_ARRAY), startTs);
    final Sequence seq = m.sequence("seq");
    m.checking(new Expectations() {

        {
            oneOf(kvMock).getLatestTimestamps(TABLE, ImmutableMap.of(cell, Long.MAX_VALUE));
            inSequence(seq);
            oneOf(kvMock).get(with(TransactionConstants.TRANSACTION_TABLE), with(any(Map.class)));
            inSequence(seq);
            oneOf(kvMock).putUnlessExists(with(TransactionConstants.TRANSACTION_TABLE), with(any(Map.class)));
            inSequence(seq);
            oneOf(kvMock).delete(TABLE, Multimaps.forMap(ImmutableMap.of(cell, startTs)));
            inSequence(seq);
            oneOf(kvMock).getLatestTimestamps(TABLE, ImmutableMap.of(cell, startTs));
            inSequence(seq);
            oneOf(kvMock).multiPut(with(any(Map.class)), with(transactionTs));
            inSequence(seq);
            oneOf(kvMock).putUnlessExists(with(TransactionConstants.TRANSACTION_TABLE), with(any(Map.class)));
            inSequence(seq);
        }
    });
    SnapshotTransaction snapshot = new SnapshotTransaction(kv, new LegacyTimelockService(timestampService, lockService, lockClient), transactionService, NoOpCleaner.INSTANCE, transactionTs, TestConflictDetectionManagers.createWithStaticConflictDetection(ImmutableMap.of(TABLE, ConflictHandler.RETRY_ON_WRITE_WRITE)), AtlasDbConstraintCheckingMode.NO_CONSTRAINT_CHECKING, TransactionReadSentinelBehavior.THROW_EXCEPTION, timestampCache, getRangesExecutor, defaultGetRangesConcurrency, sweepQueue);
    snapshot.put(TABLE, ImmutableMap.of(cell, PtBytes.EMPTY_BYTE_ARRAY));
    snapshot.commit();
    m.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) LegacyTimelockService(com.palantir.lock.impl.LegacyTimelockService) TrackingKeyValueService(com.palantir.atlasdb.keyvalue.impl.TrackingKeyValueService) ForwardingKeyValueService(com.palantir.atlasdb.keyvalue.impl.ForwardingKeyValueService) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) Sequence(org.jmock.Sequence) Mockery(org.jmock.Mockery) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ImmutableMap(com.google.common.collect.ImmutableMap) SortedMap(java.util.SortedMap) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with LegacyTimelockService

use of com.palantir.lock.impl.LegacyTimelockService 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 3 with LegacyTimelockService

use of com.palantir.lock.impl.LegacyTimelockService 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 4 with LegacyTimelockService

use of com.palantir.lock.impl.LegacyTimelockService in project atlasdb by palantir.

the class TransactionManagers method createRawLeaderServices.

private static LockAndTimestampServices createRawLeaderServices(LeaderConfig leaderConfig, Consumer<Object> env, com.google.common.base.Supplier<LockService> lock, com.google.common.base.Supplier<TimestampService> time, String userAgent) {
    // Create local services, that may or may not end up being registered in an Consumer<Object>.
    LeaderRuntimeConfig defaultRuntime = ImmutableLeaderRuntimeConfig.builder().build();
    LocalPaxosServices localPaxosServices = Leaders.createAndRegisterLocalServices(env, leaderConfig, () -> defaultRuntime, userAgent);
    LeaderElectionService leader = localPaxosServices.leaderElectionService();
    LockService localLock = ServiceCreator.createInstrumentedService(AwaitingLeadershipProxy.newProxyInstance(LockService.class, lock, leader), LockService.class);
    TimestampService localTime = ServiceCreator.createInstrumentedService(AwaitingLeadershipProxy.newProxyInstance(TimestampService.class, time, leader), TimestampService.class);
    env.accept(localLock);
    env.accept(localTime);
    // Create remote services, that may end up calling our own local services.
    ImmutableServerListConfig serverListConfig = ImmutableServerListConfig.builder().servers(leaderConfig.leaders()).sslConfiguration(leaderConfig.sslConfiguration()).build();
    LockService remoteLock = new ServiceCreator<>(LockService.class, userAgent).apply(serverListConfig);
    TimestampService remoteTime = new ServiceCreator<>(TimestampService.class, userAgent).apply(serverListConfig);
    if (leaderConfig.leaders().size() == 1) {
        // Attempting to connect to ourself while processing a request can lead to deadlock if incoming request
        // volume is high, as all Jetty threads end up waiting for the timestamp server, and no threads remain to
        // actually handle the timestamp server requests. If we are the only single leader, we can avoid the
        // deadlock entirely; so use PingableLeader's getUUID() to detect this situation and eliminate the redundant
        // call.
        PingableLeader localPingableLeader = localPaxosServices.pingableLeader();
        String localServerId = localPingableLeader.getUUID();
        PingableLeader remotePingableLeader = AtlasDbFeignTargetFactory.createRsProxy(ServiceCreator.createSslSocketFactory(leaderConfig.sslConfiguration()), Iterables.getOnlyElement(leaderConfig.leaders()), PingableLeader.class, userAgent);
        // Determine asynchronously whether the remote services are talking to our local services.
        CompletableFuture<Boolean> useLocalServicesFuture = new CompletableFuture<>();
        runAsync.accept(() -> {
            int logAfter = LOGGING_INTERVAL;
            while (true) {
                try {
                    String remoteServerId = remotePingableLeader.getUUID();
                    useLocalServicesFuture.complete(localServerId.equals(remoteServerId));
                    return;
                } catch (ClientErrorException e) {
                    useLocalServicesFuture.complete(false);
                    return;
                } catch (Throwable e) {
                    if (--logAfter == 0) {
                        log.warn("Failed to read remote timestamp server ID", e);
                        logAfter = LOGGING_INTERVAL;
                    }
                }
                Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
            }
        });
        // Create dynamic service proxies, that switch to talking directly to our local services if it turns out our
        // remote services are pointed at them anyway.
        LockService dynamicLockService = LocalOrRemoteProxy.newProxyInstance(LockService.class, localLock, remoteLock, useLocalServicesFuture);
        TimestampService dynamicTimeService = LocalOrRemoteProxy.newProxyInstance(TimestampService.class, localTime, remoteTime, useLocalServicesFuture);
        return ImmutableLockAndTimestampServices.builder().lock(dynamicLockService).timestamp(dynamicTimeService).timelock(new LegacyTimelockService(dynamicTimeService, dynamicLockService, LOCK_CLIENT)).build();
    } else {
        return ImmutableLockAndTimestampServices.builder().lock(remoteLock).timestamp(remoteTime).timelock(new LegacyTimelockService(remoteTime, remoteLock, LOCK_CLIENT)).build();
    }
}
Also used : LegacyTimelockService(com.palantir.lock.impl.LegacyTimelockService) ImmutableServerListConfig(com.palantir.atlasdb.config.ImmutableServerListConfig) 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) LocalPaxosServices(com.palantir.atlasdb.factory.Leaders.LocalPaxosServices) CompletableFuture(java.util.concurrent.CompletableFuture) PingableLeader(com.palantir.leader.PingableLeader) LeaderElectionService(com.palantir.leader.LeaderElectionService) ClientErrorException(javax.ws.rs.ClientErrorException) LeaderRuntimeConfig(com.palantir.atlasdb.config.LeaderRuntimeConfig) ImmutableLeaderRuntimeConfig(com.palantir.atlasdb.config.ImmutableLeaderRuntimeConfig) TimestampService(com.palantir.timestamp.TimestampService)

Example 5 with LegacyTimelockService

use of com.palantir.lock.impl.LegacyTimelockService in project atlasdb by palantir.

the class SnapshotTransactionManagerTest method canCloseTransactionManagerWithNonCloseableLockService.

@Test
public void canCloseTransactionManagerWithNonCloseableLockService() {
    SnapshotTransactionManager newTransactionManager = new SnapshotTransactionManager(keyValueService, new LegacyTimelockService(new InMemoryTimestampService(), closeableLockService, LockClient.of("lock")), // not closeable
    mock(LockService.class), null, null, null, null, cleaner, false, () -> AtlasDbConstants.DEFAULT_TRANSACTION_LOCK_ACQUIRE_TIMEOUT_MS, TimestampTrackerImpl.createNoOpTracker(), TransactionTestConstants.GET_RANGES_THREAD_POOL_SIZE, TransactionTestConstants.DEFAULT_GET_RANGES_CONCURRENCY, () -> AtlasDbConstants.DEFAULT_TIMESTAMP_CACHE_SIZE, MultiTableSweepQueueWriter.NO_OP);
    // should not throw
    newTransactionManager.close();
}
Also used : LegacyTimelockService(com.palantir.lock.impl.LegacyTimelockService) CloseableLockService(com.palantir.lock.CloseableLockService) LockService(com.palantir.lock.LockService) InMemoryTimestampService(com.palantir.timestamp.InMemoryTimestampService) Test(org.junit.Test)

Aggregations

LegacyTimelockService (com.palantir.lock.impl.LegacyTimelockService)7 LockService (com.palantir.lock.LockService)6 KvsBackedPersistentLockService (com.palantir.atlasdb.persistentlock.KvsBackedPersistentLockService)3 NoOpPersistentLockService (com.palantir.atlasdb.persistentlock.NoOpPersistentLockService)3 PersistentLockService (com.palantir.atlasdb.persistentlock.PersistentLockService)3 LockRefreshingLockService (com.palantir.lock.client.LockRefreshingLockService)3 TimestampService (com.palantir.timestamp.TimestampService)3 Test (org.junit.Test)3 Cell (com.palantir.atlasdb.keyvalue.api.Cell)2 KeyValueService (com.palantir.atlasdb.keyvalue.api.KeyValueService)2 ForwardingKeyValueService (com.palantir.atlasdb.keyvalue.impl.ForwardingKeyValueService)2 TrackingKeyValueService (com.palantir.atlasdb.keyvalue.impl.TrackingKeyValueService)2 Expectations (org.jmock.Expectations)2 Mockery (org.jmock.Mockery)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 ImmutableLeaderRuntimeConfig (com.palantir.atlasdb.config.ImmutableLeaderRuntimeConfig)1 ImmutableServerListConfig (com.palantir.atlasdb.config.ImmutableServerListConfig)1 LeaderRuntimeConfig (com.palantir.atlasdb.config.LeaderRuntimeConfig)1 LocalPaxosServices (com.palantir.atlasdb.factory.Leaders.LocalPaxosServices)1