Search in sources :

Example 11 with RowColumnRangeIterator

use of com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator 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);
}
Also used : Entry(java.util.Map.Entry) BatchColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection) PeekingIterator(com.google.common.collect.PeekingIterator) AbstractIterator(com.google.common.collect.AbstractIterator) LocalRowColumnRangeIterator(com.palantir.atlasdb.keyvalue.impl.LocalRowColumnRangeIterator) ClosableIterator(com.palantir.common.base.ClosableIterator) RowColumnRangeIterator(com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator) ForwardingClosableIterator(com.palantir.common.base.ForwardingClosableIterator) Iterator(java.util.Iterator) LocalRowColumnRangeIterator(com.palantir.atlasdb.keyvalue.impl.LocalRowColumnRangeIterator) RowColumnRangeIterator(com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator) Map(java.util.Map) ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap) LinkedHashMap(java.util.LinkedHashMap) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ImmutableMap(com.google.common.collect.ImmutableMap) SortedMap(java.util.SortedMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Example 12 with RowColumnRangeIterator

use of com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator 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()));
}
Also used : BatchColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection) RowColumnRangeIterator(com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator)

Example 13 with RowColumnRangeIterator

use of com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator in project atlasdb by palantir.

the class KvsGetRowsColumnRangeBenchmarks method getAllColumnsAligned.

@Benchmark
@Threads(1)
@Warmup(time = 16, timeUnit = TimeUnit.SECONDS)
@Measurement(time = 160, timeUnit = TimeUnit.SECONDS)
public Object getAllColumnsAligned(WideRowsTable table) {
    List<byte[]> rows = IntStream.rangeClosed(0, WideRowsTable.NUM_ROWS - 1).mapToObj(WideRowsTable::getRow).collect(Collectors.toList());
    RowColumnRangeIterator rowsColumnRange = table.getKvs().getRowsColumnRange(table.getTableRef(), rows, new ColumnRangeSelection(null, null), 10000, Long.MAX_VALUE);
    int expectedNumCells = WideRowsTable.NUM_ROWS * WideRowsTable.NUM_COLS_PER_ROW;
    List<Map.Entry<Cell, Value>> loadedCells = new ArrayList<>(expectedNumCells);
    while (rowsColumnRange.hasNext()) {
        loadedCells.add(rowsColumnRange.next());
    }
    Preconditions.checkState(loadedCells.size() == expectedNumCells, "Should be %s cells, but were: %s", expectedNumCells, loadedCells.size());
    return loadedCells;
}
Also used : ArrayList(java.util.ArrayList) RowColumnRangeIterator(com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator) ColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.ColumnRangeSelection) Threads(org.openjdk.jmh.annotations.Threads) Measurement(org.openjdk.jmh.annotations.Measurement) Warmup(org.openjdk.jmh.annotations.Warmup) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 14 with RowColumnRangeIterator

use of com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator in project atlasdb by palantir.

the class KvsGetRowsColumnRangeBenchmarks method getAllColumnsSingleBigRow.

@Benchmark
@Threads(1)
@Warmup(time = 16, timeUnit = TimeUnit.SECONDS)
@Measurement(time = 160, timeUnit = TimeUnit.SECONDS)
public Object getAllColumnsSingleBigRow(VeryWideRowTable table, Blackhole blackhole) {
    RowColumnRangeIterator iter = table.getKvs().getRowsColumnRange(table.getTableRef(), Collections.singleton(Tables.ROW_BYTES.array()), new ColumnRangeSelection(null, null), 10000, Long.MAX_VALUE);
    int count = 0;
    while (iter.hasNext()) {
        blackhole.consume(iter.next());
        ++count;
    }
    Preconditions.checkState(count == table.getNumCols(), "Should be %s cells, but were: %s", table.getNumCols(), count);
    return count;
}
Also used : RowColumnRangeIterator(com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator) ColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.ColumnRangeSelection) Threads(org.openjdk.jmh.annotations.Threads) Measurement(org.openjdk.jmh.annotations.Measurement) Warmup(org.openjdk.jmh.annotations.Warmup) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 15 with RowColumnRangeIterator

use of com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator in project atlasdb by palantir.

the class AbstractKeyValueServiceTest method testGetRowColumnRangeCellBatchMultipleRows.

@Test
public void testGetRowColumnRangeCellBatchMultipleRows() {
    putTestDataForSingleTimestamp();
    RowColumnRangeIterator values = keyValueService.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row1, row0, row2), new ColumnRangeSelection(PtBytes.EMPTY_BYTE_ARRAY, PtBytes.EMPTY_BYTE_ARRAY), 3, TEST_TIMESTAMP + 1);
    assertNextElementMatches(values, Cell.create(row1, column0), value10);
    assertNextElementMatches(values, Cell.create(row1, column2), value12);
    assertNextElementMatches(values, TEST_CELL, value00);
    assertNextElementMatches(values, Cell.create(row0, column1), value01);
    assertNextElementMatches(values, Cell.create(row2, column1), value21);
    assertNextElementMatches(values, Cell.create(row2, column2), value22);
    assertFalse(values.hasNext());
}
Also used : RowColumnRangeIterator(com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator) BatchColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection) ColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.ColumnRangeSelection) Test(org.junit.Test)

Aggregations

RowColumnRangeIterator (com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator)18 BatchColumnRangeSelection (com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection)12 ColumnRangeSelection (com.palantir.atlasdb.keyvalue.api.ColumnRangeSelection)8 Cell (com.palantir.atlasdb.keyvalue.api.Cell)6 Test (org.junit.Test)6 LocalRowColumnRangeIterator (com.palantir.atlasdb.keyvalue.impl.LocalRowColumnRangeIterator)5 LinkedHashMap (java.util.LinkedHashMap)5 Map (java.util.Map)5 Entry (java.util.Map.Entry)5 SortedMap (java.util.SortedMap)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)4 Value (com.palantir.atlasdb.keyvalue.api.Value)4 ArrayList (java.util.ArrayList)3 ConcurrentMap (java.util.concurrent.ConcurrentMap)3 ConcurrentNavigableMap (java.util.concurrent.ConcurrentNavigableMap)3 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)3 Benchmark (org.openjdk.jmh.annotations.Benchmark)3 Measurement (org.openjdk.jmh.annotations.Measurement)3 Threads (org.openjdk.jmh.annotations.Threads)3