use of com.palantir.common.base.BatchingVisitableView in project atlasdb by palantir.
the class SchemaApiTestImpl method getRangeSecondColumnOnlyFirstTwoResults.
@Override
protected Map<String, StringValue> getRangeSecondColumnOnlyFirstTwoResults(Transaction transaction, String startRowKey, String endRowKey) {
SchemaApiTestTable table = tableFactory.getSchemaApiTestTable(transaction);
ColumnSelection secondColSelection = SchemaApiTestTable.getColumnSelection(SchemaApiTestTable.SchemaApiTestNamedColumn.COLUMN2);
RangeRequest rangeRequest = RangeRequest.builder().startRowInclusive(SchemaApiTestRow.of(startRowKey).persistToBytes()).endRowExclusive(SchemaApiTestRow.of(endRowKey).persistToBytes()).retainColumns(secondColSelection).batchHint(2).build();
BatchingVisitableView<SchemaApiTestRowResult> rangeRequestResult = table.getRange(rangeRequest);
return BatchingVisitables.take(rangeRequestResult, 2).stream().collect(Collectors.toMap(entry -> entry.getRowName().getComponent1(), SchemaApiTestTable.SchemaApiTestRowResult::getColumn2));
}
use of com.palantir.common.base.BatchingVisitableView in project atlasdb by palantir.
the class SchemaApiTestImpl method getRangeSecondColumn.
@Override
protected Map<String, StringValue> getRangeSecondColumn(Transaction transaction, String startRowKey, String endRowKey) {
SchemaApiTestTable table = tableFactory.getSchemaApiTestTable(transaction);
ColumnSelection secondColSelection = SchemaApiTestTable.getColumnSelection(SchemaApiTestTable.SchemaApiTestNamedColumn.COLUMN2);
RangeRequest rangeRequest = RangeRequest.builder().startRowInclusive(SchemaApiTestRow.of(startRowKey).persistToBytes()).endRowExclusive(SchemaApiTestRow.of(endRowKey).persistToBytes()).retainColumns(secondColSelection).build();
BatchingVisitableView<SchemaApiTestRowResult> rangeRequestResult = table.getRange(rangeRequest);
return rangeRequestResult.immutableCopy().stream().collect(Collectors.toMap(entry -> entry.getRowName().getComponent1(), SchemaApiTestTable.SchemaApiTestRowResult::getColumn2));
}
use of com.palantir.common.base.BatchingVisitableView 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