Search in sources :

Example 66 with RangeRequest

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

the class KeyValueServices method getFirstBatchForRangeUsingGetRange.

public static void getFirstBatchForRangeUsingGetRange(KeyValueService kv, TableReference tableRef, RangeRequest request, long timestamp, @Output Map<RangeRequest, TokenBackedBasicResultsPage<RowResult<Value>, byte[]>> ret) {
    if (ret.containsKey(request)) {
        return;
    }
    RangeRequest requestWithHint = request;
    if (request.getBatchHint() == null) {
        requestWithHint = request.withBatchHint(100);
    }
    final ClosableIterator<RowResult<Value>> range = kv.getRange(tableRef, requestWithHint, timestamp);
    try {
        int batchSize = requestWithHint.getBatchHint();
        final Iterator<RowResult<Value>> withLimit = Iterators.limit(range, batchSize);
        ImmutableList<RowResult<Value>> results = ImmutableList.copyOf(withLimit);
        if (results.size() != batchSize) {
            ret.put(request, SimpleTokenBackedResultsPage.create(request.getEndExclusive(), results, false));
            return;
        }
        RowResult<Value> last = results.get(results.size() - 1);
        byte[] lastRowName = last.getRowName();
        if (RangeRequests.isTerminalRow(request.isReverse(), lastRowName)) {
            ret.put(request, SimpleTokenBackedResultsPage.create(lastRowName, results, false));
            return;
        }
        byte[] nextStartRow = RangeRequests.getNextStartRow(request.isReverse(), lastRowName);
        if (Arrays.equals(request.getEndExclusive(), nextStartRow)) {
            ret.put(request, SimpleTokenBackedResultsPage.create(nextStartRow, results, false));
        } else {
            ret.put(request, SimpleTokenBackedResultsPage.create(nextStartRow, results, true));
        }
    } finally {
        range.close();
    }
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Value(com.palantir.atlasdb.keyvalue.api.Value)

Example 67 with RangeRequest

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

the class KvsRangeMigrator 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();
    if (log.isTraceEnabled()) {
        log.trace("Copying table {} range {} from {}  to {}", srcTable, rangeId, BaseEncoding.base16().lowerCase().encode(rangeToUse.getStartInclusive()), BaseEncoding.base16().lowerCase().encode(rangeToUse.getEndExclusive()));
    }
    BatchingVisitable<RowResult<byte[]>> bv = readT.getRange(srcTable, rangeToUse);
    Map<Cell, byte[]> writeMap = Maps.newHashMap();
    byte[] lastRow = internalCopyRange(bv, maxBytes, writeMap);
    if (log.isTraceEnabled() && (lastRow != null)) {
        log.trace("Copying {} bytes for range {} on table {}", lastRow.length, rangeId, srcTable);
    }
    writeToKvs(writeMap);
    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) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Example 68 with RangeRequest

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

the class TableMigrator method migrate.

public void migrate() {
    List<byte[]> rangeBoundaries = getRangeBoundaries();
    int totalTasks = rangeBoundaries.size() - 1;
    progress.beginTask("Migrating table " + srcTable + "...", totalTasks);
    Map<Long, byte[]> boundaryById = Maps.newHashMap();
    for (long rangeId = 0; rangeId < rangeBoundaries.size() - 1; rangeId++) {
        boundaryById.put(rangeId, rangeBoundaries.get((int) rangeId));
    }
    checkpointer.createCheckpoints(srcTable.getQualifiedName(), boundaryById);
    // Look up the checkpoints and log start point (or done)
    rangeMigrator.logStatus(rangeBoundaries.size());
    List<Future<Void>> futures = Lists.newArrayList();
    for (long rangeId = 0; rangeId < rangeBoundaries.size() - 1; rangeId++) {
        byte[] end = rangeBoundaries.get((int) rangeId + 1);
        // the range's start will be set within the transaction
        RangeRequest range = RangeRequest.builder().endRowExclusive(end).batchHint(readBatchSize).retainColumns(columnSelection).build();
        Callable<Void> task = createMigrationTask(range, rangeId);
        Callable<Void> wrappedTask = PTExecutors.wrap(task);
        Future<Void> future = executor.submit(wrappedTask);
        futures.add(future);
    }
    waitForFutures(futures);
    progress.taskComplete();
}
Also used : RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Future(java.util.concurrent.Future)

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