Search in sources :

Example 56 with RowResult

use of com.palantir.atlasdb.keyvalue.api.RowResult 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 57 with RowResult

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

the class KvsRangeMigrator method internalCopyRange.

private byte[] internalCopyRange(BatchingVisitable<RowResult<byte[]>> bv, final long maxBytes, @Output final Map<Cell, byte[]> writeMap) {
    final Mutable<byte[]> lastRowName = Mutables.newMutable(null);
    final MutableLong bytesPut = new MutableLong(0L);
    bv.batchAccept(readBatchSize, AbortingVisitors.batching(// even though no exception can be thrown :-(
    new AbortingVisitor<RowResult<byte[]>, RuntimeException>() {

        @Override
        public boolean visit(RowResult<byte[]> rr) throws RuntimeException {
            return KvsRangeMigrator.this.internalCopyRow(rr, maxBytes, writeMap, bytesPut, lastRowName);
        }
    }));
    return lastRowName.get();
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) MutableLong(org.apache.commons.lang3.mutable.MutableLong) AbortingVisitor(com.palantir.common.base.AbortingVisitor)

Aggregations

RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)57 RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)40 Test (org.junit.Test)23 Cell (com.palantir.atlasdb.keyvalue.api.Cell)17 Value (com.palantir.atlasdb.keyvalue.api.Value)16 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)10 TokenBackedBasicResultsPage (com.palantir.util.paging.TokenBackedBasicResultsPage)10 Set (java.util.Set)8 ColumnSelection (com.palantir.atlasdb.keyvalue.api.ColumnSelection)7 Transaction (com.palantir.atlasdb.transaction.api.Transaction)7 SortedMap (java.util.SortedMap)7 Map (java.util.Map)6 ImmutableSet (com.google.common.collect.ImmutableSet)5 Lists (com.google.common.collect.Lists)5 AbstractPagingIterable (com.palantir.util.paging.AbstractPagingIterable)5 Entry (java.util.Map.Entry)5 ImmutableList (com.google.common.collect.ImmutableList)4 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)4 PtBytes (com.palantir.atlasdb.encoding.PtBytes)4 ClosableIterator (com.palantir.common.base.ClosableIterator)4