use of com.palantir.atlasdb.keyvalue.api.RangeRequest in project atlasdb by palantir.
the class SerializableTransaction method verifyRanges.
private void verifyRanges(Transaction readOnlyTransaction) {
// verify each set of reads to ensure they are the same.
for (Entry<TableReference, ConcurrentMap<RangeRequest, byte[]>> tableAndRange : rangeEndByTable.entrySet()) {
TableReference table = tableAndRange.getKey();
Map<RangeRequest, byte[]> rangeEnds = tableAndRange.getValue();
for (Entry<RangeRequest, byte[]> rangeAndRangeEndEntry : rangeEnds.entrySet()) {
RangeRequest range = rangeAndRangeEndEntry.getKey();
byte[] rangeEnd = rangeAndRangeEndEntry.getValue();
if (rangeEnd.length != 0 && !RangeRequests.isTerminalRow(range.isReverse(), rangeEnd)) {
range = range.getBuilder().endRowExclusive(RangeRequests.getNextStartRow(range.isReverse(), rangeEnd)).build();
}
ConcurrentNavigableMap<Cell, byte[]> writes = writesByTable.get(table);
BatchingVisitableView<RowResult<byte[]>> bv = BatchingVisitableView.of(readOnlyTransaction.getRange(table, range));
NavigableMap<Cell, ByteBuffer> readsInRange = Maps.transformValues(getReadsInRange(table, range), ByteBuffer::wrap);
if (!bv.transformBatch(input -> filterWritesFromRows(input, writes)).isEqual(readsInRange.entrySet())) {
handleTransactionConflict(table);
}
}
}
}
use of com.palantir.atlasdb.keyvalue.api.RangeRequest in project atlasdb by palantir.
the class RangeVisitor method visitRange.
private void visitRange(Visitor visitor, MutableRange range) {
do {
final RangeRequest request = range.getRangeRequest();
try {
long startTime = System.currentTimeMillis();
long numVisited = txManager.runTaskWithLocksWithRetry(lockTokens, Suppliers.ofInstance(null), new LockAwareTransactionTask<Long, RuntimeException>() {
@Override
public Long execute(Transaction tx, Iterable<HeldLocksToken> heldLocks) {
return visitInternal(tx, visitor, request, range);
}
@Override
public String toString() {
return "visitRange(" + request + ")";
}
});
counter.addAndGet(numVisited);
log.info("Visited {} rows from {} in {} ms.", numVisited, tableRef.getQualifiedName(), System.currentTimeMillis() - startTime);
} catch (InterruptedException e) {
throw Throwables.rewrapAndThrowUncheckedException(e);
}
} while (!range.isComplete());
}
use of com.palantir.atlasdb.keyvalue.api.RangeRequest in project atlasdb by palantir.
the class KvsGetRangeBenchmarks method getSingleRangeInner.
private Object getSingleRangeInner(ConsecutiveNarrowTable table, int sliceSize) {
RangeRequest request = Iterables.getOnlyElement(table.getRangeRequests(1, sliceSize, false));
int startRow = Ints.fromByteArray(request.getStartInclusive());
ClosableIterator<RowResult<Value>> result = table.getKvs().getRange(table.getTableRef(), request, Long.MAX_VALUE);
ArrayList<RowResult<Value>> list = Lists.newArrayList(result);
result.close();
Preconditions.checkState(list.size() == sliceSize, "List size %s != %s", sliceSize, list.size());
list.forEach(rowResult -> {
byte[] rowName = rowResult.getRowName();
int rowNumber = Ints.fromByteArray(rowName);
Preconditions.checkState(rowNumber - startRow < sliceSize, "Start Row %s, row number %s, sliceSize %s", startRow, rowNumber, sliceSize);
});
return result;
}
use of com.palantir.atlasdb.keyvalue.api.RangeRequest in project atlasdb by palantir.
the class JdbcKeyValueService method getRangeOfTimestamps.
@Override
public ClosableIterator<RowResult<Set<Long>>> getRangeOfTimestamps(final TableReference tableRef, final RangeRequest rangeRequest, final long timestamp) {
Iterable<RowResult<Set<Long>>> iter = new AbstractPagingIterable<RowResult<Set<Long>>, TokenBackedBasicResultsPage<RowResult<Set<Long>>, byte[]>>() {
@Override
protected TokenBackedBasicResultsPage<RowResult<Set<Long>>, byte[]> getFirstPage() {
return getPageWithTimestamps(tableRef, rangeRequest, timestamp);
}
@Override
protected TokenBackedBasicResultsPage<RowResult<Set<Long>>, byte[]> getNextPage(TokenBackedBasicResultsPage<RowResult<Set<Long>>, byte[]> previous) {
byte[] startRow = previous.getTokenForNextPage();
RangeRequest newRange = rangeRequest.getBuilder().startRowInclusive(startRow).build();
return getPageWithTimestamps(tableRef, newRange, timestamp);
}
};
return ClosableIterators.wrap(iter.iterator());
}
use of com.palantir.atlasdb.keyvalue.api.RangeRequest in project atlasdb by palantir.
the class AbstractKeyValueServiceTest method testGetRange.
public void testGetRange(boolean reverseSupported) {
putTestDataForSingleTimestamp();
// Unbounded
final RangeRequest all = RangeRequest.all();
assertRangeSizeAndOrdering(keyValueService.getRange(TEST_TABLE, all, TEST_TIMESTAMP + 1), 3, all);
if (reverseSupported) {
final RangeRequest allReverse = RangeRequest.reverseBuilder().build();
assertRangeSizeAndOrdering(keyValueService.getRange(TEST_TABLE, allReverse, TEST_TIMESTAMP + 1), 3, allReverse);
}
// Upbounded
final RangeRequest upbounded = RangeRequest.builder().endRowExclusive(row2).build();
assertRangeSizeAndOrdering(keyValueService.getRange(TEST_TABLE, upbounded, TEST_TIMESTAMP + 1), 2, upbounded);
if (reverseSupported) {
final RangeRequest upboundedReverse = RangeRequest.reverseBuilder().endRowExclusive(row0).build();
assertRangeSizeAndOrdering(keyValueService.getRange(TEST_TABLE, upboundedReverse, TEST_TIMESTAMP + 1), 2, upboundedReverse);
}
// Downbounded
final RangeRequest downbounded = RangeRequest.builder().startRowInclusive(row1).build();
assertRangeSizeAndOrdering(keyValueService.getRange(TEST_TABLE, downbounded, TEST_TIMESTAMP + 1), 2, downbounded);
if (reverseSupported) {
final RangeRequest downboundedReverse = RangeRequest.reverseBuilder().startRowInclusive(row1).build();
assertRangeSizeAndOrdering(keyValueService.getRange(TEST_TABLE, downboundedReverse, TEST_TIMESTAMP + 1), 2, downboundedReverse);
}
// Both-bounded
final RangeRequest bothbounded = RangeRequest.builder().startRowInclusive(row1).endRowExclusive(row2).build();
assertRangeSizeAndOrdering(keyValueService.getRange(TEST_TABLE, bothbounded, TEST_TIMESTAMP + 1), 1, bothbounded);
if (reverseSupported) {
final RangeRequest bothboundedReverse = RangeRequest.reverseBuilder().startRowInclusive(row2).endRowExclusive(row1).build();
assertRangeSizeAndOrdering(keyValueService.getRange(TEST_TABLE, bothboundedReverse, TEST_TIMESTAMP + 1), 1, bothboundedReverse);
}
// Precise test for lower-bounded
RangeRequest rangeRequest = downbounded;
ClosableIterator<RowResult<Value>> rangeResult = keyValueService.getRange(TEST_TABLE, rangeRequest, TEST_TIMESTAMP + 1);
assertFalse(keyValueService.getRange(TEST_TABLE, rangeRequest, TEST_TIMESTAMP).hasNext());
assertTrue(rangeResult.hasNext());
assertEquals(RowResult.create(row1, ImmutableSortedMap.orderedBy(UnsignedBytes.lexicographicalComparator()).put(column0, Value.create(value10, TEST_TIMESTAMP)).put(column2, Value.create(value12, TEST_TIMESTAMP)).build()), rangeResult.next());
assertTrue(rangeResult.hasNext());
assertEquals(RowResult.create(row2, ImmutableSortedMap.orderedBy(UnsignedBytes.lexicographicalComparator()).put(column1, Value.create(value21, TEST_TIMESTAMP)).put(column2, Value.create(value22, TEST_TIMESTAMP)).build()), rangeResult.next());
rangeResult.close();
}
Aggregations