Search in sources :

Example 6 with KeyValueService

use of com.palantir.atlasdb.keyvalue.api.KeyValueService in project atlasdb by palantir.

the class ScrubberTest method isNotInitializedWhenKvsIsNotInitialized.

@Test
public void isNotInitializedWhenKvsIsNotInitialized() {
    KeyValueService mockKvs = mock(KeyValueService.class);
    ScrubberStore mockStore = mock(ScrubberStore.class);
    when(mockKvs.isInitialized()).thenReturn(false);
    when(mockStore.isInitialized()).thenReturn(true);
    Scrubber theScrubber = getScrubber(mockKvs, mockStore, transactions);
    assertFalse(theScrubber.isInitialized());
}
Also used : InMemoryKeyValueService(com.palantir.atlasdb.keyvalue.impl.InMemoryKeyValueService) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) Test(org.junit.Test)

Example 7 with KeyValueService

use of com.palantir.atlasdb.keyvalue.api.KeyValueService in project atlasdb by palantir.

the class ScrubberTest method isInitializedWhenPrerequisitesAreInitialized.

@Test
public void isInitializedWhenPrerequisitesAreInitialized() {
    KeyValueService mockKvs = mock(KeyValueService.class);
    ScrubberStore mockStore = mock(ScrubberStore.class);
    when(mockKvs.isInitialized()).thenReturn(true);
    when(mockStore.isInitialized()).thenReturn(true);
    Scrubber theScrubber = getScrubber(mockKvs, mockStore, transactions);
    assertTrue(theScrubber.isInitialized());
}
Also used : InMemoryKeyValueService(com.palantir.atlasdb.keyvalue.impl.InMemoryKeyValueService) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) Test(org.junit.Test)

Example 8 with KeyValueService

use of com.palantir.atlasdb.keyvalue.api.KeyValueService in project atlasdb by palantir.

the class SchemaMetadataServiceImplTest method canInitializeAsynchronously.

@Test
public void canInitializeAsynchronously() {
    ForwardingKeyValueService forwardingKeyValueService = new ForwardingKeyValueService() {

        private KeyValueService realKeyValueService = new InMemoryKeyValueService(true);

        private boolean fail = true;

        @Override
        protected KeyValueService delegate() {
            if (fail) {
                fail = false;
                return mock(KeyValueService.class, (Answer) invocation -> {
                    throw new RuntimeException("I am unhappy");
                });
            }
            return realKeyValueService;
        }
    };
    SchemaMetadataService metadataService = SchemaMetadataServiceImpl.create(forwardingKeyValueService, true);
    assertThatThrownBy(() -> metadataService.putSchemaMetadata(SCHEMA_NAME_ONE, SCHEMA_METADATA_ONE)).isInstanceOf(NotInitializedException.class);
    Awaitility.await().atMost(30, TimeUnit.SECONDS).pollInterval(1, TimeUnit.SECONDS).until(metadataService::isInitialized);
    metadataService.putSchemaMetadata(SCHEMA_NAME_ONE, SCHEMA_METADATA_ONE);
    assertThat(metadataService.loadSchemaMetadata(SCHEMA_NAME_ONE)).contains(SCHEMA_METADATA_ONE);
}
Also used : IntStream(java.util.stream.IntStream) NotInitializedException(com.palantir.exception.NotInitializedException) Namespace(com.palantir.atlasdb.keyvalue.api.Namespace) ImmutableMap(com.google.common.collect.ImmutableMap) SchemaMetadataService(com.palantir.atlasdb.schema.metadata.SchemaMetadataService) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) InMemoryKeyValueService(com.palantir.atlasdb.keyvalue.impl.InMemoryKeyValueService) TimeUnit(java.util.concurrent.TimeUnit) Answer(org.mockito.stubbing.Answer) ImmutableSchemaDependentTableMetadata(com.palantir.atlasdb.schema.ImmutableSchemaDependentTableMetadata) ImmutableStreamStoreCleanupMetadata(com.palantir.atlasdb.schema.cleanup.ImmutableStreamStoreCleanupMetadata) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ValueType(com.palantir.atlasdb.table.description.ValueType) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) ImmutableSchemaMetadata(com.palantir.atlasdb.schema.ImmutableSchemaMetadata) Map(java.util.Map) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) ForwardingKeyValueService(com.palantir.atlasdb.keyvalue.impl.ForwardingKeyValueService) SchemaMetadataServiceImpl(com.palantir.atlasdb.schema.metadata.SchemaMetadataServiceImpl) Awaitility(org.awaitility.Awaitility) Mockito.mock(org.mockito.Mockito.mock) SchemaMetadata(com.palantir.atlasdb.schema.SchemaMetadata) NullCleanupMetadata(com.palantir.atlasdb.schema.cleanup.NullCleanupMetadata) SchemaMetadataService(com.palantir.atlasdb.schema.metadata.SchemaMetadataService) InMemoryKeyValueService(com.palantir.atlasdb.keyvalue.impl.InMemoryKeyValueService) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) ForwardingKeyValueService(com.palantir.atlasdb.keyvalue.impl.ForwardingKeyValueService) InMemoryKeyValueService(com.palantir.atlasdb.keyvalue.impl.InMemoryKeyValueService) ForwardingKeyValueService(com.palantir.atlasdb.keyvalue.impl.ForwardingKeyValueService) Test(org.junit.Test)

Example 9 with KeyValueService

use of com.palantir.atlasdb.keyvalue.api.KeyValueService 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)

Example 10 with KeyValueService

use of com.palantir.atlasdb.keyvalue.api.KeyValueService in project atlasdb by palantir.

the class TransactionManagers method serializableInternal.

private SerializableTransactionManager serializableInternal(@Output List<AutoCloseable> closeables) {
    AtlasDbMetrics.setMetricRegistries(globalMetricsRegistry(), globalTaggedMetricRegistry());
    final AtlasDbConfig config = config();
    checkInstallConfig(config);
    AtlasDbRuntimeConfig defaultRuntime = AtlasDbRuntimeConfig.defaultRuntimeConfig();
    Supplier<AtlasDbRuntimeConfig> runtimeConfigSupplier = () -> runtimeConfigSupplier().get().orElse(defaultRuntime);
    QosClient qosClient = initializeCloseable(() -> getQosClient(JavaSuppliers.compose(AtlasDbRuntimeConfig::qos, runtimeConfigSupplier)), closeables);
    ServiceDiscoveringAtlasSupplier atlasFactory = new ServiceDiscoveringAtlasSupplier(config.keyValueService(), JavaSuppliers.compose(AtlasDbRuntimeConfig::keyValueService, runtimeConfigSupplier), config.leader(), config.namespace(), config.initializeAsync(), qosClient);
    LockRequest.setDefaultLockTimeout(SimpleTimeDuration.of(config.getDefaultLockTimeoutSeconds(), TimeUnit.SECONDS));
    LockAndTimestampServices lockAndTimestampServices = createLockAndTimestampServices(config, runtimeConfigSupplier, registrar(), () -> LockServiceImpl.create(lockServerOptions()), atlasFactory::getTimestampService, atlasFactory.getTimestampStoreInvalidator(), userAgent());
    KvsProfilingLogger.setSlowLogThresholdMillis(config.getKvsSlowLogThresholdMillis());
    Supplier<SweepConfig> sweepConfig = JavaSuppliers.compose(AtlasDbRuntimeConfig::sweep, runtimeConfigSupplier);
    KeyValueService keyValueService = initializeCloseable(() -> {
        KeyValueService kvs = atlasFactory.getKeyValueService();
        kvs = ProfilingKeyValueService.create(kvs);
        kvs = SweepStatsKeyValueService.create(kvs, new TimelockTimestampServiceAdapter(lockAndTimestampServices.timelock()), JavaSuppliers.compose(SweepConfig::writeThreshold, sweepConfig), JavaSuppliers.compose(SweepConfig::writeSizeThreshold, sweepConfig));
        kvs = TracingKeyValueService.create(kvs);
        kvs = AtlasDbMetrics.instrument(KeyValueService.class, kvs, MetricRegistry.name(KeyValueService.class));
        return ValidatingQueryRewritingKeyValueService.create(kvs);
    }, closeables);
    SchemaMetadataService schemaMetadataService = SchemaMetadataServiceImpl.create(keyValueService, config.initializeAsync());
    TransactionManagersInitializer initializer = TransactionManagersInitializer.createInitialTables(keyValueService, schemas(), schemaMetadataService, config.initializeAsync());
    PersistentLockService persistentLockService = createAndRegisterPersistentLockService(keyValueService, registrar(), config.initializeAsync());
    TransactionService transactionService = AtlasDbMetrics.instrument(TransactionService.class, TransactionServices.createTransactionService(keyValueService));
    ConflictDetectionManager conflictManager = ConflictDetectionManagers.create(keyValueService);
    SweepStrategyManager sweepStrategyManager = SweepStrategyManagers.createDefault(keyValueService);
    CleanupFollower follower = CleanupFollower.create(schemas());
    Cleaner cleaner = initializeCloseable(() -> new DefaultCleanerBuilder(keyValueService, lockAndTimestampServices.timelock(), ImmutableList.of(follower), transactionService).setBackgroundScrubAggressively(config.backgroundScrubAggressively()).setBackgroundScrubBatchSize(config.getBackgroundScrubBatchSize()).setBackgroundScrubFrequencyMillis(config.getBackgroundScrubFrequencyMillis()).setBackgroundScrubThreads(config.getBackgroundScrubThreads()).setPunchIntervalMillis(config.getPunchIntervalMillis()).setTransactionReadTimeout(config.getTransactionReadTimeoutMillis()).setInitializeAsync(config.initializeAsync()).buildCleaner(), closeables);
    SerializableTransactionManager transactionManager = initializeCloseable(() -> SerializableTransactionManager.create(keyValueService, lockAndTimestampServices.timelock(), lockAndTimestampServices.lock(), transactionService, Suppliers.ofInstance(AtlasDbConstraintCheckingMode.FULL_CONSTRAINT_CHECKING_THROWS_EXCEPTIONS), conflictManager, sweepStrategyManager, cleaner, () -> areTransactionManagerInitializationPrerequisitesSatisfied(initializer, lockAndTimestampServices), allowHiddenTableAccess(), () -> runtimeConfigSupplier.get().transaction().getLockAcquireTimeoutMillis(), config.keyValueService().concurrentGetRangesThreadPoolSize(), config.keyValueService().defaultGetRangesConcurrency(), config.initializeAsync(), () -> runtimeConfigSupplier.get().getTimestampCacheSize(), MultiTableSweepQueueWriter.NO_OP, wrapInitializationCallbackAndAddConsistencyChecks(config, runtimeConfigSupplier.get(), lockAndTimestampServices, asyncInitializationCallback())), closeables);
    PersistentLockManager persistentLockManager = initializeCloseable(() -> new PersistentLockManager(persistentLockService, config.getSweepPersistentLockWaitMillis()), closeables);
    initializeCloseable(() -> initializeSweepEndpointAndBackgroundProcess(config, runtimeConfigSupplier, registrar(), keyValueService, transactionService, sweepStrategyManager, follower, transactionManager, persistentLockManager), closeables);
    initializeCloseable(initializeCompactBackgroundProcess(lockAndTimestampServices, keyValueService, transactionManager, JavaSuppliers.compose(AtlasDbRuntimeConfig::compact, runtimeConfigSupplier)), closeables);
    return transactionManager;
}
Also used : SweepStrategyManager(com.palantir.atlasdb.transaction.impl.SweepStrategyManager) SweepStatsKeyValueService(com.palantir.atlasdb.keyvalue.impl.SweepStatsKeyValueService) ValidatingQueryRewritingKeyValueService(com.palantir.atlasdb.keyvalue.impl.ValidatingQueryRewritingKeyValueService) ProfilingKeyValueService(com.palantir.atlasdb.keyvalue.impl.ProfilingKeyValueService) TracingKeyValueService(com.palantir.atlasdb.keyvalue.impl.TracingKeyValueService) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) TimelockTimestampServiceAdapter(com.palantir.atlasdb.transaction.impl.TimelockTimestampServiceAdapter) TransactionService(com.palantir.atlasdb.transaction.service.TransactionService) PersistentLockManager(com.palantir.atlasdb.sweep.PersistentLockManager) SerializableTransactionManager(com.palantir.atlasdb.transaction.impl.SerializableTransactionManager) ImmutableAtlasDbConfig(com.palantir.atlasdb.config.ImmutableAtlasDbConfig) InMemoryAtlasDbConfig(com.palantir.atlasdb.memory.InMemoryAtlasDbConfig) AtlasDbConfig(com.palantir.atlasdb.config.AtlasDbConfig) QosClient(com.palantir.atlasdb.qos.QosClient) AtlasDbQosClient(com.palantir.atlasdb.qos.client.AtlasDbQosClient) SweepConfig(com.palantir.atlasdb.config.SweepConfig) SchemaMetadataService(com.palantir.atlasdb.schema.metadata.SchemaMetadataService) NoOpPersistentLockService(com.palantir.atlasdb.persistentlock.NoOpPersistentLockService) KvsBackedPersistentLockService(com.palantir.atlasdb.persistentlock.KvsBackedPersistentLockService) PersistentLockService(com.palantir.atlasdb.persistentlock.PersistentLockService) DefaultCleanerBuilder(com.palantir.atlasdb.cleaner.DefaultCleanerBuilder) ConflictDetectionManager(com.palantir.atlasdb.transaction.impl.ConflictDetectionManager) AtlasDbRuntimeConfig(com.palantir.atlasdb.config.AtlasDbRuntimeConfig) CleanupFollower(com.palantir.atlasdb.cleaner.CleanupFollower) Cleaner(com.palantir.atlasdb.cleaner.Cleaner)

Aggregations

KeyValueService (com.palantir.atlasdb.keyvalue.api.KeyValueService)30 Test (org.junit.Test)16 InMemoryKeyValueService (com.palantir.atlasdb.keyvalue.impl.InMemoryKeyValueService)12 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)7 SerializableTransactionManager (com.palantir.atlasdb.transaction.impl.SerializableTransactionManager)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 Cell (com.palantir.atlasdb.keyvalue.api.Cell)5 TrackingKeyValueService (com.palantir.atlasdb.keyvalue.impl.TrackingKeyValueService)5 TimestampService (com.palantir.timestamp.TimestampService)5 Map (java.util.Map)5 SingleBackendCliTestRunner (com.palantir.atlasdb.cli.runner.SingleBackendCliTestRunner)4 ForwardingKeyValueService (com.palantir.atlasdb.keyvalue.impl.ForwardingKeyValueService)4 TracingKeyValueService (com.palantir.atlasdb.keyvalue.impl.TracingKeyValueService)4 DaggerTestAtlasDbServices (com.palantir.atlasdb.services.test.DaggerTestAtlasDbServices)4 TestAtlasDbServices (com.palantir.atlasdb.services.test.TestAtlasDbServices)4 Before (org.junit.Before)4 RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)3 LockService (com.palantir.lock.LockService)3 LegacyTimelockService (com.palantir.lock.impl.LegacyTimelockService)3 IdentityHashMap (java.util.IdentityHashMap)3