Search in sources :

Example 6 with BatchColumnRangeSelection

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

Example 7 with BatchColumnRangeSelection

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);
}
Also used : BatchColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 8 with BatchColumnRangeSelection

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);
}
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 9 with BatchColumnRangeSelection

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

Example 10 with BatchColumnRangeSelection

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);
                }
            }
        }
    }
}
Also used : TransactionService(com.palantir.atlasdb.transaction.service.TransactionService) RangeRequests(com.palantir.atlasdb.keyvalue.api.RangeRequests) BatchColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection) LoggerFactory(org.slf4j.LoggerFactory) BatchingVisitable(com.palantir.common.base.BatchingVisitable) ByteBuffer(java.nio.ByteBuffer) TransactionSerializableConflictException(com.palantir.atlasdb.transaction.api.TransactionSerializableConflictException) Map(java.util.Map) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Cell(com.palantir.atlasdb.keyvalue.api.Cell) TransactionReadSentinelBehavior(com.palantir.atlasdb.transaction.api.TransactionReadSentinelBehavior) ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap) Set(java.util.Set) Cleaner(com.palantir.atlasdb.cleaner.Cleaner) Maps2(com.palantir.common.collect.Maps2) NavigableMap(java.util.NavigableMap) Sets(com.google.common.collect.Sets) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) List(java.util.List) Predicate(com.google.common.base.Predicate) Transaction(com.palantir.atlasdb.transaction.api.Transaction) Entry(java.util.Map.Entry) Optional(java.util.Optional) Cells(com.palantir.atlasdb.keyvalue.impl.Cells) SortedMap(java.util.SortedMap) NoOpCleaner(com.palantir.atlasdb.cleaner.NoOpCleaner) Iterables(com.google.common.collect.Iterables) ConflictHandler(com.palantir.atlasdb.transaction.api.ConflictHandler) AtlasDbMetrics(com.palantir.atlasdb.util.AtlasDbMetrics) Supplier(com.google.common.base.Supplier) Multimap(com.google.common.collect.Multimap) PtBytes(com.palantir.atlasdb.encoding.PtBytes) ConcurrentMap(java.util.concurrent.ConcurrentMap) Multimaps(com.google.common.collect.Multimaps) Meter(com.codahale.metrics.Meter) AtlasDbConstraintCheckingMode(com.palantir.atlasdb.transaction.api.AtlasDbConstraintCheckingMode) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Predicates(com.google.common.base.Predicates) Suppliers(com.google.common.base.Suppliers) ExecutorService(java.util.concurrent.ExecutorService) Functions(com.google.common.base.Functions) UnsignedBytes(com.google.common.primitives.UnsignedBytes) Logger(org.slf4j.Logger) MetricRegistry(com.codahale.metrics.MetricRegistry) PreCommitCondition(com.palantir.atlasdb.transaction.api.PreCommitCondition) LockToken(com.palantir.lock.v2.LockToken) TimestampCache(com.palantir.atlasdb.cache.TimestampCache) TimelockService(com.palantir.lock.v2.TimelockService) Maps(com.google.common.collect.Maps) IterableUtils(com.palantir.common.collect.IterableUtils) Pair(com.palantir.util.Pair) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) Validate(org.apache.commons.lang3.Validate) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) BatchingVisitableView(com.palantir.common.base.BatchingVisitableView) MultiTableSweepQueueWriter(com.palantir.atlasdb.sweep.queue.MultiTableSweepQueueWriter) Idempotent(com.palantir.common.annotation.Idempotent) AbortingVisitor(com.palantir.common.base.AbortingVisitor) BatchingVisitable(com.palantir.common.base.BatchingVisitable) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Entry(java.util.Map.Entry) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Cell(com.palantir.atlasdb.keyvalue.api.Cell) BatchColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection) ConcurrentMap(java.util.concurrent.ConcurrentMap) ByteBuffer(java.nio.ByteBuffer) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap) NavigableMap(java.util.NavigableMap) SortedMap(java.util.SortedMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap)

Aggregations

BatchColumnRangeSelection (com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection)12 RowColumnRangeIterator (com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator)9 Cell (com.palantir.atlasdb.keyvalue.api.Cell)6 Map (java.util.Map)6 Entry (java.util.Map.Entry)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 SortedMap (java.util.SortedMap)5 Value (com.palantir.atlasdb.keyvalue.api.Value)4 LinkedHashMap (java.util.LinkedHashMap)4 ImmutableList (com.google.common.collect.ImmutableList)3 LocalRowColumnRangeIterator (com.palantir.atlasdb.keyvalue.impl.LocalRowColumnRangeIterator)3 HashMap (java.util.HashMap)3 NavigableMap (java.util.NavigableMap)3 AbstractIterator (com.google.common.collect.AbstractIterator)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 ConcurrentNavigableMap (java.util.concurrent.ConcurrentNavigableMap)2 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)2 Test (org.junit.Test)2