Search in sources :

Example 16 with SweepResults

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

the class AbstractSweepTaskRunnerTest method testSweepBatches.

@Test(timeout = 50000)
public void testSweepBatches() {
    CellsSweeper cellsSweeper = Mockito.mock(CellsSweeper.class);
    SweepTaskRunner spiedSweepRunner = new SweepTaskRunner(kvs, tsSupplier, tsSupplier, txService, ssm, cellsSweeper);
    putTwoValuesInEachCell(BIG_LIST_OF_CELLS);
    int deleteBatchSize = 2;
    Pair<List<List<Cell>>, SweepResults> sweptCellsAndSweepResults = runSweep(cellsSweeper, spiedSweepRunner, 1000, 1, deleteBatchSize);
    List<List<Cell>> sweptCells = sweptCellsAndSweepResults.getLhSide();
    SweepResults sweepResults = sweptCellsAndSweepResults.getRhSide();
    assertThat(Iterables.concat(sweptCells)).containsExactlyElementsOf(BIG_LIST_OF_CELLS);
    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.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 17 with SweepResults

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

the class AbstractSweepTaskRunnerTest method testSweepUncommittedConservative.

@Test(timeout = 50000)
public void testSweepUncommittedConservative() {
    createTable(SweepStrategy.CONSERVATIVE);
    putIntoDefaultColumn("foo", "bar", 50);
    putUncommitted("foo", "baz", 100);
    SweepResults results = completeSweep(175).get();
    assertEquals(1, results.getStaleValuesDeleted());
    assertThat(results.getCellTsPairsExamined()).isGreaterThanOrEqualTo(2);
    assertEquals("bar", getFromDefaultColumn("foo", 750));
    assertEquals(ImmutableSet.of(50L), getAllTsFromDefaultColumn("foo"));
}
Also used : SweepResults(com.palantir.atlasdb.keyvalue.api.SweepResults) ImmutableSweepResults(com.palantir.atlasdb.keyvalue.api.ImmutableSweepResults) Test(org.junit.Test)

Example 18 with SweepResults

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

the class AbstractSweepTaskRunnerTest method runSweep.

@SuppressWarnings("unchecked")
private Pair<List<List<Cell>>, SweepResults> runSweep(CellsSweeper cellsSweeper, SweepTaskRunner spiedSweepRunner, int maxCellTsPairsToExamine, int candidateBatchSize, int deleteBatchSize) {
    sweepTimestamp.set(Long.MAX_VALUE);
    List<List<Cell>> sweptCells = Lists.newArrayList();
    doAnswer((invocationOnMock) -> {
        Object[] arguments = invocationOnMock.getArguments();
        Collection<Cell> sentinelsToAdd = (Collection<Cell>) arguments[2];
        sweptCells.add(new ArrayList(sentinelsToAdd));
        return null;
    }).when(cellsSweeper).sweepCells(eq(TABLE_NAME), any(), any());
    SweepResults sweepResults = spiedSweepRunner.run(TABLE_NAME, ImmutableSweepBatchConfig.builder().maxCellTsPairsToExamine(maxCellTsPairsToExamine).candidateBatchSize(candidateBatchSize).deleteBatchSize(deleteBatchSize).build(), PtBytes.EMPTY_BYTE_ARRAY);
    return new Pair(sweptCells, sweepResults);
}
Also used : SweepResults(com.palantir.atlasdb.keyvalue.api.SweepResults) ImmutableSweepResults(com.palantir.atlasdb.keyvalue.api.ImmutableSweepResults) ArrayList(java.util.ArrayList) Collection(java.util.Collection) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Pair(com.palantir.util.Pair)

Example 19 with SweepResults

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

the class AbstractSweepTaskRunnerTest method completeSweep.

protected Optional<SweepResults> completeSweep(TableReference tableReference, long ts) {
    sweepTimestamp.set(ts);
    byte[] startRow = PtBytes.EMPTY_BYTE_ARRAY;
    long totalStaleValuesDeleted = 0;
    long totalCellsExamined = 0;
    for (int run = 0; run < 100; ++run) {
        SweepResults results = sweepRunner.run(tableReference, ImmutableSweepBatchConfig.builder().deleteBatchSize(DEFAULT_BATCH_SIZE).candidateBatchSize(DEFAULT_BATCH_SIZE).maxCellTsPairsToExamine(DEFAULT_BATCH_SIZE).build(), startRow);
        assertEquals(ts, results.getMinSweptTimestamp());
        assertArrayEquals(startRow, results.getPreviousStartRow().orElse(null));
        totalStaleValuesDeleted += results.getStaleValuesDeleted();
        totalCellsExamined += results.getCellTsPairsExamined();
        if (!results.getNextStartRow().isPresent()) {
            return Optional.of(ImmutableSweepResults.builder().staleValuesDeleted(totalStaleValuesDeleted).cellTsPairsExamined(totalCellsExamined).timeInMillis(1).timeSweepStarted(1).minSweptTimestamp(ts).build());
        }
        startRow = results.getNextStartRow().get();
    }
    fail("failed to completely sweep a table in 100 runs");
    // should never be reached
    return null;
}
Also used : SweepResults(com.palantir.atlasdb.keyvalue.api.SweepResults) ImmutableSweepResults(com.palantir.atlasdb.keyvalue.api.ImmutableSweepResults)

Example 20 with SweepResults

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

the class AbstractSweepTaskRunnerTest method testSweepManyLatestDeletedThoroughIncludingUncommitted1.

@Test(timeout = 50000)
public void testSweepManyLatestDeletedThoroughIncludingUncommitted1() {
    createTable(SweepStrategy.THOROUGH);
    putIntoDefaultColumn("foo", "bar", 50);
    putUncommitted("foo", "bad", 75);
    putIntoDefaultColumn("foo", "baz", 100);
    putIntoDefaultColumn("foo", "", 125);
    putUncommitted("foo", "foo", 150);
    putIntoDefaultColumn("zzz", "bar", 51);
    SweepResults results = completeSweep(175).get();
    assertEquals(4, results.getStaleValuesDeleted());
    assertThat(results.getCellTsPairsExamined()).isGreaterThanOrEqualTo(6);
    // this check is a nuance of SweepTaskRunner: the value at timestamp 125 is actually eligible for deletion,
    // but we don't delete it on the first pass due to the later uncommitted value. below we sweep again and make
    // sure it's deleted
    assertEquals("", getFromDefaultColumn("foo", 200));
    assertEquals(ImmutableSet.of(125L), getAllTsFromDefaultColumn("foo"));
    results = completeSweep(175).get();
    assertEquals(1, results.getStaleValuesDeleted());
    assertThat(results.getCellTsPairsExamined()).isGreaterThanOrEqualTo(2);
    assertNull(getFromDefaultColumn("foo", 200));
    assertEquals(ImmutableSet.of(), getAllTsFromDefaultColumn("foo"));
}
Also used : SweepResults(com.palantir.atlasdb.keyvalue.api.SweepResults) ImmutableSweepResults(com.palantir.atlasdb.keyvalue.api.ImmutableSweepResults) Test(org.junit.Test)

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