use of com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection in project atlasdb by palantir.
the class TracingKeyValueServiceTest method getRowsColumnRangeBatch.
@Test
public void getRowsColumnRangeBatch() throws Exception {
RowColumnRangeIterator rowColumnIterator = mock(RowColumnRangeIterator.class);
List<byte[]> rows = ImmutableList.of(ROW_NAME);
Map<byte[], RowColumnRangeIterator> expectedResult = ImmutableMap.of(ROW_NAME, rowColumnIterator);
BatchColumnRangeSelection range = BatchColumnRangeSelection.create(COL_NAME, COL_NAME, 2);
when(delegate.getRowsColumnRange(TABLE_REF, rows, range, TIMESTAMP)).thenReturn(expectedResult);
Map<byte[], RowColumnRangeIterator> result = kvs.getRowsColumnRange(TABLE_REF, rows, range, TIMESTAMP);
assertThat(result, equalTo(expectedResult));
checkSpan("atlasdb-kvs.getRowsColumnRange({table}, 1 rows, ts 1)");
verify(delegate).getRowsColumnRange(TABLE_REF, rows, range, TIMESTAMP);
verifyNoMoreInteractions(delegate);
}
use of com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection in project atlasdb by palantir.
the class AbstractDbQueryFactory method getRowsColumnRangeQuery.
@Override
public FullQuery getRowsColumnRangeQuery(Map<byte[], BatchColumnRangeSelection> columnRangeSelectionsByRow, long ts) {
List<String> subQueries = new ArrayList<>(columnRangeSelectionsByRow.size());
int totalArgs = 0;
for (BatchColumnRangeSelection columnRangeSelection : columnRangeSelectionsByRow.values()) {
totalArgs += 2 + ((columnRangeSelection.getStartCol().length > 0) ? 1 : 0) + ((columnRangeSelection.getEndCol().length > 0) ? 1 : 0);
}
List<Object> args = new ArrayList<>(totalArgs);
for (Map.Entry<byte[], BatchColumnRangeSelection> entry : columnRangeSelectionsByRow.entrySet()) {
FullQuery query = getRowsColumnRangeSubQuery(entry.getKey(), ts, entry.getValue());
subQueries.add(query.getQuery());
for (Object arg : query.getArgs()) {
args.add(arg);
}
}
String query = Joiner.on(") UNION ALL (").appendTo(new StringBuilder("("), subQueries).append(")").append(" ORDER BY row_name ASC, col_name ASC").toString();
return new FullQuery(query).withArgs(args);
}
use of com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection in project atlasdb by palantir.
the class SnapshotTransaction method getRowsColumnRange.
@Override
public Iterator<Map.Entry<Cell, byte[]>> getRowsColumnRange(TableReference tableRef, Iterable<byte[]> rows, ColumnRangeSelection columnRangeSelection, int batchHint) {
checkGetPreconditions(tableRef);
if (Iterables.isEmpty(rows)) {
return Collections.emptyIterator();
}
hasReads = true;
RowColumnRangeIterator rawResults = keyValueService.getRowsColumnRange(tableRef, rows, columnRangeSelection, batchHint, getStartTimestamp());
if (!rawResults.hasNext()) {
validateExternalAndCommitLocksIfNecessary(tableRef, getStartTimestamp());
}
// else the postFiltered iterator will check for each batch.
Iterator<Map.Entry<byte[], RowColumnRangeIterator>> rawResultsByRow = partitionByRow(rawResults);
Iterator<Iterator<Map.Entry<Cell, byte[]>>> postFiltered = Iterators.transform(rawResultsByRow, e -> {
byte[] row = e.getKey();
RowColumnRangeIterator rawIterator = e.getValue();
BatchColumnRangeSelection batchColumnRangeSelection = BatchColumnRangeSelection.create(columnRangeSelection, batchHint);
return getPostFilteredColumns(tableRef, batchColumnRangeSelection, row, rawIterator);
});
return Iterators.concat(postFiltered);
}
use of com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection in project atlasdb by palantir.
the class ColumnRangeBatchProvider method getBatch.
@Override
public ClosableIterator<Map.Entry<Cell, Value>> getBatch(int batchSize, @Nullable byte[] lastToken) {
byte[] startCol = columnRangeSelection.getStartCol();
if (lastToken != null) {
startCol = RangeRequests.nextLexicographicName(lastToken);
}
BatchColumnRangeSelection newRange = BatchColumnRangeSelection.create(startCol, columnRangeSelection.getEndCol(), batchSize);
Map<byte[], RowColumnRangeIterator> range = keyValueService.getRowsColumnRange(tableRef, ImmutableList.of(row), newRange, timestamp);
if (range.isEmpty()) {
return ClosableIterators.wrap(ImmutableList.<Map.Entry<Cell, Value>>of().iterator());
}
return ClosableIterators.wrap(Iterables.getOnlyElement(range.values()));
}
use of com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection in project atlasdb by palantir.
the class SerializableTransaction method verifyColumnRanges.
private void verifyColumnRanges(Transaction readOnlyTransaction) {
// verify each set of reads to ensure they are the same.
for (Entry<TableReference, ConcurrentMap<byte[], ConcurrentMap<BatchColumnRangeSelection, byte[]>>> tableAndRange : columnRangeEndsByTable.entrySet()) {
TableReference table = tableAndRange.getKey();
Map<byte[], ConcurrentMap<BatchColumnRangeSelection, byte[]>> columnRangeEnds = tableAndRange.getValue();
Map<Cell, byte[]> writes = writesByTable.get(table);
Map<BatchColumnRangeSelection, List<byte[]>> rangesToRows = Maps.newHashMap();
for (Entry<byte[], ConcurrentMap<BatchColumnRangeSelection, byte[]>> rowAndRangeEnds : columnRangeEnds.entrySet()) {
byte[] row = rowAndRangeEnds.getKey();
Map<BatchColumnRangeSelection, byte[]> rangeEnds = columnRangeEnds.get(row);
for (Entry<BatchColumnRangeSelection, byte[]> e : rangeEnds.entrySet()) {
BatchColumnRangeSelection range = e.getKey();
byte[] rangeEnd = e.getValue();
if (rangeEnd.length != 0 && !RangeRequests.isTerminalRow(false, rangeEnd)) {
range = BatchColumnRangeSelection.create(range.getStartCol(), RangeRequests.getNextStartRow(false, rangeEnd), range.getBatchHint());
}
if (rangesToRows.get(range) != null) {
rangesToRows.get(range).add(row);
} else {
rangesToRows.put(range, ImmutableList.of(row));
}
}
}
for (Entry<BatchColumnRangeSelection, List<byte[]>> e : rangesToRows.entrySet()) {
BatchColumnRangeSelection range = e.getKey();
List<byte[]> rows = e.getValue();
Map<byte[], BatchingVisitable<Map.Entry<Cell, byte[]>>> result = readOnlyTransaction.getRowsColumnRange(table, rows, range);
for (Entry<byte[], BatchingVisitable<Map.Entry<Cell, byte[]>>> res : result.entrySet()) {
byte[] row = res.getKey();
BatchingVisitableView<Entry<Cell, byte[]>> bv = BatchingVisitableView.of(res.getValue());
NavigableMap<Cell, ByteBuffer> readsInRange = Maps.transformValues(getReadsInColumnRange(table, row, range), input -> ByteBuffer.wrap(input));
boolean isEqual = bv.transformBatch(input -> filterWritesFromCells(input, writes)).isEqual(readsInRange.entrySet());
if (!isEqual) {
handleTransactionConflict(table);
}
}
}
}
}
Aggregations