Search in sources :

Example 21 with SweepResults

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

the class AbstractSweepTaskRunnerTest method testSweepManyValuesThorough.

@Test(timeout = 50000)
public void testSweepManyValuesThorough() {
    createTable(SweepStrategy.THOROUGH);
    putIntoDefaultColumn("foo", "bar", 50);
    putUncommitted("foo", "bad", 75);
    putIntoDefaultColumn("foo", "baz", 100);
    putIntoDefaultColumn("foo", "buzz", 125);
    putUncommitted("foo", "foo", 150);
    SweepResults results = completeSweep(175).get();
    assertEquals(4, results.getStaleValuesDeleted());
    assertThat(results.getCellTsPairsExamined()).isGreaterThanOrEqualTo(5);
    assertEquals("buzz", getFromDefaultColumn("foo", 200));
    assertNull(getFromDefaultColumn("foo", 124));
    assertEquals(ImmutableSet.of(125L), getAllTsFromDefaultColumn("foo"));
}
Also used : SweepResults(com.palantir.atlasdb.keyvalue.api.SweepResults) ImmutableSweepResults(com.palantir.atlasdb.keyvalue.api.ImmutableSweepResults) Test(org.junit.Test)

Example 22 with SweepResults

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

the class AbstractSweepTaskRunnerTest method partialSweep.

private SweepResults partialSweep(long ts) {
    sweepTimestamp.set(ts);
    SweepResults results = sweepRunner.run(TABLE_NAME, ImmutableSweepBatchConfig.builder().deleteBatchSize(1).candidateBatchSize(1).maxCellTsPairsToExamine(1).build(), PtBytes.EMPTY_BYTE_ARRAY);
    assertTrue(results.getNextStartRow().isPresent());
    return results;
}
Also used : SweepResults(com.palantir.atlasdb.keyvalue.api.SweepResults) ImmutableSweepResults(com.palantir.atlasdb.keyvalue.api.ImmutableSweepResults)

Example 23 with SweepResults

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

the class AbstractSweepTaskRunnerTest method testSweepBatchesInDifferentRows.

@Test(timeout = 50000)
public void testSweepBatchesInDifferentRows() {
    CellsSweeper cellsSweeper = Mockito.mock(CellsSweeper.class);
    SweepTaskRunner spiedSweepRunner = new SweepTaskRunner(kvs, tsSupplier, tsSupplier, txService, ssm, cellsSweeper);
    putTwoValuesInEachCell(BIG_LIST_OF_CELLS_IN_DIFFERENT_ROWS);
    int deleteBatchSize = 2;
    Pair<List<List<Cell>>, SweepResults> sweptCellsAndSweepResults = runSweep(cellsSweeper, spiedSweepRunner, 10, 1, deleteBatchSize);
    List<List<Cell>> sweptCells = sweptCellsAndSweepResults.getLhSide();
    SweepResults sweepResults = sweptCellsAndSweepResults.getRhSide();
    assertThat(Iterables.concat(sweptCells)).containsExactlyElementsOf(BIG_LIST_OF_CELLS_IN_DIFFERENT_ROWS);
    for (List<Cell> sweptBatch : sweptCells.subList(0, sweptCells.size() - 1)) {
        // We requested deleteBatchSize = 2, so we expect between 2 and 4 timestamps deleted at a time.
        // We also expect a single timestamp to be swept per each cell.
        assertThat(sweptBatch.size()).isBetween(deleteBatchSize, 2 * deleteBatchSize);
    }
    // The last batch can be smaller than deleteBatchSize
    assertThat(sweptCells.get(sweptCells.size() - 1).size()).isLessThanOrEqualTo(2 * deleteBatchSize);
    assertEquals("Expected Ts Pairs Examined should add up to entire table (2 values in each cell)", 2 * BIG_LIST_OF_CELLS_IN_DIFFERENT_ROWS.size(), sweepResults.getCellTsPairsExamined());
}
Also used : SweepResults(com.palantir.atlasdb.keyvalue.api.SweepResults) ImmutableSweepResults(com.palantir.atlasdb.keyvalue.api.ImmutableSweepResults) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Test(org.junit.Test)

Example 24 with SweepResults

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

the class AbstractSweepTest method testSweepOnMixedCaseTable.

@Test(timeout = 50000)
public void testSweepOnMixedCaseTable() {
    TableReference mixedCaseTable = TableReference.create(Namespace.create("someNamespace"), "someTable");
    createTable(mixedCaseTable, SweepStrategy.CONSERVATIVE);
    put(mixedCaseTable, "row", "col", "val", 10);
    put(mixedCaseTable, "row", "col", "val", 20);
    Optional<SweepResults> optResults = completeSweep(mixedCaseTable, 30);
    optResults.ifPresent(results -> {
        assertEquals(1, results.getStaleValuesDeleted());
        assertThat(results.getCellTsPairsExamined()).isGreaterThanOrEqualTo(2);
    });
}
Also used : TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) SweepResults(com.palantir.atlasdb.keyvalue.api.SweepResults) Test(org.junit.Test)

Example 25 with SweepResults

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

SweepResults (com.palantir.atlasdb.keyvalue.api.SweepResults)27 Test (org.junit.Test)16 ImmutableSweepResults (com.palantir.atlasdb.keyvalue.api.ImmutableSweepResults)15 Cell (com.palantir.atlasdb.keyvalue.api.Cell)4 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)4 List (java.util.List)4 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableSweepBatchConfig (com.palantir.atlasdb.sweep.ImmutableSweepBatchConfig)3 SweepBatchConfig (com.palantir.atlasdb.sweep.SweepBatchConfig)3 SweepTaskRunner (com.palantir.atlasdb.sweep.SweepTaskRunner)3 ArrayList (java.util.ArrayList)3 Stopwatch (com.google.common.base.Stopwatch)2 AtlasDbConstants (com.palantir.atlasdb.AtlasDbConstants)2 PtBytes (com.palantir.atlasdb.encoding.PtBytes)2 LoggingArgs (com.palantir.atlasdb.logging.LoggingArgs)2 AbstractSweepTaskRunnerTest (com.palantir.atlasdb.sweep.AbstractSweepTaskRunnerTest)2 UnsafeArg (com.palantir.logsafe.UnsafeArg)2 Arrays (java.util.Arrays)2 Optional (java.util.Optional)2 TimeUnit (java.util.concurrent.TimeUnit)2