Search in sources :

Example 26 with Value

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

the class InMemoryKeyValueService method getColumnRangeForSingleRow.

private RowColumnRangeIterator getColumnRangeForSingleRow(ConcurrentSkipListMap<Key, byte[]> table, byte[] row, ColumnRangeSelection columnRangeSelection, long timestamp) {
    Cell rowBegin;
    if (columnRangeSelection.getStartCol().length > 0) {
        rowBegin = Cell.create(row, columnRangeSelection.getStartCol());
    } else {
        rowBegin = Cells.createSmallestCellForRow(row);
    }
    // Inclusive last cell.
    Cell rowEnd;
    if (columnRangeSelection.getEndCol().length > 0) {
        rowEnd = Cell.create(row, RangeRequests.previousLexicographicName(columnRangeSelection.getEndCol()));
    } else {
        rowEnd = Cells.createLargestCellForRow(row);
    }
    PeekingIterator<Entry<Key, byte[]>> entries = Iterators.peekingIterator(table.subMap(new Key(rowBegin, Long.MIN_VALUE), new Key(rowEnd, timestamp)).entrySet().iterator());
    Map<Cell, Value> rowResults = new LinkedHashMap<>();
    while (entries.hasNext()) {
        Entry<Key, byte[]> entry = entries.peek();
        Key key = entry.getKey();
        Iterator<Entry<Key, byte[]>> cellIter = takeCell(entries, key);
        getLatestVersionOfCell(row, key, cellIter, timestamp, rowResults);
    }
    return new LocalRowColumnRangeIterator(rowResults.entrySet().iterator());
}
Also used : Entry(java.util.Map.Entry) Value(com.palantir.atlasdb.keyvalue.api.Value) Cell(com.palantir.atlasdb.keyvalue.api.Cell) LinkedHashMap(java.util.LinkedHashMap)

Example 27 with Value

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

the class InMemoryKeyValueService method get.

@Override
public Map<Cell, Value> get(TableReference tableRef, Map<Cell, Long> timestampByCell) {
    ConcurrentSkipListMap<Key, byte[]> table = getTableMap(tableRef).entries;
    Map<Cell, Value> result = Maps.newHashMap();
    for (Map.Entry<Cell, Long> e : timestampByCell.entrySet()) {
        Cell cell = e.getKey();
        Entry<Key, byte[]> lastEntry = table.lowerEntry(new Key(cell, e.getValue()));
        if (lastEntry != null) {
            Key key = lastEntry.getKey();
            if (key.matchesCell(cell)) {
                long ts = lastEntry.getKey().ts;
                result.put(cell, Value.createWithCopyOfData(lastEntry.getValue(), ts));
            }
        }
    }
    return result;
}
Also used : Value(com.palantir.atlasdb.keyvalue.api.Value) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Map(java.util.Map) ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap) SortedMap(java.util.SortedMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) LinkedHashMap(java.util.LinkedHashMap) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap)

Example 28 with Value

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

the class GetCandidateCellsForSweepingShim method getCandidateCellsForSweeping.

public ClosableIterator<List<CandidateCellForSweeping>> getCandidateCellsForSweeping(TableReference tableRef, CandidateCellForSweepingRequest request) {
    RangeRequest range = RangeRequest.builder().startRowInclusive(request.startRowInclusive()).batchHint(request.batchSizeHint().orElse(AtlasDbConstants.DEFAULT_SWEEP_CANDIDATE_BATCH_HINT)).build();
    try (ReleasableCloseable<ClosableIterator<RowResult<Value>>> valueResults = new ReleasableCloseable<>(getValues(tableRef, range, request.maxTimestampExclusive(), request.shouldCheckIfLatestValueIsEmpty()));
        ReleasableCloseable<ClosableIterator<RowResult<Set<Long>>>> tsResults = new ReleasableCloseable<>(keyValueService.getRangeOfTimestamps(tableRef, range, request.maxTimestampExclusive()))) {
        PeekingIterator<RowResult<Value>> peekingValues = Iterators.peekingIterator(valueResults.get());
        Iterator<List<RowResult<Set<Long>>>> tsBatches = Iterators.partition(tsResults.get(), range.getBatchHint());
        Iterator<List<CandidateCellForSweeping>> candidates = Iterators.transform(tsBatches, tsBatch -> {
            List<CandidateCellForSweeping> candidateBatch = Lists.newArrayList();
            for (RowResult<Set<Long>> rr : tsBatch) {
                for (Map.Entry<byte[], Set<Long>> e : rr.getColumns().entrySet()) {
                    byte[] colName = e.getKey();
                    List<Long> sortedTimestamps = e.getValue().stream().filter(request::shouldSweep).sorted().collect(Collectors.toList());
                    Cell cell = Cell.create(rr.getRowName(), colName);
                    boolean latestValEmpty = isLatestValueEmpty(cell, peekingValues);
                    candidateBatch.add(ImmutableCandidateCellForSweeping.builder().cell(cell).sortedTimestamps(sortedTimestamps).isLatestValueEmpty(latestValEmpty).build());
                }
            }
            return candidateBatch;
        });
        Closer closer = createCloserAndRelease(valueResults, tsResults);
        return ClosableIterators.wrap(candidates, closer);
    }
}
Also used : Closer(com.google.common.io.Closer) Set(java.util.Set) ClosableIterator(com.palantir.common.base.ClosableIterator) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) CandidateCellForSweeping(com.palantir.atlasdb.keyvalue.api.CandidateCellForSweeping) ImmutableCandidateCellForSweeping(com.palantir.atlasdb.keyvalue.api.ImmutableCandidateCellForSweeping) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Value(com.palantir.atlasdb.keyvalue.api.Value) List(java.util.List) Map(java.util.Map) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Example 29 with Value

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

the class GetCandidateCellsForSweepingShim method isLatestValueEmpty.

private static boolean isLatestValueEmpty(Cell cell, PeekingIterator<RowResult<Value>> values) {
    while (values.hasNext()) {
        RowResult<Value> result = values.peek();
        int comparison = UnsignedBytes.lexicographicalComparator().compare(cell.getRowName(), result.getRowName());
        if (comparison == 0) {
            Value matchingValue = result.getColumns().get(cell.getColumnName());
            return matchingValue != null && matchingValue.getContents().length == 0;
        } else if (comparison < 0) {
            return false;
        } else {
            values.next();
        }
    }
    return false;
}
Also used : Value(com.palantir.atlasdb.keyvalue.api.Value)

Example 30 with Value

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

the class TestSweepCommand method get.

private String get(KeyValueService kvs, TableReference table, String row, long ts) {
    Cell cell = Cell.create(row.getBytes(StandardCharsets.UTF_8), COL.getBytes(StandardCharsets.UTF_8));
    Value val = kvs.get(table, ImmutableMap.of(cell, ts)).get(cell);
    return val == null ? null : new String(val.getContents());
}
Also used : Value(com.palantir.atlasdb.keyvalue.api.Value) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

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