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());
}
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"));
}
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);
}
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;
}
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"));
}
Aggregations