Search in sources :

Example 16 with RowResult

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

the class ScrubQueueMigrationCommand method run.

public static void run(KeyValueService kvs, PrintWriter output, int batchSize) {
    Context context = new Context(kvs, output, batchSize);
    // top version of each cell until the entire queue is drained.
    for (int i = 0; ; i++) {
        output.println("Starting iteration " + i + " of scrub migration.");
        Stopwatch watch = Stopwatch.createStarted();
        try (ClosableIterator<RowResult<Value>> iter = kvs.getRange(AtlasDbConstants.OLD_SCRUB_TABLE, RangeRequest.all(), Long.MAX_VALUE)) {
            if (!iter.hasNext()) {
                output.println("Finished all iterations of scrub migration.");
                break;
            }
            runOnce(context, iter);
        }
        output.println("Finished iteration " + i + " of scrub migration in " + watch.elapsed(TimeUnit.SECONDS) + " seconds.");
    }
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) Stopwatch(com.google.common.base.Stopwatch)

Example 17 with RowResult

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

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

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

the class SchemaApiTestV2Table method getColumn2.

/**
 * Returns a mapping from the specified row keys to their value at column Column2.
 * As the Column2 values are all loaded in memory, do not use for large amounts of data.
 * If the column does not exist for a key, the entry will be omitted from the map.
 */
public Map<String, StringValue> getColumn2(Iterable<String> rowKeys) {
    ColumnSelection colSelection = ColumnSelection.create(ImmutableList.of(PtBytes.toCachedBytes("d")));
    List<SchemaApiTestTable.SchemaApiTestRow> rows = Lists.newArrayList(rowKeys).stream().map(SchemaApiTestTable.SchemaApiTestRow::of).collect(Collectors.toList());
    SortedMap<byte[], RowResult<byte[]>> results = t.getRows(tableRef, Persistables.persistAll(rows), colSelection);
    return results.values().stream().map(entry -> SchemaApiTestTable.SchemaApiTestRowResult.of(entry)).collect(Collectors.toMap(entry -> entry.getRowName().getComponent1(), SchemaApiTestTable.SchemaApiTestRowResult::getColumn2));
}
Also used : StringValue(com.palantir.atlasdb.table.description.test.StringValue) Persistables(com.palantir.common.persist.Persistables) Function(java.util.function.Function) PtBytes(com.palantir.atlasdb.encoding.PtBytes) Iterable(java.lang.Iterable) LinkedHashMap(java.util.LinkedHashMap) Generated(javax.annotation.Generated) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) ColumnValues(com.palantir.atlasdb.table.generation.ColumnValues) Long(java.lang.Long) Map(java.util.Map) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) String(java.lang.String) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) ImmutableSet(com.google.common.collect.ImmutableSet) Namespace(com.palantir.atlasdb.keyvalue.api.Namespace) SuppressWarnings(java.lang.SuppressWarnings) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Set(java.util.Set) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) Objects(java.util.Objects) List(java.util.List) Transaction(com.palantir.atlasdb.transaction.api.Transaction) BatchingVisitableView(com.palantir.common.base.BatchingVisitableView) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) SortedMap(java.util.SortedMap) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult)

Example 20 with RowResult

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

the class SchemaApiTestV2Table method getColumn1.

/**
 * Returns a mapping from the specified row keys to their value at column Column1.
 * As the Column1 values are all loaded in memory, do not use for large amounts of data.
 * If the column does not exist for a key, the entry will be omitted from the map.
 */
public Map<String, Long> getColumn1(Iterable<String> rowKeys) {
    ColumnSelection colSelection = ColumnSelection.create(ImmutableList.of(PtBytes.toCachedBytes("c")));
    List<SchemaApiTestTable.SchemaApiTestRow> rows = Lists.newArrayList(rowKeys).stream().map(SchemaApiTestTable.SchemaApiTestRow::of).collect(Collectors.toList());
    SortedMap<byte[], RowResult<byte[]>> results = t.getRows(tableRef, Persistables.persistAll(rows), colSelection);
    return results.values().stream().map(entry -> SchemaApiTestTable.SchemaApiTestRowResult.of(entry)).collect(Collectors.toMap(entry -> entry.getRowName().getComponent1(), SchemaApiTestTable.SchemaApiTestRowResult::getColumn1));
}
Also used : StringValue(com.palantir.atlasdb.table.description.test.StringValue) Persistables(com.palantir.common.persist.Persistables) Function(java.util.function.Function) PtBytes(com.palantir.atlasdb.encoding.PtBytes) Iterable(java.lang.Iterable) LinkedHashMap(java.util.LinkedHashMap) Generated(javax.annotation.Generated) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) ColumnValues(com.palantir.atlasdb.table.generation.ColumnValues) Long(java.lang.Long) Map(java.util.Map) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) String(java.lang.String) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) ImmutableSet(com.google.common.collect.ImmutableSet) Namespace(com.palantir.atlasdb.keyvalue.api.Namespace) SuppressWarnings(java.lang.SuppressWarnings) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Set(java.util.Set) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) Objects(java.util.Objects) List(java.util.List) Transaction(com.palantir.atlasdb.transaction.api.Transaction) BatchingVisitableView(com.palantir.common.base.BatchingVisitableView) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) SortedMap(java.util.SortedMap) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult)

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