use of com.palantir.atlasdb.keyvalue.api.RangeRequest in project atlasdb by palantir.
the class AbstractTransactionTest method testRangePagingBatchSizeOne.
@Test
public void testRangePagingBatchSizeOne() {
int totalPuts = 100;
for (int i = 0; i < totalPuts; i++) {
putDirect("row" + i, "col1", "v1", 0);
}
RangeRequest rangeRequest = RangeRequest.builder().batchHint(1).build();
Map<RangeRequest, TokenBackedBasicResultsPage<RowResult<Value>, byte[]>> ranges = keyValueService.getFirstBatchForRanges(TEST_TABLE, Iterables.limit(Iterables.cycle(rangeRequest), 100), 1);
assertEquals(1, ranges.keySet().size());
assertEquals(1, ranges.values().iterator().next().getResults().size());
assertEquals("row0", PtBytes.toString(ranges.values().iterator().next().getResults().iterator().next().getRowName()));
}
use of com.palantir.atlasdb.keyvalue.api.RangeRequest in project atlasdb by palantir.
the class RangeRequestTest method testEmpty.
@Test
public void testEmpty() {
RangeRequest request = RangeRequest.builder().endRowExclusive(RangeRequests.getFirstRowName()).build();
Assert.assertTrue(request.isEmptyRange());
request = RangeRequest.reverseBuilder().endRowExclusive(RangeRequests.getLastRowName()).build();
Assert.assertTrue(request.isEmptyRange());
}
use of com.palantir.atlasdb.keyvalue.api.RangeRequest 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.RangeRequest 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.RangeRequest in project atlasdb by palantir.
the class TransactionRangeMigrator method copyOneTransactionInternal.
private byte[] copyOneTransactionInternal(RangeRequest range, long rangeId, Transaction readT, Transaction writeT) {
final long maxBytes = TransactionConstants.WARN_LEVEL_FOR_QUEUED_BYTES / 2;
byte[] start = getCheckpoint(rangeId, writeT);
if (start == null) {
return null;
}
RangeRequest.Builder builder = range.getBuilder().startRowInclusive(start);
if (builder.isInvalidRange()) {
return null;
}
RangeRequest rangeToUse = builder.build();
BatchingVisitable<RowResult<byte[]>> bv = readT.getRange(srcTable, rangeToUse);
byte[] lastRow = internalCopyRange(bv, maxBytes, writeT);
byte[] nextRow = getNextRowName(lastRow);
checkpointer.checkpoint(srcTable.getQualifiedName(), rangeId, nextRow, writeT);
return lastRow;
}
Aggregations