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();
}
}
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;
}
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();
}
Aggregations