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());
}
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;
}
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);
}
}
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;
}
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());
}
Aggregations