use of com.palantir.atlasdb.keyvalue.api.RowResult in project atlasdb by palantir.
the class ScrubQueueMigrationCommand method run.
public static void run(KeyValueService kvs, PrintWriter output, int batchSize) {
Context context = new Context(kvs, output, batchSize);
// top version of each cell until the entire queue is drained.
for (int i = 0; ; i++) {
output.println("Starting iteration " + i + " of scrub migration.");
Stopwatch watch = Stopwatch.createStarted();
try (ClosableIterator<RowResult<Value>> iter = kvs.getRange(AtlasDbConstants.OLD_SCRUB_TABLE, RangeRequest.all(), Long.MAX_VALUE)) {
if (!iter.hasNext()) {
output.println("Finished all iterations of scrub migration.");
break;
}
runOnce(context, iter);
}
output.println("Finished iteration " + i + " of scrub migration in " + watch.elapsed(TimeUnit.SECONDS) + " seconds.");
}
}
use of com.palantir.atlasdb.keyvalue.api.RowResult in project atlasdb by palantir.
the class JdbcKeyValueService method getRange.
@Override
public ClosableIterator<RowResult<Value>> getRange(final TableReference tableRef, final RangeRequest rangeRequest, final long timestamp) {
Iterable<RowResult<Value>> iter = new AbstractPagingIterable<RowResult<Value>, TokenBackedBasicResultsPage<RowResult<Value>, byte[]>>() {
@Override
protected TokenBackedBasicResultsPage<RowResult<Value>, byte[]> getFirstPage() {
return getPageWithValues(tableRef, rangeRequest, timestamp);
}
@Override
protected TokenBackedBasicResultsPage<RowResult<Value>, byte[]> getNextPage(TokenBackedBasicResultsPage<RowResult<Value>, byte[]> previous) {
byte[] startRow = previous.getTokenForNextPage();
RangeRequest newRange = rangeRequest.getBuilder().startRowInclusive(startRow).build();
return getPageWithValues(tableRef, newRange, timestamp);
}
};
return ClosableIterators.wrap(iter.iterator());
}
use of com.palantir.atlasdb.keyvalue.api.RowResult 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.RowResult in project atlasdb by palantir.
the class SchemaApiTestV2Table method getColumn2.
/**
* Returns a mapping from the specified row keys to their value at column Column2.
* As the Column2 values are all loaded in memory, do not use for large amounts of data.
* If the column does not exist for a key, the entry will be omitted from the map.
*/
public Map<String, StringValue> getColumn2(Iterable<String> rowKeys) {
ColumnSelection colSelection = ColumnSelection.create(ImmutableList.of(PtBytes.toCachedBytes("d")));
List<SchemaApiTestTable.SchemaApiTestRow> rows = Lists.newArrayList(rowKeys).stream().map(SchemaApiTestTable.SchemaApiTestRow::of).collect(Collectors.toList());
SortedMap<byte[], RowResult<byte[]>> results = t.getRows(tableRef, Persistables.persistAll(rows), colSelection);
return results.values().stream().map(entry -> SchemaApiTestTable.SchemaApiTestRowResult.of(entry)).collect(Collectors.toMap(entry -> entry.getRowName().getComponent1(), SchemaApiTestTable.SchemaApiTestRowResult::getColumn2));
}
use of com.palantir.atlasdb.keyvalue.api.RowResult in project atlasdb by palantir.
the class SchemaApiTestV2Table method getColumn1.
/**
* Returns a mapping from the specified row keys to their value at column Column1.
* As the Column1 values are all loaded in memory, do not use for large amounts of data.
* If the column does not exist for a key, the entry will be omitted from the map.
*/
public Map<String, Long> getColumn1(Iterable<String> rowKeys) {
ColumnSelection colSelection = ColumnSelection.create(ImmutableList.of(PtBytes.toCachedBytes("c")));
List<SchemaApiTestTable.SchemaApiTestRow> rows = Lists.newArrayList(rowKeys).stream().map(SchemaApiTestTable.SchemaApiTestRow::of).collect(Collectors.toList());
SortedMap<byte[], RowResult<byte[]>> results = t.getRows(tableRef, Persistables.persistAll(rows), colSelection);
return results.values().stream().map(entry -> SchemaApiTestTable.SchemaApiTestRowResult.of(entry)).collect(Collectors.toMap(entry -> entry.getRowName().getComponent1(), SchemaApiTestTable.SchemaApiTestRowResult::getColumn1));
}
Aggregations