Search in sources :

Example 1 with SweepTaskRunner

use of com.palantir.atlasdb.sweep.SweepTaskRunner in project atlasdb by palantir.

the class TestSweeperModule method provideSweepTaskRunner.

@Provides
@Singleton
public SweepTaskRunner provideSweepTaskRunner(SerializableTransactionManager txm, @Named("kvs") KeyValueService kvs, TransactionService transactionService, SweepStrategyManager sweepStrategyManager, Follower follower, PersistentLockManager persistentLockManager, ServicesConfig config) {
    LongSupplier unreadable = unreadableTs.orElse(txm::getUnreadableTimestamp);
    LongSupplier immutable = immutableTs.orElse(txm::getImmutableTimestamp);
    return new SweepTaskRunner(kvs, unreadable, immutable, transactionService, sweepStrategyManager, new CellsSweeper(txm, kvs, persistentLockManager, ImmutableList.of(follower)));
}
Also used : CellsSweeper(com.palantir.atlasdb.sweep.CellsSweeper) LongSupplier(java.util.function.LongSupplier) SweepTaskRunner(com.palantir.atlasdb.sweep.SweepTaskRunner) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Example 2 with SweepTaskRunner

use of com.palantir.atlasdb.sweep.SweepTaskRunner in project atlasdb by palantir.

the class SweepBenchmarks method runSingleSweep.

private Object runSingleSweep(RegeneratingTable table, int uniqueCellsToSweep) {
    SweepTaskRunner sweepTaskRunner = table.getSweepTaskRunner();
    SweepBatchConfig batchConfig = ImmutableSweepBatchConfig.builder().deleteBatchSize(DELETED_COUNT * uniqueCellsToSweep).candidateBatchSize(RegeneratingTable.SWEEP_DUPLICATES * uniqueCellsToSweep + 1).maxCellTsPairsToExamine(RegeneratingTable.SWEEP_DUPLICATES * uniqueCellsToSweep).build();
    SweepResults sweepResults = sweepTaskRunner.run(table.getTableRef(), batchConfig, PtBytes.EMPTY_BYTE_ARRAY);
    assertThat(sweepResults.getStaleValuesDeleted(), is((long) DELETED_COUNT * uniqueCellsToSweep));
    return sweepResults;
}
Also used : SweepBatchConfig(com.palantir.atlasdb.sweep.SweepBatchConfig) ImmutableSweepBatchConfig(com.palantir.atlasdb.sweep.ImmutableSweepBatchConfig) SweepResults(com.palantir.atlasdb.keyvalue.api.SweepResults) SweepTaskRunner(com.palantir.atlasdb.sweep.SweepTaskRunner)

Example 3 with SweepTaskRunner

use of com.palantir.atlasdb.sweep.SweepTaskRunner in project atlasdb by palantir.

the class SweepBenchmarks method runMultiSweep.

private Object runMultiSweep(RegeneratingTable table) {
    SweepTaskRunner sweepTaskRunner = table.getSweepTaskRunner();
    SweepResults sweepResults = null;
    byte[] nextStartRow = PtBytes.EMPTY_BYTE_ARRAY;
    for (int i = 0; i < BATCH_SIZE; i++) {
        SweepBatchConfig batchConfig = ImmutableSweepBatchConfig.builder().deleteBatchSize(DELETED_COUNT).candidateBatchSize(1).maxCellTsPairsToExamine(RegeneratingTable.SWEEP_DUPLICATES).build();
        sweepResults = sweepTaskRunner.run(table.getTableRef(), batchConfig, nextStartRow);
        nextStartRow = sweepResults.getNextStartRow().get();
        assertThat(sweepResults.getStaleValuesDeleted(), is((long) DELETED_COUNT));
    }
    return sweepResults;
}
Also used : SweepBatchConfig(com.palantir.atlasdb.sweep.SweepBatchConfig) ImmutableSweepBatchConfig(com.palantir.atlasdb.sweep.ImmutableSweepBatchConfig) SweepResults(com.palantir.atlasdb.keyvalue.api.SweepResults) SweepTaskRunner(com.palantir.atlasdb.sweep.SweepTaskRunner)

Example 4 with SweepTaskRunner

use of com.palantir.atlasdb.sweep.SweepTaskRunner 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 5 with SweepTaskRunner

use of com.palantir.atlasdb.sweep.SweepTaskRunner in project atlasdb by palantir.

the class SweepCommand method execute.

@Override
public int execute(final AtlasDbServices services) {
    SweepTaskRunner sweepRunner = services.getSweepTaskRunner();
    if (!((namespace != null) ^ (table != null) ^ sweepAllTables)) {
        printer.error("Specify one of --namespace, --table, or --all options.");
        return 1;
    }
    if ((namespace != null) && (row != null)) {
        printer.error("Cannot specify a start row (" + row + ") when sweeping multiple tables (in namespace " + namespace + ")");
        return 1;
    }
    Map<TableReference, byte[]> tableToStartRow = Maps.newHashMap();
    if (table != null) {
        TableReference tableToSweep = TableReference.createUnsafe(table);
        if (!services.getKeyValueService().getAllTableNames().contains(tableToSweep)) {
            printer.info("The table {} passed in to sweep does not exist", LoggingArgs.tableRef(tableToSweep));
            return 1;
        }
        byte[] startRow = PtBytes.EMPTY_BYTE_ARRAY;
        if (row != null) {
            startRow = decodeStartRow(row);
        }
        tableToStartRow.put(tableToSweep, startRow);
    } else if (namespace != null) {
        Set<TableReference> tablesInNamespace = services.getKeyValueService().getAllTableNames().stream().filter(tableRef -> tableRef.getNamespace().getName().equals(namespace)).collect(Collectors.toSet());
        for (TableReference tableInNamespace : tablesInNamespace) {
            tableToStartRow.put(tableInNamespace, new byte[0]);
        }
    } else if (sweepAllTables) {
        tableToStartRow.putAll(Maps.asMap(Sets.difference(services.getKeyValueService().getAllTableNames(), AtlasDbConstants.hiddenTables), Functions.constant(new byte[0])));
    }
    SweepBatchConfig batchConfig = getSweepBatchConfig();
    for (Map.Entry<TableReference, byte[]> entry : tableToStartRow.entrySet()) {
        final TableReference tableToSweep = entry.getKey();
        SweepResults accumulatedResults = SweepResults.createEmptySweepResult(Optional.of(entry.getValue()));
        while (accumulatedResults.getNextStartRow().isPresent()) {
            SweepResults newResults = dryRun ? sweepRunner.dryRun(tableToSweep, batchConfig, accumulatedResults.getNextStartRow().get()) : sweepRunner.run(tableToSweep, batchConfig, accumulatedResults.getNextStartRow().get());
            accumulatedResults = accumulatedResults.accumulateWith(newResults);
            printer.info("{} Swept from {} to {} in table {} in {} ms, examined {} cell values," + " deleted {} stale versions of those cells. Time elapsed since started sweeping:" + " {} ms. Total time sweeping this table: {} ms.", SafeArg.of("isDryRun", dryRun ? "[DRY RUN]" : ""), UnsafeArg.of("startRow", encodeStartRow(accumulatedResults.getNextStartRow())), UnsafeArg.of("exclusiveEndRow", encodeEndRow(newResults.getNextStartRow())), LoggingArgs.tableRef(tableToSweep), SafeArg.of("time taken millis", newResults.getTimeInMillis()), SafeArg.of("cellTs pairs examined", newResults.getCellTsPairsExamined()), SafeArg.of("cellTs pairs deleted", newResults.getStaleValuesDeleted()), SafeArg.of("time elapsed", accumulatedResults.getTimeElapsedSinceStartedSweeping()), SafeArg.of("time sweeping", accumulatedResults.getTimeInMillis()));
            maybeSleep();
        }
        SweepResults finalAccumulatedResults = accumulatedResults;
        if (!dryRun) {
            services.getTransactionManager().runTaskWithRetry((TxTask) t -> {
                SweepPriorityTable priorityTable = SweepTableFactory.of().getSweepPriorityTable(t);
                SweepPriorityTable.SweepPriorityRow row1 = SweepPriorityTable.SweepPriorityRow.of(tableToSweep.getQualifiedName());
                priorityTable.putWriteCount(row1, 0L);
                priorityTable.putCellsExamined(row1, finalAccumulatedResults.getCellTsPairsExamined());
                priorityTable.putCellsDeleted(row1, finalAccumulatedResults.getStaleValuesDeleted());
                priorityTable.putLastSweepTime(row1, System.currentTimeMillis());
                return null;
            });
        }
        printer.info("{} Finished sweeping {}, examined {} cell values, deleted {} stale versions of those cells.", SafeArg.of("isDryRun", dryRun ? "[DRY RUN]" : ""), LoggingArgs.tableRef(tableToSweep), SafeArg.of("cellTs pairs examined", finalAccumulatedResults.getCellTsPairsExamined()), SafeArg.of("cellTs pairs deleted", finalAccumulatedResults.getStaleValuesDeleted()));
        if (!dryRun && finalAccumulatedResults.getStaleValuesDeleted() > 0) {
            Stopwatch watch = Stopwatch.createStarted();
            services.getKeyValueService().compactInternally(tableToSweep);
            printer.info("Finished performing compactInternally on {} in {} ms.", LoggingArgs.tableRef(tableToSweep), SafeArg.of("time taken", watch.elapsed(TimeUnit.MILLISECONDS)));
        }
    }
    return 0;
}
Also used : Arrays(java.util.Arrays) OutputPrinter(com.palantir.atlasdb.cli.output.OutputPrinter) Stopwatch(com.google.common.base.Stopwatch) Throwables(com.palantir.common.base.Throwables) LoggerFactory(org.slf4j.LoggerFactory) PtBytes(com.palantir.atlasdb.encoding.PtBytes) SafeArg(com.palantir.logsafe.SafeArg) ImmutableSweepBatchConfig(com.palantir.atlasdb.sweep.ImmutableSweepBatchConfig) Option(io.airlift.airline.Option) Map(java.util.Map) LoggingArgs(com.palantir.atlasdb.logging.LoggingArgs) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) SweepTaskRunner(com.palantir.atlasdb.sweep.SweepTaskRunner) Nullable(javax.annotation.Nullable) AtlasDbConstants(com.palantir.atlasdb.AtlasDbConstants) Functions(com.google.common.base.Functions) BaseEncoding(com.google.common.io.BaseEncoding) Set(java.util.Set) SweepResults(com.palantir.atlasdb.keyvalue.api.SweepResults) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) SweepPriorityTable(com.palantir.atlasdb.schema.generated.SweepPriorityTable) TimeUnit(java.util.concurrent.TimeUnit) SweepBatchConfig(com.palantir.atlasdb.sweep.SweepBatchConfig) Command(io.airlift.airline.Command) SweepTableFactory(com.palantir.atlasdb.schema.generated.SweepTableFactory) TxTask(com.palantir.atlasdb.transaction.impl.TxTask) UnsafeArg(com.palantir.logsafe.UnsafeArg) Optional(java.util.Optional) AtlasDbServices(com.palantir.atlasdb.services.AtlasDbServices) SweepResults(com.palantir.atlasdb.keyvalue.api.SweepResults) Set(java.util.Set) Stopwatch(com.google.common.base.Stopwatch) SweepTaskRunner(com.palantir.atlasdb.sweep.SweepTaskRunner) ImmutableSweepBatchConfig(com.palantir.atlasdb.sweep.ImmutableSweepBatchConfig) SweepBatchConfig(com.palantir.atlasdb.sweep.SweepBatchConfig) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) SweepPriorityTable(com.palantir.atlasdb.schema.generated.SweepPriorityTable) Map(java.util.Map)

Aggregations

SweepTaskRunner (com.palantir.atlasdb.sweep.SweepTaskRunner)5 SweepResults (com.palantir.atlasdb.keyvalue.api.SweepResults)3 ImmutableSweepBatchConfig (com.palantir.atlasdb.sweep.ImmutableSweepBatchConfig)3 SweepBatchConfig (com.palantir.atlasdb.sweep.SweepBatchConfig)3 CellsSweeper (com.palantir.atlasdb.sweep.CellsSweeper)2 Functions (com.google.common.base.Functions)1 Stopwatch (com.google.common.base.Stopwatch)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 BaseEncoding (com.google.common.io.BaseEncoding)1 AtlasDbConstants (com.palantir.atlasdb.AtlasDbConstants)1 OutputPrinter (com.palantir.atlasdb.cli.output.OutputPrinter)1 PtBytes (com.palantir.atlasdb.encoding.PtBytes)1 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)1 LoggingArgs (com.palantir.atlasdb.logging.LoggingArgs)1 SweepPriorityTable (com.palantir.atlasdb.schema.generated.SweepPriorityTable)1 SweepTableFactory (com.palantir.atlasdb.schema.generated.SweepTableFactory)1 AtlasDbServices (com.palantir.atlasdb.services.AtlasDbServices)1 AdjustableSweepBatchConfigSource (com.palantir.atlasdb.sweep.AdjustableSweepBatchConfigSource)1 BackgroundSweeperImpl (com.palantir.atlasdb.sweep.BackgroundSweeperImpl)1