Search in sources :

Example 6 with TimestampService

use of com.palantir.timestamp.TimestampService in project atlasdb by palantir.

the class TransactionManagerTest method shouldNotMakeRemoteCallsInAReadonlyTransactionIfNoWorkIsDone.

@Test
public void shouldNotMakeRemoteCallsInAReadonlyTransactionIfNoWorkIsDone() {
    TimestampService mockTimestampService = mock(TimestampService.class);
    LockService mockLockService = mock(LockService.class);
    TransactionManager txnManagerWithMocks = SerializableTransactionManager.createForTest(getKeyValueService(), mockTimestampService, LockClient.of("foo"), mockLockService, transactionService, () -> AtlasDbConstraintCheckingMode.FULL_CONSTRAINT_CHECKING_THROWS_EXCEPTIONS, conflictDetectionManager, sweepStrategyManager, NoOpCleaner.INSTANCE, AbstractTransactionTest.GET_RANGES_THREAD_POOL_SIZE, AbstractTransactionTest.DEFAULT_GET_RANGES_CONCURRENCY, () -> AtlasDbConstants.DEFAULT_TIMESTAMP_CACHE_SIZE, MultiTableSweepQueueWriter.NO_OP);
    // fetch an immutable timestamp once so it's cached
    when(mockTimestampService.getFreshTimestamp()).thenReturn(1L);
    when(mockLockService.getMinLockedInVersionId("foo")).thenReturn(1L);
    txnManagerWithMocks.getImmutableTimestamp();
    verify(mockTimestampService).getFreshTimestamp();
    verify(mockLockService).getMinLockedInVersionId("foo");
    // now execute a read transaction
    txnManagerWithMocks.runTaskReadOnly(txn -> null);
    verifyNoMoreInteractions(mockLockService);
    verifyNoMoreInteractions(mockTimestampService);
}
Also used : LockService(com.palantir.lock.LockService) TransactionManager(com.palantir.atlasdb.transaction.api.TransactionManager) TimestampService(com.palantir.timestamp.TimestampService) Test(org.junit.Test)

Example 7 with TimestampService

use of com.palantir.timestamp.TimestampService 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 8 with TimestampService

use of com.palantir.timestamp.TimestampService in project atlasdb by palantir.

the class KeyValueServiceMigrators method getTimestampManagementService.

@VisibleForTesting
static TimestampManagementService getTimestampManagementService(AtlasDbServices toServices) {
    TimestampService toTimestampService = toServices.getTimestampService();
    if (toTimestampService instanceof TimestampManagementService) {
        return (TimestampManagementService) toTimestampService;
    }
    String errorMessage = String.format("Timestamp service must be of type %s, but yours is %s. Exiting.", TimestampManagementService.class.toString(), toTimestampService.getClass().toString());
    printer.error(errorMessage);
    throw new IllegalArgumentException(errorMessage);
}
Also used : TimestampManagementService(com.palantir.timestamp.TimestampManagementService) TimestampService(com.palantir.timestamp.TimestampService) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 9 with TimestampService

use of com.palantir.timestamp.TimestampService 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 10 with TimestampService

use of com.palantir.timestamp.TimestampService in project atlasdb by palantir.

the class TestSweepCommand method testSweepAll.

@Test
public void testSweepAll() throws Exception {
    try (SingleBackendCliTestRunner runner = makeRunner(paramsWithDryRunSet(SWEEP_COMMAND, "-a"))) {
        TestAtlasDbServices services = runner.connect(moduleFactory);
        SerializableTransactionManager txm = services.getTransactionManager();
        TimestampService tss = services.getTimestampService();
        KeyValueService kvs = services.getKeyValueService();
        createTable(kvs, TABLE_ONE, TableMetadataPersistence.SweepStrategy.CONSERVATIVE);
        createTable(kvs, TABLE_TWO, TableMetadataPersistence.SweepStrategy.CONSERVATIVE);
        createTable(kvs, TABLE_THREE, TableMetadataPersistence.SweepStrategy.CONSERVATIVE);
        long ts1 = put(txm, TABLE_ONE, "foo", "bar");
        long ts2 = put(txm, TABLE_TWO, "foo", "tar");
        long ts3 = put(txm, TABLE_THREE, "foo", "jar");
        long ts4 = put(txm, TABLE_ONE, "foo", "baz");
        long ts5 = put(txm, TABLE_THREE, "foo", "jaz");
        long ts6 = put(txm, TABLE_TWO, "foo", "taz");
        long ts7 = tss.getFreshTimestamp();
        sweep(runner, ts7);
        Assert.assertEquals("baz", get(kvs, TABLE_ONE, "foo", ts7));
        Assert.assertEquals(deletedValue("bar"), get(kvs, TABLE_ONE, "foo", mid(ts1, ts2)));
        Assert.assertEquals(ImmutableSet.of(deletedTimestamp(ts1), ts4), getAllTs(kvs, TABLE_ONE, "foo"));
        Assert.assertEquals("taz", get(kvs, TABLE_TWO, "foo", ts7));
        Assert.assertEquals(deletedValue("tar"), get(kvs, TABLE_TWO, "foo", mid(ts4, ts6)));
        Assert.assertEquals(ImmutableSet.of(deletedTimestamp(ts2), ts6), getAllTs(kvs, TABLE_TWO, "foo"));
        Assert.assertEquals("jaz", get(kvs, TABLE_THREE, "foo", ts7));
        Assert.assertEquals(deletedValue("jar"), get(kvs, TABLE_THREE, "foo", mid(ts3, ts5)));
        Assert.assertEquals(ImmutableSet.of(deletedTimestamp(ts3), ts5), getAllTs(kvs, TABLE_THREE, "foo"));
    }
}
Also used : KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) SingleBackendCliTestRunner(com.palantir.atlasdb.cli.runner.SingleBackendCliTestRunner) SerializableTransactionManager(com.palantir.atlasdb.transaction.impl.SerializableTransactionManager) DaggerTestAtlasDbServices(com.palantir.atlasdb.services.test.DaggerTestAtlasDbServices) TestAtlasDbServices(com.palantir.atlasdb.services.test.TestAtlasDbServices) TimestampService(com.palantir.timestamp.TimestampService) Test(org.junit.Test)

Aggregations

TimestampService (com.palantir.timestamp.TimestampService)26 Test (org.junit.Test)12 InMemoryTimestampService (com.palantir.timestamp.InMemoryTimestampService)7 SerializableTransactionManager (com.palantir.atlasdb.transaction.impl.SerializableTransactionManager)6 LockService (com.palantir.lock.LockService)6 SingleBackendCliTestRunner (com.palantir.atlasdb.cli.runner.SingleBackendCliTestRunner)5 KeyValueService (com.palantir.atlasdb.keyvalue.api.KeyValueService)5 DaggerTestAtlasDbServices (com.palantir.atlasdb.services.test.DaggerTestAtlasDbServices)5 TestAtlasDbServices (com.palantir.atlasdb.services.test.TestAtlasDbServices)5 LockRefreshingLockService (com.palantir.lock.client.LockRefreshingLockService)4 Before (org.junit.Before)4 KvsBackedPersistentLockService (com.palantir.atlasdb.persistentlock.KvsBackedPersistentLockService)3 NoOpPersistentLockService (com.palantir.atlasdb.persistentlock.NoOpPersistentLockService)3 PersistentLockService (com.palantir.atlasdb.persistentlock.PersistentLockService)3 SweepStrategyManager (com.palantir.atlasdb.transaction.impl.SweepStrategyManager)3 TransactionService (com.palantir.atlasdb.transaction.service.TransactionService)3 LockClient (com.palantir.lock.LockClient)3 LegacyTimelockService (com.palantir.lock.impl.LegacyTimelockService)3 TimestampManagementService (com.palantir.timestamp.TimestampManagementService)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2