Search in sources :

Example 46 with RangeRequest

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

the class SerializableTransaction method verifyRanges.

private void verifyRanges(Transaction readOnlyTransaction) {
    // verify each set of reads to ensure they are the same.
    for (Entry<TableReference, ConcurrentMap<RangeRequest, byte[]>> tableAndRange : rangeEndByTable.entrySet()) {
        TableReference table = tableAndRange.getKey();
        Map<RangeRequest, byte[]> rangeEnds = tableAndRange.getValue();
        for (Entry<RangeRequest, byte[]> rangeAndRangeEndEntry : rangeEnds.entrySet()) {
            RangeRequest range = rangeAndRangeEndEntry.getKey();
            byte[] rangeEnd = rangeAndRangeEndEntry.getValue();
            if (rangeEnd.length != 0 && !RangeRequests.isTerminalRow(range.isReverse(), rangeEnd)) {
                range = range.getBuilder().endRowExclusive(RangeRequests.getNextStartRow(range.isReverse(), rangeEnd)).build();
            }
            ConcurrentNavigableMap<Cell, byte[]> writes = writesByTable.get(table);
            BatchingVisitableView<RowResult<byte[]>> bv = BatchingVisitableView.of(readOnlyTransaction.getRange(table, range));
            NavigableMap<Cell, ByteBuffer> readsInRange = Maps.transformValues(getReadsInRange(table, range), ByteBuffer::wrap);
            if (!bv.transformBatch(input -> filterWritesFromRows(input, writes)).isEqual(readsInRange.entrySet())) {
                handleTransactionConflict(table);
            }
        }
    }
}
Also used : ConcurrentMap(java.util.concurrent.ConcurrentMap) ByteBuffer(java.nio.ByteBuffer) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Example 47 with RangeRequest

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

the class RangeVisitor method visitRange.

private void visitRange(Visitor visitor, MutableRange range) {
    do {
        final RangeRequest request = range.getRangeRequest();
        try {
            long startTime = System.currentTimeMillis();
            long numVisited = txManager.runTaskWithLocksWithRetry(lockTokens, Suppliers.ofInstance(null), new LockAwareTransactionTask<Long, RuntimeException>() {

                @Override
                public Long execute(Transaction tx, Iterable<HeldLocksToken> heldLocks) {
                    return visitInternal(tx, visitor, request, range);
                }

                @Override
                public String toString() {
                    return "visitRange(" + request + ")";
                }
            });
            counter.addAndGet(numVisited);
            log.info("Visited {} rows from {} in {} ms.", numVisited, tableRef.getQualifiedName(), System.currentTimeMillis() - startTime);
        } catch (InterruptedException e) {
            throw Throwables.rewrapAndThrowUncheckedException(e);
        }
    } while (!range.isComplete());
}
Also used : Transaction(com.palantir.atlasdb.transaction.api.Transaction) HeldLocksToken(com.palantir.lock.HeldLocksToken) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 48 with RangeRequest

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

the class KvsGetRangeBenchmarks method getSingleRangeInner.

private Object getSingleRangeInner(ConsecutiveNarrowTable table, int sliceSize) {
    RangeRequest request = Iterables.getOnlyElement(table.getRangeRequests(1, sliceSize, false));
    int startRow = Ints.fromByteArray(request.getStartInclusive());
    ClosableIterator<RowResult<Value>> result = table.getKvs().getRange(table.getTableRef(), request, Long.MAX_VALUE);
    ArrayList<RowResult<Value>> list = Lists.newArrayList(result);
    result.close();
    Preconditions.checkState(list.size() == sliceSize, "List size %s != %s", sliceSize, list.size());
    list.forEach(rowResult -> {
        byte[] rowName = rowResult.getRowName();
        int rowNumber = Ints.fromByteArray(rowName);
        Preconditions.checkState(rowNumber - startRow < sliceSize, "Start Row %s, row number %s, sliceSize %s", startRow, rowNumber, sliceSize);
    });
    return result;
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest)

Example 49 with RangeRequest

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

the class JdbcKeyValueService method getRangeOfTimestamps.

@Override
public ClosableIterator<RowResult<Set<Long>>> getRangeOfTimestamps(final TableReference tableRef, final RangeRequest rangeRequest, final long timestamp) {
    Iterable<RowResult<Set<Long>>> iter = new AbstractPagingIterable<RowResult<Set<Long>>, TokenBackedBasicResultsPage<RowResult<Set<Long>>, byte[]>>() {

        @Override
        protected TokenBackedBasicResultsPage<RowResult<Set<Long>>, byte[]> getFirstPage() {
            return getPageWithTimestamps(tableRef, rangeRequest, timestamp);
        }

        @Override
        protected TokenBackedBasicResultsPage<RowResult<Set<Long>>, byte[]> getNextPage(TokenBackedBasicResultsPage<RowResult<Set<Long>>, byte[]> previous) {
            byte[] startRow = previous.getTokenForNextPage();
            RangeRequest newRange = rangeRequest.getBuilder().startRowInclusive(startRow).build();
            return getPageWithTimestamps(tableRef, newRange, timestamp);
        }
    };
    return ClosableIterators.wrap(iter.iterator());
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) TokenBackedBasicResultsPage(com.palantir.util.paging.TokenBackedBasicResultsPage) Set(java.util.Set) ImmutableSet(com.google.common.collect.ImmutableSet) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) AbstractPagingIterable(com.palantir.util.paging.AbstractPagingIterable)

Example 50 with RangeRequest

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

the class AbstractKeyValueServiceTest method testGetRange.

public void testGetRange(boolean reverseSupported) {
    putTestDataForSingleTimestamp();
    // Unbounded
    final RangeRequest all = RangeRequest.all();
    assertRangeSizeAndOrdering(keyValueService.getRange(TEST_TABLE, all, TEST_TIMESTAMP + 1), 3, all);
    if (reverseSupported) {
        final RangeRequest allReverse = RangeRequest.reverseBuilder().build();
        assertRangeSizeAndOrdering(keyValueService.getRange(TEST_TABLE, allReverse, TEST_TIMESTAMP + 1), 3, allReverse);
    }
    // Upbounded
    final RangeRequest upbounded = RangeRequest.builder().endRowExclusive(row2).build();
    assertRangeSizeAndOrdering(keyValueService.getRange(TEST_TABLE, upbounded, TEST_TIMESTAMP + 1), 2, upbounded);
    if (reverseSupported) {
        final RangeRequest upboundedReverse = RangeRequest.reverseBuilder().endRowExclusive(row0).build();
        assertRangeSizeAndOrdering(keyValueService.getRange(TEST_TABLE, upboundedReverse, TEST_TIMESTAMP + 1), 2, upboundedReverse);
    }
    // Downbounded
    final RangeRequest downbounded = RangeRequest.builder().startRowInclusive(row1).build();
    assertRangeSizeAndOrdering(keyValueService.getRange(TEST_TABLE, downbounded, TEST_TIMESTAMP + 1), 2, downbounded);
    if (reverseSupported) {
        final RangeRequest downboundedReverse = RangeRequest.reverseBuilder().startRowInclusive(row1).build();
        assertRangeSizeAndOrdering(keyValueService.getRange(TEST_TABLE, downboundedReverse, TEST_TIMESTAMP + 1), 2, downboundedReverse);
    }
    // Both-bounded
    final RangeRequest bothbounded = RangeRequest.builder().startRowInclusive(row1).endRowExclusive(row2).build();
    assertRangeSizeAndOrdering(keyValueService.getRange(TEST_TABLE, bothbounded, TEST_TIMESTAMP + 1), 1, bothbounded);
    if (reverseSupported) {
        final RangeRequest bothboundedReverse = RangeRequest.reverseBuilder().startRowInclusive(row2).endRowExclusive(row1).build();
        assertRangeSizeAndOrdering(keyValueService.getRange(TEST_TABLE, bothboundedReverse, TEST_TIMESTAMP + 1), 1, bothboundedReverse);
    }
    // Precise test for lower-bounded
    RangeRequest rangeRequest = downbounded;
    ClosableIterator<RowResult<Value>> rangeResult = keyValueService.getRange(TEST_TABLE, rangeRequest, TEST_TIMESTAMP + 1);
    assertFalse(keyValueService.getRange(TEST_TABLE, rangeRequest, TEST_TIMESTAMP).hasNext());
    assertTrue(rangeResult.hasNext());
    assertEquals(RowResult.create(row1, ImmutableSortedMap.orderedBy(UnsignedBytes.lexicographicalComparator()).put(column0, Value.create(value10, TEST_TIMESTAMP)).put(column2, Value.create(value12, TEST_TIMESTAMP)).build()), rangeResult.next());
    assertTrue(rangeResult.hasNext());
    assertEquals(RowResult.create(row2, ImmutableSortedMap.orderedBy(UnsignedBytes.lexicographicalComparator()).put(column1, Value.create(value21, TEST_TIMESTAMP)).put(column2, Value.create(value22, TEST_TIMESTAMP)).build()), rangeResult.next());
    rangeResult.close();
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest)

Aggregations

RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)68 RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)36 Test (org.junit.Test)35 Value (com.palantir.atlasdb.keyvalue.api.Value)17 TokenBackedBasicResultsPage (com.palantir.util.paging.TokenBackedBasicResultsPage)14 Cell (com.palantir.atlasdb.keyvalue.api.Cell)12 Transaction (com.palantir.atlasdb.transaction.api.Transaction)7 List (java.util.List)5 Set (java.util.Set)5 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)4 StringValue (com.palantir.atlasdb.table.description.test.StringValue)4 AbstractPagingIterable (com.palantir.util.paging.AbstractPagingIterable)4 Map (java.util.Map)4 ColumnSelection (com.palantir.atlasdb.keyvalue.api.ColumnSelection)3 AbstractIterator (com.google.common.collect.AbstractIterator)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Hashing (com.google.common.hash.Hashing)2 NameComponentDescription (com.palantir.atlasdb.table.description.NameComponentDescription)2 BatchingVisitableView (com.palantir.common.base.BatchingVisitableView)2 ClosableIterator (com.palantir.common.base.ClosableIterator)2