Search in sources :

Example 21 with RangeRequest

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

the class AbstractTransactionTest method testRangePagingBatchSizeOne.

@Test
public void testRangePagingBatchSizeOne() {
    int totalPuts = 100;
    for (int i = 0; i < totalPuts; i++) {
        putDirect("row" + i, "col1", "v1", 0);
    }
    RangeRequest rangeRequest = RangeRequest.builder().batchHint(1).build();
    Map<RangeRequest, TokenBackedBasicResultsPage<RowResult<Value>, byte[]>> ranges = keyValueService.getFirstBatchForRanges(TEST_TABLE, Iterables.limit(Iterables.cycle(rangeRequest), 100), 1);
    assertEquals(1, ranges.keySet().size());
    assertEquals(1, ranges.values().iterator().next().getResults().size());
    assertEquals("row0", PtBytes.toString(ranges.values().iterator().next().getResults().iterator().next().getRowName()));
}
Also used : TokenBackedBasicResultsPage(com.palantir.util.paging.TokenBackedBasicResultsPage) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Value(com.palantir.atlasdb.keyvalue.api.Value) Test(org.junit.Test)

Example 22 with RangeRequest

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

the class RangeRequestTest method testEmpty.

@Test
public void testEmpty() {
    RangeRequest request = RangeRequest.builder().endRowExclusive(RangeRequests.getFirstRowName()).build();
    Assert.assertTrue(request.isEmptyRange());
    request = RangeRequest.reverseBuilder().endRowExclusive(RangeRequests.getLastRowName()).build();
    Assert.assertTrue(request.isEmptyRange());
}
Also used : RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Test(org.junit.Test)

Example 23 with RangeRequest

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

the class JdbcKeyValueService method getRange.

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

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

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

Example 24 with RangeRequest

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

the class GetCandidateCellsForSweepingShim method getCandidateCellsForSweeping.

public ClosableIterator<List<CandidateCellForSweeping>> getCandidateCellsForSweeping(TableReference tableRef, CandidateCellForSweepingRequest request) {
    RangeRequest range = RangeRequest.builder().startRowInclusive(request.startRowInclusive()).batchHint(request.batchSizeHint().orElse(AtlasDbConstants.DEFAULT_SWEEP_CANDIDATE_BATCH_HINT)).build();
    try (ReleasableCloseable<ClosableIterator<RowResult<Value>>> valueResults = new ReleasableCloseable<>(getValues(tableRef, range, request.maxTimestampExclusive(), request.shouldCheckIfLatestValueIsEmpty()));
        ReleasableCloseable<ClosableIterator<RowResult<Set<Long>>>> tsResults = new ReleasableCloseable<>(keyValueService.getRangeOfTimestamps(tableRef, range, request.maxTimestampExclusive()))) {
        PeekingIterator<RowResult<Value>> peekingValues = Iterators.peekingIterator(valueResults.get());
        Iterator<List<RowResult<Set<Long>>>> tsBatches = Iterators.partition(tsResults.get(), range.getBatchHint());
        Iterator<List<CandidateCellForSweeping>> candidates = Iterators.transform(tsBatches, tsBatch -> {
            List<CandidateCellForSweeping> candidateBatch = Lists.newArrayList();
            for (RowResult<Set<Long>> rr : tsBatch) {
                for (Map.Entry<byte[], Set<Long>> e : rr.getColumns().entrySet()) {
                    byte[] colName = e.getKey();
                    List<Long> sortedTimestamps = e.getValue().stream().filter(request::shouldSweep).sorted().collect(Collectors.toList());
                    Cell cell = Cell.create(rr.getRowName(), colName);
                    boolean latestValEmpty = isLatestValueEmpty(cell, peekingValues);
                    candidateBatch.add(ImmutableCandidateCellForSweeping.builder().cell(cell).sortedTimestamps(sortedTimestamps).isLatestValueEmpty(latestValEmpty).build());
                }
            }
            return candidateBatch;
        });
        Closer closer = createCloserAndRelease(valueResults, tsResults);
        return ClosableIterators.wrap(candidates, closer);
    }
}
Also used : Closer(com.google.common.io.Closer) Set(java.util.Set) ClosableIterator(com.palantir.common.base.ClosableIterator) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) CandidateCellForSweeping(com.palantir.atlasdb.keyvalue.api.CandidateCellForSweeping) ImmutableCandidateCellForSweeping(com.palantir.atlasdb.keyvalue.api.ImmutableCandidateCellForSweeping) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Value(com.palantir.atlasdb.keyvalue.api.Value) List(java.util.List) Map(java.util.Map) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Example 25 with RangeRequest

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

the class TransactionRangeMigrator method copyOneTransactionInternal.

private byte[] copyOneTransactionInternal(RangeRequest range, long rangeId, Transaction readT, Transaction writeT) {
    final long maxBytes = TransactionConstants.WARN_LEVEL_FOR_QUEUED_BYTES / 2;
    byte[] start = getCheckpoint(rangeId, writeT);
    if (start == null) {
        return null;
    }
    RangeRequest.Builder builder = range.getBuilder().startRowInclusive(start);
    if (builder.isInvalidRange()) {
        return null;
    }
    RangeRequest rangeToUse = builder.build();
    BatchingVisitable<RowResult<byte[]>> bv = readT.getRange(srcTable, rangeToUse);
    byte[] lastRow = internalCopyRange(bv, maxBytes, writeT);
    byte[] nextRow = getNextRowName(lastRow);
    checkpointer.checkpoint(srcTable.getQualifiedName(), rangeId, nextRow, writeT);
    return lastRow;
}
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