Search in sources :

Example 1 with SweepMetricsManager

use of com.palantir.atlasdb.sweep.metrics.SweepMetricsManager in project atlasdb by palantir.

the class TransactionManagers method initializeSweepEndpointAndBackgroundProcess.

private static BackgroundSweeperImpl initializeSweepEndpointAndBackgroundProcess(AtlasDbConfig config, Supplier<AtlasDbRuntimeConfig> runtimeConfigSupplier, Consumer<Object> env, KeyValueService kvs, TransactionService transactionService, SweepStrategyManager sweepStrategyManager, CleanupFollower follower, SerializableTransactionManager transactionManager, PersistentLockManager persistentLockManager) {
    CellsSweeper cellsSweeper = new CellsSweeper(transactionManager, kvs, persistentLockManager, ImmutableList.of(follower));
    SweepMetricsManager sweepMetricsManager = new SweepMetricsManager();
    SweepTaskRunner sweepRunner = new SweepTaskRunner(kvs, transactionManager::getUnreadableTimestamp, transactionManager::getImmutableTimestamp, transactionService, sweepStrategyManager, cellsSweeper, sweepMetricsManager);
    BackgroundSweeperPerformanceLogger sweepPerfLogger = new NoOpBackgroundSweeperPerformanceLogger();
    AdjustableSweepBatchConfigSource sweepBatchConfigSource = AdjustableSweepBatchConfigSource.create(() -> getSweepBatchConfig(runtimeConfigSupplier.get().sweep(), config.keyValueService()));
    SweepMetricsManager sweepMetrics = new SweepMetricsManager();
    SpecificTableSweeper specificTableSweeper = initializeSweepEndpoint(env, kvs, transactionManager, sweepRunner, sweepPerfLogger, sweepMetrics, config.initializeAsync(), sweepBatchConfigSource);
    BackgroundSweeperImpl backgroundSweeper = BackgroundSweeperImpl.create(sweepBatchConfigSource, () -> runtimeConfigSupplier.get().sweep().enabled(), () -> runtimeConfigSupplier.get().sweep().pauseMillis(), persistentLockManager, specificTableSweeper);
    transactionManager.registerClosingCallback(backgroundSweeper::shutdown);
    backgroundSweeper.runInBackground();
    return backgroundSweeper;
}
Also used : BackgroundSweeperImpl(com.palantir.atlasdb.sweep.BackgroundSweeperImpl) AdjustableSweepBatchConfigSource(com.palantir.atlasdb.sweep.AdjustableSweepBatchConfigSource) SpecificTableSweeper(com.palantir.atlasdb.sweep.SpecificTableSweeper) CellsSweeper(com.palantir.atlasdb.sweep.CellsSweeper) NoOpBackgroundSweeperPerformanceLogger(com.palantir.atlasdb.sweep.NoOpBackgroundSweeperPerformanceLogger) SweepMetricsManager(com.palantir.atlasdb.sweep.metrics.SweepMetricsManager) SweepTaskRunner(com.palantir.atlasdb.sweep.SweepTaskRunner) NoOpBackgroundSweeperPerformanceLogger(com.palantir.atlasdb.sweep.NoOpBackgroundSweeperPerformanceLogger) BackgroundSweeperPerformanceLogger(com.palantir.atlasdb.sweep.BackgroundSweeperPerformanceLogger)

Example 2 with SweepMetricsManager

use of com.palantir.atlasdb.sweep.metrics.SweepMetricsManager 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 3 with SweepMetricsManager

use of com.palantir.atlasdb.sweep.metrics.SweepMetricsManager in project atlasdb by palantir.

the class AbstractBackgroundSweeperIntegrationTest method setup.

@Before
public void setup() {
    TimestampService tsService = new InMemoryTimestampService();
    kvs = SweepStatsKeyValueService.create(getKeyValueService(), tsService, () -> AtlasDbConstants.DEFAULT_SWEEP_WRITE_THRESHOLD, () -> AtlasDbConstants.DEFAULT_SWEEP_WRITE_SIZE_THRESHOLD);
    SweepStrategyManager ssm = SweepStrategyManagers.createDefault(kvs);
    txService = TransactionServices.createTransactionService(kvs);
    txManager = SweepTestUtils.setupTxManager(kvs, tsService, ssm, txService);
    LongSupplier tsSupplier = sweepTimestamp::get;
    PersistentLockManager persistentLockManager = new PersistentLockManager(SweepTestUtils.getPersistentLockService(kvs), AtlasDbConstants.DEFAULT_SWEEP_PERSISTENT_LOCK_WAIT_MILLIS);
    CellsSweeper cellsSweeper = new CellsSweeper(txManager, kvs, persistentLockManager, ImmutableList.of());
    SweepTaskRunner sweepRunner = new SweepTaskRunner(kvs, tsSupplier, tsSupplier, txService, ssm, cellsSweeper);
    SweepMetricsManager sweepMetricsManager = new SweepMetricsManager();
    specificTableSweeper = SpecificTableSweeper.create(txManager, kvs, sweepRunner, SweepTableFactory.of(), new NoOpBackgroundSweeperPerformanceLogger(), sweepMetricsManager, false);
    sweepBatchConfigSource = AdjustableSweepBatchConfigSource.create(() -> sweepBatchConfig);
    backgroundSweeper = BackgroundSweeperImpl.create(sweepBatchConfigSource, // sweepEnabled
    () -> true, // sweepPauseMillis
    () -> 10L, persistentLockManager, specificTableSweeper);
}
Also used : SweepStrategyManager(com.palantir.atlasdb.transaction.impl.SweepStrategyManager) InMemoryTimestampService(com.palantir.timestamp.InMemoryTimestampService) LongSupplier(java.util.function.LongSupplier) SweepMetricsManager(com.palantir.atlasdb.sweep.metrics.SweepMetricsManager) InMemoryTimestampService(com.palantir.timestamp.InMemoryTimestampService) TimestampService(com.palantir.timestamp.TimestampService) Before(org.junit.Before)

Aggregations

SweepMetricsManager (com.palantir.atlasdb.sweep.metrics.SweepMetricsManager)3 Stopwatch (com.google.common.base.Stopwatch)1 CandidateCellForSweepingRequest (com.palantir.atlasdb.keyvalue.api.CandidateCellForSweepingRequest)1 ImmutableCandidateCellForSweepingRequest (com.palantir.atlasdb.keyvalue.api.ImmutableCandidateCellForSweepingRequest)1 AdjustableSweepBatchConfigSource (com.palantir.atlasdb.sweep.AdjustableSweepBatchConfigSource)1 BackgroundSweeperImpl (com.palantir.atlasdb.sweep.BackgroundSweeperImpl)1 BackgroundSweeperPerformanceLogger (com.palantir.atlasdb.sweep.BackgroundSweeperPerformanceLogger)1 CellsSweeper (com.palantir.atlasdb.sweep.CellsSweeper)1 ExaminedCellLimit (com.palantir.atlasdb.sweep.CellsToSweepPartitioningIterator.ExaminedCellLimit)1 NoOpBackgroundSweeperPerformanceLogger (com.palantir.atlasdb.sweep.NoOpBackgroundSweeperPerformanceLogger)1 SpecificTableSweeper (com.palantir.atlasdb.sweep.SpecificTableSweeper)1 SweepTaskRunner (com.palantir.atlasdb.sweep.SweepTaskRunner)1 SweepStrategyManager (com.palantir.atlasdb.transaction.impl.SweepStrategyManager)1 InMemoryTimestampService (com.palantir.timestamp.InMemoryTimestampService)1 TimestampService (com.palantir.timestamp.TimestampService)1 List (java.util.List)1 LongSupplier (java.util.function.LongSupplier)1 Before (org.junit.Before)1