Search in sources :

Example 31 with RangeRequest

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

the class SchemaApiTestV2Impl method getRangeSecondColumnOnlyFirstTwoResults.

@Override
protected Map<String, StringValue> getRangeSecondColumnOnlyFirstTwoResults(Transaction transaction, String startRowKey, String endRowKey) {
    SchemaApiTestV2Table table = tableFactory.getSchemaApiTestV2Table(transaction);
    RangeRequest rangeRequest = RangeRequest.builder().startRowInclusive(SchemaApiTestTable.SchemaApiTestRow.of(startRowKey).persistToBytes()).endRowExclusive(SchemaApiTestTable.SchemaApiTestRow.of(endRowKey).persistToBytes()).build();
    return table.getSmallRowRangeColumn2(rangeRequest, 2);
}
Also used : SchemaApiTestV2Table(com.palantir.atlasdb.table.description.generated.SchemaApiTestV2Table) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest)

Example 32 with RangeRequest

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

the class SchemaApiTestImpl method getRangeSecondColumnOnlyFirstTwoResults.

@Override
protected Map<String, StringValue> getRangeSecondColumnOnlyFirstTwoResults(Transaction transaction, String startRowKey, String endRowKey) {
    SchemaApiTestTable table = tableFactory.getSchemaApiTestTable(transaction);
    ColumnSelection secondColSelection = SchemaApiTestTable.getColumnSelection(SchemaApiTestTable.SchemaApiTestNamedColumn.COLUMN2);
    RangeRequest rangeRequest = RangeRequest.builder().startRowInclusive(SchemaApiTestRow.of(startRowKey).persistToBytes()).endRowExclusive(SchemaApiTestRow.of(endRowKey).persistToBytes()).retainColumns(secondColSelection).batchHint(2).build();
    BatchingVisitableView<SchemaApiTestRowResult> rangeRequestResult = table.getRange(rangeRequest);
    return BatchingVisitables.take(rangeRequestResult, 2).stream().collect(Collectors.toMap(entry -> entry.getRowName().getComponent1(), SchemaApiTestTable.SchemaApiTestRowResult::getColumn2));
}
Also used : StringValue(com.palantir.atlasdb.table.description.test.StringValue) EncodingUtils(com.palantir.atlasdb.ptobject.EncodingUtils) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashComponentsTestTable(com.palantir.atlasdb.table.description.generated.HashComponentsTestTable) ApiTestTableFactory(com.palantir.atlasdb.table.description.generated.ApiTestTableFactory) Test(org.junit.Test) Hashing(com.google.common.hash.Hashing) Collectors(java.util.stream.Collectors) PtBytes(com.palantir.atlasdb.encoding.PtBytes) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) SchemaApiTestRow(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable.SchemaApiTestRow) List(java.util.List) Transaction(com.palantir.atlasdb.transaction.api.Transaction) Map(java.util.Map) SchemaApiTestRowResult(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable.SchemaApiTestRowResult) BatchingVisitableView(com.palantir.common.base.BatchingVisitableView) Optional(java.util.Optional) SchemaApiTestTable(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable) BatchingVisitables(com.palantir.common.base.BatchingVisitables) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) SchemaApiTestTable(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable) SchemaApiTestRowResult(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable.SchemaApiTestRowResult)

Example 33 with RangeRequest

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

the class SnapshotTransaction method getRanges.

@Override
public Iterable<BatchingVisitable<RowResult<byte[]>>> getRanges(final TableReference tableRef, Iterable<RangeRequest> rangeRequests) {
    checkGetPreconditions(tableRef);
    if (perfLogger.isDebugEnabled()) {
        perfLogger.debug("Passed {} ranges to getRanges({}, {})", Iterables.size(rangeRequests), tableRef, rangeRequests);
    }
    if (!Iterables.isEmpty(rangeRequests)) {
        hasReads = true;
    }
    return FluentIterable.from(Iterables.partition(rangeRequests, BATCH_SIZE_GET_FIRST_PAGE)).transformAndConcat(input -> {
        Timer.Context timer = getTimer("processedRangeMillis").time();
        Map<RangeRequest, TokenBackedBasicResultsPage<RowResult<Value>, byte[]>> firstPages = keyValueService.getFirstBatchForRanges(tableRef, input, getStartTimestamp());
        validateExternalAndCommitLocksIfNecessary(tableRef, getStartTimestamp());
        SortedMap<Cell, byte[]> postFiltered = postFilterPages(tableRef, firstPages.values());
        List<BatchingVisitable<RowResult<byte[]>>> ret = Lists.newArrayListWithCapacity(input.size());
        for (RangeRequest rangeRequest : input) {
            TokenBackedBasicResultsPage<RowResult<Value>, byte[]> prePostFilter = firstPages.get(rangeRequest);
            byte[] nextStartRowName = getNextStartRowName(rangeRequest, prePostFilter);
            List<Entry<Cell, byte[]>> mergeIterators = getPostFilteredWithLocalWrites(tableRef, postFiltered, rangeRequest, prePostFilter.getResults(), nextStartRowName);
            ret.add(new AbstractBatchingVisitable<RowResult<byte[]>>() {

                @Override
                protected <K extends Exception> void batchAcceptSizeHint(int batchSizeHint, ConsistentVisitor<RowResult<byte[]>, K> visitor) throws K {
                    checkGetPreconditions(tableRef);
                    final Iterator<RowResult<byte[]>> rowResults = Cells.createRowView(mergeIterators);
                    while (rowResults.hasNext()) {
                        if (!visitor.visit(ImmutableList.of(rowResults.next()))) {
                            return;
                        }
                    }
                    if ((nextStartRowName.length == 0) || !prePostFilter.moreResultsAvailable()) {
                        return;
                    }
                    RangeRequest newRange = rangeRequest.getBuilder().startRowInclusive(nextStartRowName).build();
                    getRange(tableRef, newRange).batchAccept(batchSizeHint, visitor);
                }
            });
        }
        long processedRangeMillis = TimeUnit.NANOSECONDS.toMillis(timer.stop());
        log.trace("Processed {} range requests for {} in {}ms", SafeArg.of("numRequests", input.size()), LoggingArgs.tableRef(tableRef), SafeArg.of("millis", processedRangeMillis));
        return ret;
    });
}
Also used : TokenBackedBasicResultsPage(com.palantir.util.paging.TokenBackedBasicResultsPage) AbstractBatchingVisitable(com.palantir.common.base.AbstractBatchingVisitable) BatchingVisitable(com.palantir.common.base.BatchingVisitable) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) Entry(java.util.Map.Entry) Timer(com.codahale.metrics.Timer) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Value(com.palantir.atlasdb.keyvalue.api.Value) 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) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Example 34 with RangeRequest

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

the class TableTasks method executeDiffTask.

private static void executeDiffTask(DiffStrategy strategy, TableReference plusTable, TableReference minusTable, DiffStats stats, DiffTask task, MutableRange range) throws InterruptedException {
    final RangeRequest request = range.getRangeRequest();
    long startTime = System.currentTimeMillis();
    PartialDiffStats partialStats = task.call(request, range, strategy);
    stats.rowsOnlyInSource.addAndGet(partialStats.rowsOnlyInSource);
    stats.rowsPartiallyInCommon.addAndGet(partialStats.rowsPartiallyInCommon);
    stats.rowsCompletelyInCommon.addAndGet(partialStats.rowsCompletelyInCommon);
    stats.rowsVisited.addAndGet(partialStats.rowsVisited);
    stats.cellsOnlyInSource.addAndGet(partialStats.cellsOnlyInSource);
    stats.cellsInCommon.addAndGet(partialStats.cellsInCommon);
    if (log.isInfoEnabled()) {
        log.info("Processed diff of " + "{} rows " + "{} rows only in source " + "{} rows partially in common " + "{} rows completely in common " + "{} cells only in source " + "{} cells in common " + "between {} and {} in {} ms.", SafeArg.of("rowsVisited", partialStats.rowsVisited), SafeArg.of("rowsOnlyInSource", partialStats.rowsOnlyInSource), SafeArg.of("rowsPartiallyInCommon", partialStats.rowsPartiallyInCommon), SafeArg.of("rowsCompletelyInCommon", partialStats.rowsCompletelyInCommon), SafeArg.of("cellsOnlyInSource", partialStats.cellsOnlyInSource), SafeArg.of("cellsInCommon", partialStats.cellsInCommon), LoggingArgs.tableRef("plusTable", plusTable), LoggingArgs.tableRef("minusTable", minusTable), SafeArg.of("timeTaken", System.currentTimeMillis() - startTime));
    }
}
Also used : RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest)

Example 35 with RangeRequest

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

the class SchemaApiTestImpl method getRangeSecondColumn.

@Override
protected Map<String, StringValue> getRangeSecondColumn(Transaction transaction, String startRowKey, String endRowKey) {
    SchemaApiTestTable table = tableFactory.getSchemaApiTestTable(transaction);
    ColumnSelection secondColSelection = SchemaApiTestTable.getColumnSelection(SchemaApiTestTable.SchemaApiTestNamedColumn.COLUMN2);
    RangeRequest rangeRequest = RangeRequest.builder().startRowInclusive(SchemaApiTestRow.of(startRowKey).persistToBytes()).endRowExclusive(SchemaApiTestRow.of(endRowKey).persistToBytes()).retainColumns(secondColSelection).build();
    BatchingVisitableView<SchemaApiTestRowResult> rangeRequestResult = table.getRange(rangeRequest);
    return rangeRequestResult.immutableCopy().stream().collect(Collectors.toMap(entry -> entry.getRowName().getComponent1(), SchemaApiTestTable.SchemaApiTestRowResult::getColumn2));
}
Also used : StringValue(com.palantir.atlasdb.table.description.test.StringValue) EncodingUtils(com.palantir.atlasdb.ptobject.EncodingUtils) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashComponentsTestTable(com.palantir.atlasdb.table.description.generated.HashComponentsTestTable) ApiTestTableFactory(com.palantir.atlasdb.table.description.generated.ApiTestTableFactory) Test(org.junit.Test) Hashing(com.google.common.hash.Hashing) Collectors(java.util.stream.Collectors) PtBytes(com.palantir.atlasdb.encoding.PtBytes) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) SchemaApiTestRow(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable.SchemaApiTestRow) List(java.util.List) Transaction(com.palantir.atlasdb.transaction.api.Transaction) Map(java.util.Map) SchemaApiTestRowResult(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable.SchemaApiTestRowResult) BatchingVisitableView(com.palantir.common.base.BatchingVisitableView) Optional(java.util.Optional) SchemaApiTestTable(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable) BatchingVisitables(com.palantir.common.base.BatchingVisitables) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) SchemaApiTestTable(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable) SchemaApiTestRowResult(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable.SchemaApiTestRowResult)

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