Search in sources :

Example 1 with CandidateCellForSweepingRequest

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

the class SweepTaskRunner method doRun.

private SweepResults doRun(TableReference tableRef, SweepBatchConfig batchConfig, byte[] startRow, RunType runType, Sweeper sweeper) {
    Stopwatch watch = Stopwatch.createStarted();
    long timeSweepStarted = System.currentTimeMillis();
    log.info("Beginning iteration of sweep for table {} starting at row {}", LoggingArgs.tableRef(tableRef), UnsafeArg.of("startRow", PtBytes.encodeHexString(startRow)));
    // Earliest start timestamp of any currently open transaction, with two caveats:
    // (1) unreadableTimestamps are calculated via wall-clock time, and so may not be correct
    // under pathological clock conditions
    // (2) immutableTimestamps do not account for locks have timed out after checking their locks;
    // such a transaction may have a start timestamp less than the immutableTimestamp, and it
    // could still get successfully committed (its commit timestamp may or may not be less than
    // the immutableTimestamp
    // Note that this is fine, because we'll either
    // (1) force old readers to abort (if they read a garbage collection sentinel), or
    // (2) force old writers to retry (note that we must roll back any uncommitted transactions that
    // we encounter
    long sweepTs = sweeper.getSweepTimestampSupplier().getSweepTimestamp(unreadableTimestampSupplier, immutableTimestampSupplier);
    CandidateCellForSweepingRequest request = ImmutableCandidateCellForSweepingRequest.builder().startRowInclusive(startRow).batchSizeHint(batchConfig.candidateBatchSize()).maxTimestampExclusive(sweepTs).shouldCheckIfLatestValueIsEmpty(sweeper.shouldSweepLastCommitted()).shouldDeleteGarbageCollectionSentinels(!sweeper.shouldAddSentinels()).build();
    SweepableCellFilter sweepableCellFilter = new SweepableCellFilter(transactionService, sweeper, sweepTs);
    try (ClosableIterator<List<CandidateCellForSweeping>> candidates = keyValueService.getCandidateCellsForSweeping(tableRef, request)) {
        ExaminedCellLimit limit = new ExaminedCellLimit(startRow, batchConfig.maxCellTsPairsToExamine());
        Iterator<BatchOfCellsToSweep> batchesToSweep = getBatchesToSweep(candidates, batchConfig, sweepableCellFilter, limit);
        long totalCellTsPairsExamined = 0;
        long totalCellTsPairsDeleted = 0;
        metricsManager.ifPresent(SweepMetricsManager::resetBeforeDeleteBatch);
        byte[] lastRow = startRow;
        while (batchesToSweep.hasNext()) {
            BatchOfCellsToSweep batch = batchesToSweep.next();
            /*
                 * At this point cells were merged in batches of at least deleteBatchSize blocks per batch. Therefore we
                 * expect most batches to have slightly more than deleteBatchSize blocks. Partitioning such batches with
                 * deleteBatchSize as a limit results in a small second batch, which is bad for performance reasons.
                 * Therefore, deleteBatchSize is doubled.
                 */
            long cellsDeleted = sweepBatch(tableRef, batch.cells(), runType, 2 * batchConfig.deleteBatchSize());
            totalCellTsPairsDeleted += cellsDeleted;
            long cellsExamined = batch.numCellTsPairsExamined();
            totalCellTsPairsExamined += cellsExamined;
            metricsManager.ifPresent(manager -> manager.updateAfterDeleteBatch(cellsExamined, cellsDeleted));
            lastRow = batch.lastCellExamined().getRowName();
        }
        return SweepResults.builder().previousStartRow(Optional.of(startRow)).nextStartRow(Arrays.equals(startRow, lastRow) ? Optional.empty() : Optional.of(lastRow)).cellTsPairsExamined(totalCellTsPairsExamined).staleValuesDeleted(totalCellTsPairsDeleted).minSweptTimestamp(sweepTs).timeInMillis(watch.elapsed(TimeUnit.MILLISECONDS)).timeSweepStarted(timeSweepStarted).build();
    }
}
Also used : ExaminedCellLimit(com.palantir.atlasdb.sweep.CellsToSweepPartitioningIterator.ExaminedCellLimit) ImmutableCandidateCellForSweepingRequest(com.palantir.atlasdb.keyvalue.api.ImmutableCandidateCellForSweepingRequest) CandidateCellForSweepingRequest(com.palantir.atlasdb.keyvalue.api.CandidateCellForSweepingRequest) Stopwatch(com.google.common.base.Stopwatch) List(java.util.List) SweepMetricsManager(com.palantir.atlasdb.sweep.metrics.SweepMetricsManager)

Example 2 with CandidateCellForSweepingRequest

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

the class KvsGetCandidateCellsForSweepingBenchmarks method fullTableScan.

private int fullTableScan(TableReference tableRef, KeyValueService kvs, int numCellsExpected, boolean thorough) {
    CandidateCellForSweepingRequest request = ImmutableCandidateCellForSweepingRequest.builder().startRowInclusive(PtBytes.EMPTY_BYTE_ARRAY).batchSizeHint(1000).maxTimestampExclusive(Long.MAX_VALUE).shouldCheckIfLatestValueIsEmpty(thorough).shouldDeleteGarbageCollectionSentinels(thorough).build();
    try (ClosableIterator<List<CandidateCellForSweeping>> iter = kvs.getCandidateCellsForSweeping(tableRef, request)) {
        int numCandidates = Iterators.size(Iterators.concat(Iterators.transform(iter, List::iterator)));
        Preconditions.checkState(numCandidates == numCellsExpected, "Number of candidates %s != %s", numCandidates, numCellsExpected);
        return numCandidates;
    }
}
Also used : CandidateCellForSweepingRequest(com.palantir.atlasdb.keyvalue.api.CandidateCellForSweepingRequest) ImmutableCandidateCellForSweepingRequest(com.palantir.atlasdb.keyvalue.api.ImmutableCandidateCellForSweepingRequest) List(java.util.List)

Aggregations

CandidateCellForSweepingRequest (com.palantir.atlasdb.keyvalue.api.CandidateCellForSweepingRequest)2 ImmutableCandidateCellForSweepingRequest (com.palantir.atlasdb.keyvalue.api.ImmutableCandidateCellForSweepingRequest)2 List (java.util.List)2 Stopwatch (com.google.common.base.Stopwatch)1 ExaminedCellLimit (com.palantir.atlasdb.sweep.CellsToSweepPartitioningIterator.ExaminedCellLimit)1 SweepMetricsManager (com.palantir.atlasdb.sweep.metrics.SweepMetricsManager)1