Search in sources :

Example 46 with Value

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

the class TransactionKvsWrapper method get.

public Long get(Long startTimestamp) {
    Cell cell = getTransactionCell(startTimestamp);
    Map<Cell, Value> returnMap = keyValueService.get(TransactionConstants.TRANSACTION_TABLE, ImmutableMap.of(cell, MAX_TIMESTAMP));
    if (returnMap.containsKey(cell)) {
        return TransactionConstants.getTimestampForValue(returnMap.get(cell).getContents());
    } else {
        return null;
    }
}
Also used : Value(com.palantir.atlasdb.keyvalue.api.Value) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Example 47 with Value

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

the class ScrubberTest method testScrubQueueIsCleared.

@Test
public void testScrubQueueIsCleared() {
    Cell cell1 = Cell.create(new byte[] { 1 }, new byte[] { 2 });
    Cell cell2 = Cell.create(new byte[] { 2 }, new byte[] { 3 });
    Cell cell3 = Cell.create(new byte[] { 3 }, new byte[] { 4 });
    TableReference tableRef = TableReference.createFromFullyQualifiedName("foo.bar");
    kvs.createTable(tableRef, new byte[] {});
    kvs.putWithTimestamps(tableRef, ImmutableMultimap.<Cell, Value>builder().put(cell1, Value.create(new byte[] { 3 }, 10)).put(cell1, Value.create(new byte[] { 4 }, 20)).put(cell2, Value.create(new byte[] { 4 }, 30)).put(cell2, Value.create(new byte[] { 5 }, 40)).put(cell2, Value.create(new byte[] { 6 }, 50)).put(cell3, Value.create(new byte[] { 7 }, 60)).build());
    transactions.putUnlessExists(10, 15);
    transactions.putUnlessExists(20, 25);
    transactions.putUnlessExists(30, 35);
    transactions.putUnlessExists(50, 55);
    transactions.putUnlessExists(60, 65);
    scrubStore.queueCellsForScrubbing(ImmutableMultimap.of(cell1, tableRef), 10, 100);
    scrubStore.queueCellsForScrubbing(ImmutableMultimap.of(cell1, tableRef), 20, 100);
    scrubStore.queueCellsForScrubbing(ImmutableMultimap.of(cell2, tableRef), 40, 100);
    scrubStore.queueCellsForScrubbing(ImmutableMultimap.of(cell2, tableRef), 50, 100);
    scrubStore.queueCellsForScrubbing(ImmutableMultimap.of(cell3, tableRef), 60, 100);
    scrubber.runBackgroundScrubTask(null);
    List<SortedMap<Long, Multimap<TableReference, Cell>>> scrubQueue = BatchingVisitables.copyToList(scrubStore.getBatchingVisitableScrubQueue(Long.MAX_VALUE, null, null));
    Assert.assertEquals(ImmutableList.of(), scrubQueue);
}
Also used : TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) SortedMap(java.util.SortedMap) Value(com.palantir.atlasdb.keyvalue.api.Value) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Test(org.junit.Test)

Example 48 with Value

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

the class LockEntryTest method fromRowResultProducesLockEntry.

@Test
public void fromRowResultProducesLockEntry() {
    KeyValueService kvs = new InMemoryKeyValueService(false);
    kvs.createTable(TEST_TABLE, AtlasDbConstants.GENERIC_TABLE_METADATA);
    kvs.checkAndSet(CheckAndSetRequest.newCell(TEST_TABLE, LOCK_ENTRY.cell(), LOCK_ENTRY.value()));
    Iterator<RowResult<Value>> range = kvs.getRange(TEST_TABLE, RangeRequest.all(), AtlasDbConstants.TRANSACTION_TS + 1);
    RowResult<Value> onlyEntry = Iterables.getOnlyElement(ImmutableSet.copyOf(range));
    LockEntry lockEntry = LockEntry.fromRowResult(onlyEntry);
    assertEquals(LOCK_ENTRY, lockEntry);
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) InMemoryKeyValueService(com.palantir.atlasdb.keyvalue.impl.InMemoryKeyValueService) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) InMemoryKeyValueService(com.palantir.atlasdb.keyvalue.impl.InMemoryKeyValueService) Value(com.palantir.atlasdb.keyvalue.api.Value) Test(org.junit.Test)

Example 49 with Value

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

the class SimpleTransactionService method get.

@Override
public Map<Long, Long> get(Iterable<Long> startTimestamps) {
    Map<Cell, Long> startTsMap = Maps.newHashMap();
    for (Long startTimestamp : startTimestamps) {
        Cell cell = getTransactionCell(startTimestamp);
        startTsMap.put(cell, MAX_TIMESTAMP);
    }
    Map<Cell, Value> rawResults = keyValueService.get(TransactionConstants.TRANSACTION_TABLE, startTsMap);
    Map<Long, Long> result = Maps.newHashMapWithExpectedSize(rawResults.size());
    for (Map.Entry<Cell, Value> e : rawResults.entrySet()) {
        long startTs = TransactionConstants.getTimestampForValue(e.getKey().getRowName());
        long commitTs = TransactionConstants.getTimestampForValue(e.getValue().getContents());
        result.put(startTs, commitTs);
    }
    return result;
}
Also used : Value(com.palantir.atlasdb.keyvalue.api.Value) Cell(com.palantir.atlasdb.keyvalue.api.Cell) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Example 50 with Value

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

the class JdbcKeyValueService method breakUpValuesByRow.

private static NavigableMap<byte[], SortedMap<byte[], Value>> breakUpValuesByRow(Result<? extends Record> records) {
    NavigableMap<byte[], SortedMap<byte[], Value>> ret = Maps.newTreeMap(UnsignedBytes.lexicographicalComparator());
    for (Record record : records) {
        byte[] row = record.getValue(A_ROW_NAME);
        SortedMap<byte[], Value> colMap = ret.computeIfAbsent(row, rowName -> Maps.newTreeMap(UnsignedBytes.lexicographicalComparator()));
        colMap.put(record.getValue(A_COL_NAME), Value.create(record.getValue(A_VALUE), record.getValue(A_TIMESTAMP)));
    }
    return ret;
}
Also used : SortedMap(java.util.SortedMap) Value(com.palantir.atlasdb.keyvalue.api.Value) Record(org.jooq.Record)

Aggregations

Value (com.palantir.atlasdb.keyvalue.api.Value)74 Cell (com.palantir.atlasdb.keyvalue.api.Cell)55 RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)20 RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)18 Test (org.junit.Test)18 Entry (java.util.Map.Entry)16 TokenBackedBasicResultsPage (com.palantir.util.paging.TokenBackedBasicResultsPage)15 Map (java.util.Map)15 SortedMap (java.util.SortedMap)13 ImmutableMap (com.google.common.collect.ImmutableMap)12 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)10 LinkedHashMap (java.util.LinkedHashMap)9 ImmutableList (com.google.common.collect.ImmutableList)7 KeyAlreadyExistsException (com.palantir.atlasdb.keyvalue.api.KeyAlreadyExistsException)7 InsufficientConsistencyException (com.palantir.atlasdb.keyvalue.api.InsufficientConsistencyException)6 RowColumnRangeIterator (com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator)6 List (java.util.List)6 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)5 BatchColumnRangeSelection (com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection)5 LocalRowColumnRangeIterator (com.palantir.atlasdb.keyvalue.impl.LocalRowColumnRangeIterator)5