Search in sources :

Example 6 with LegacyTimelockService

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

the class SnapshotTransactionTest method testLockAfterGet.

// If lock happens concurrent with get, we aren't sure that we can rollback the transaction
@Test
public void testLockAfterGet() throws Exception {
    byte[] rowName = PtBytes.toBytes("1");
    Mockery m = new Mockery();
    final KeyValueService kvMock = m.mock(KeyValueService.class);
    final LockService lockMock = m.mock(LockService.class);
    LockService lock = MultiDelegateProxy.newProxyInstance(LockService.class, lockService, lockMock);
    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);
    m.checking(new Expectations() {

        {
            oneOf(kvMock).get(TABLE, ImmutableMap.of(cell, transactionTs));
            will(throwException(new RuntimeException()));
            never(lockMock).lockWithFullLockResponse(with(LockClient.ANONYMOUS), with(any(LockRequest.class)));
        }
    });
    SnapshotTransaction snapshot = new SnapshotTransaction(kvMock, new LegacyTimelockService(timestampService, lock, 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);
    try {
        snapshot.get(TABLE, ImmutableSet.of(cell));
        fail();
    } catch (RuntimeException e) {
    // expected
    }
    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) LockService(com.palantir.lock.LockService) Mockery(org.jmock.Mockery) Cell(com.palantir.atlasdb.keyvalue.api.Cell) LockRequest(com.palantir.lock.LockRequest) Test(org.junit.Test)

Example 7 with LegacyTimelockService

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

the class LegacyTimeLockServicesCreator method createTimeLockServices.

@Override
public TimeLockServices createTimeLockServices(String client, Supplier<ManagedTimestampService> rawTimestampServiceSupplier, Supplier<LockService> rawLockServiceSupplier) {
    log.info("Creating legacy timelock service for client {}", client);
    ManagedTimestampService timestampService = instrumentInLeadershipProxy(ManagedTimestampService.class, rawTimestampServiceSupplier, client);
    LockService lockService = instrumentInLeadershipProxy(LockService.class, rawLockServiceSupplier, client);
    // The underlying primitives are already wrapped in a leadership proxy (and must be).
    // Wrapping this means that we will make 2 paxos checks per request, which is silly.
    TimelockService legacyTimelockService = instrument(TimelockService.class, createRawLegacyTimelockService(timestampService, lockService), client);
    return TimeLockServices.create(timestampService, lockService, AsyncOrLegacyTimelockService.createFromLegacyTimelock(legacyTimelockService), timestampService);
}
Also used : LockService(com.palantir.lock.LockService) LegacyTimelockService(com.palantir.lock.impl.LegacyTimelockService) TimelockService(com.palantir.lock.v2.TimelockService) AsyncOrLegacyTimelockService(com.palantir.atlasdb.timelock.util.AsyncOrLegacyTimelockService) ManagedTimestampService(com.palantir.atlasdb.timelock.paxos.ManagedTimestampService)

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