Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

getRowsColumnRange always has cells grouped by row #4687

Merged
merged 10 commits into from
Apr 1, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -476,19 +477,19 @@ private Iterator<Map.Entry<Cell, byte[]>> filterDeletedValues(
private Iterator<Map.Entry<Cell, Value>> getRowColumnRangePostFiltered(
TableReference tableRef, RowColumnRangeIterator iterator, int batchHint) {
return Iterators.concat(Iterators.transform(Iterators.partition(iterator, batchHint), batch -> {
ImmutableMap.Builder<Cell, Value> rawBuilder = ImmutableMap.builder();
batch.forEach(rawBuilder::put);
Map<Cell, Value> raw = rawBuilder.build();
// N.B. This batch could be spread across multiple rows, and those rows might extend into other
// batches. We are given cells for a row grouped together, so easiest way to ensure they stay together
// is to preserve the original order.
Map<Cell, Value> raw = new LinkedHashMap<>();
mswintermeyer marked this conversation as resolved.
Show resolved Hide resolved
batch.forEach(entry -> raw.put(entry.getKey(), entry.getValue()));
validatePreCommitRequirementsOnReadIfNecessary(tableRef, getStartTimestamp());
if (raw.isEmpty()) {
return Collections.emptyIterator();
}
SortedMap<Cell, Value> postFiltered = ImmutableSortedMap.copyOf(
getWithPostFilteringSync(
tableRef,
raw,
x -> x));
return postFiltered.entrySet().iterator();
return getWithPostFilteringSync(
tableRef,
raw,
x -> x).iterator();
}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -87,6 +88,7 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimaps;
import com.google.common.primitives.UnsignedBytes;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
Expand Down Expand Up @@ -1184,6 +1186,7 @@ public void testRowsColumnRangesSingleIteratorVersion() {
runTestForGetRowsColumnRangeSingleIteratorVersion(10, 10, 5);
runTestForGetRowsColumnRangeSingleIteratorVersion(10, 10, 10);
runTestForGetRowsColumnRangeSingleIteratorVersion(100, 100, 99);
runTestForGetRowsColumnRangeSingleIteratorVersion(100, 11, 0);
mswintermeyer marked this conversation as resolved.
Show resolved Hide resolved
}

private void runTestForGetRowsColumnRangeSingleIteratorVersion(
Expand Down Expand Up @@ -1213,19 +1216,35 @@ private void runTestForGetRowsColumnRangeSingleIteratorVersion(
});
keyValueService.addGarbageCollectionSentinelValues(TABLE, expectedDeletedCells);

List<byte[]> shuffledRows = expectedRows;
Collections.shuffle(shuffledRows);
List<Cell> cells = serializableTxManager.runTaskReadOnly(tx ->
ImmutableList.copyOf(Iterators.transform(
tx.getRowsColumnRange(
TABLE,
expectedRows,
shuffledRows,
new ColumnRangeSelection(null, null),
10),
Map.Entry::getKey)));
expectedCells.sort(Comparator
.comparing(
(Cell cell) -> indexOfArrayEquality(shuffledRows, cell.getRowName()),
Comparator.naturalOrder())
.thenComparing(Cell::getColumnName, UnsignedBytes.lexicographicalComparator()));
Assertions.assertThat(cells).isEqualTo(expectedCells);

keyValueService.truncateTable(TABLE);
}

private int indexOfArrayEquality(List<byte[]> list, byte[] value) {
for (int i = 0; i < list.size(); i++) {
if (Arrays.equals(list.get(i), value)) {
return i;
}
}
return -1;
}

@Test
public void commitThrowsIfRolledBackAtCommitTime_expiredLocks() {
final Cell cell = Cell.create(PtBytes.toBytes("row1"), PtBytes.toBytes("column1"));
Expand Down