Search in sources :

Example 1 with KeyValueService

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

the class DbkvsPostgresKeyValueServiceTest method getKeyValueService.

@Override
protected KeyValueService getKeyValueService() {
    KeyValueService kvs = ConnectionManagerAwareDbKvs.create(DbkvsPostgresTestSuite.getKvsConfig());
    kvs.getAllTableNames().stream().filter(table -> !table.getQualifiedName().equals("_metadata")).forEach(kvs::dropTable);
    return kvs;
}
Also used : PostgresDdlTable(com.palantir.atlasdb.keyvalue.dbkvs.impl.postgres.PostgresDdlTable) Namespace(com.palantir.atlasdb.keyvalue.api.Namespace) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Test(org.junit.Test) ConnectionManagerAwareDbKvs(com.palantir.atlasdb.keyvalue.dbkvs.impl.ConnectionManagerAwareDbKvs) StringUtils(org.apache.commons.lang3.StringUtils) AtlasDbConstants(com.palantir.atlasdb.AtlasDbConstants) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService)

Example 2 with KeyValueService

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

the class TableSplittingKeyValueService method dropTables.

@Override
public void dropTables(Set<TableReference> tableRefs) {
    Map<KeyValueService, Set<TableReference>> tablesByKvs = Maps.newHashMap();
    for (TableReference tableRef : tableRefs) {
        KeyValueService delegate = getDelegate(tableRef);
        if (tablesByKvs.containsKey(delegate)) {
            tablesByKvs.get(delegate).add(tableRef);
        } else {
            Set<TableReference> tablesBelongingToThisDelegate = Sets.newHashSet(tableRef);
            tablesByKvs.put(delegate, tablesBelongingToThisDelegate);
        }
    }
    for (Entry<KeyValueService, Set<TableReference>> kvsEntry : tablesByKvs.entrySet()) {
        kvsEntry.getKey().dropTables(kvsEntry.getValue());
    }
}
Also used : KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Set(java.util.Set)

Example 3 with KeyValueService

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

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

the class SweepProgressStoreTest method setup.

@Before
public void setup() {
    exec = PTExecutors.newCachedThreadPool();
    KeyValueService kvs = new InMemoryKeyValueService(false, exec);
    txManager = SweepTestUtils.setupTxManager(kvs);
    progressStore = SweepProgressStoreImpl.create(kvs, false);
}
Also used : InMemoryKeyValueService(com.palantir.atlasdb.keyvalue.impl.InMemoryKeyValueService) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) InMemoryKeyValueService(com.palantir.atlasdb.keyvalue.impl.InMemoryKeyValueService) Before(org.junit.Before)

Example 5 with KeyValueService

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

the class ReadPunchTableCommand method execute.

@Override
public int execute(AtlasDbServices services) {
    if (epochTime == null) {
        throw new IllegalArgumentException("Required option '-e' is missing");
    }
    if (epochTime < 0) {
        throw new IllegalArgumentException("Option '-e' should be a positive long, as epoch time" + " is never negative.");
    }
    Instant epochTimeInstant = Instant.ofEpochSecond(epochTime);
    ZonedDateTime date = ZonedDateTime.ofInstant(epochTimeInstant, ZoneId.systemDefault());
    printer.info("Input {} in epoch millis is {}", SafeArg.of("epochMillis", epochTime), SafeArg.of("date", date.toString()));
    KeyValueService keyValueService = services.getKeyValueService();
    PuncherStore puncherStore = KeyValueServicePuncherStore.create(keyValueService, false);
    Long value = puncherStore.get(epochTime);
    printer.info("The first timestamp before {} is {}", SafeArg.of("date", date.toString()), SafeArg.of("timestamp", value));
    return 0;
}
Also used : KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) ZonedDateTime(java.time.ZonedDateTime) Instant(java.time.Instant) KeyValueServicePuncherStore(com.palantir.atlasdb.cleaner.KeyValueServicePuncherStore) PuncherStore(com.palantir.atlasdb.cleaner.PuncherStore)

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