public static SweepResults createEmptySweepResultWithMoreToSweep() { return createEmptySweepResult(Optional.of(PtBytes.EMPTY_BYTE_ARRAY)); }
public static SweepResults createEmptySweepResultWithNoMoreToSweep() { return createEmptySweepResult(Optional.empty()); }
private SweepResults runFullSweepWithoutSavingResults( TableReference tableRef, byte[] startRow, SweepBatchConfig sweepBatchConfig) { SweepResults cumulativeResults = SweepResults.createEmptySweepResult(Optional.of(startRow)); while (cumulativeResults.getNextStartRow().isPresent()) { SweepResults results = runOneBatchWithoutSavingResults( tableRef, cumulativeResults.getNextStartRow().get(), sweepBatchConfig); specificTableSweeper.updateTimeMetricsOneIteration(results.getTimeInMillis(), results.getTimeElapsedSinceStartedSweeping()); cumulativeResults = cumulativeResults.accumulateWith(results); } return cumulativeResults; }
@Test public void sweepsEntireTableByDefault() { List<byte[]> startRows = ImmutableList.of( PtBytes.EMPTY_BYTE_ARRAY, new byte[] {0x10}, new byte[] {0x50}); for (int i = 0; i < startRows.size(); i++) { byte[] currentRow = startRows.get(i); Optional<byte[]> nextRow = (i + 1) == startRows.size() ? Optional.empty() : Optional.of(startRows.get(i + 1)); SweepResults results = SweepResults.createEmptySweepResult(nextRow); when(sweepTaskRunner.run(any(), any(), eq(currentRow))).thenReturn(results); } sweeperService.sweepTableFully(TABLE_REF.getQualifiedName()); startRows.forEach(row -> verify(sweepTaskRunner).run(any(), any(), eq(row))); verifyNoMoreInteractions(sweepTaskRunner); }
@Test public void equalsIgnoresTimeSweepStarted() { SweepResults emptySweepResult = SweepResults.createEmptySweepResult(Optional.empty()); SweepResults laterEmptySweepResult = SweepResults.builder().from(emptySweepResult) .timeSweepStarted(emptySweepResult.getTimeSweepStarted() + 1) .build(); Assert.assertThat(emptySweepResult, Matchers.equalTo(laterEmptySweepResult)); } }
@Test(timeout = 50000) public void testSweeperFailsHalfwayThroughOnDeleteTable() { createTable(SweepStrategy.CONSERVATIVE); putIntoDefaultColumn("foo", "bar", 50); putIntoDefaultColumn("foo2", "bang", 75); putIntoDefaultColumn("foo3", "baz", 100); putIntoDefaultColumn("foo4", "buzz", 125); byte[] nextStartRow = partialSweep(150).getNextStartRow().get(); kvs.dropTable(TABLE_NAME); SweepResults results = sweepRunner.run( TABLE_NAME, ImmutableSweepBatchConfig.builder() .deleteBatchSize(DEFAULT_BATCH_SIZE) .candidateBatchSize(DEFAULT_BATCH_SIZE) .maxCellTsPairsToExamine(DEFAULT_BATCH_SIZE) .build(), nextStartRow); assertEquals(SweepResults.createEmptySweepResult(Optional.empty()), results); }
@Test(timeout = 50000) public void testSweepStrategyNothing() { createTable(SweepStrategy.NOTHING); putIntoDefaultColumn("foo", "bar", 50); putUncommitted("foo", "bad", 75); putIntoDefaultColumn("foo", "baz", 100); putIntoDefaultColumn("foo", "buzz", 125); putUncommitted("foo", "foo", 150); SweepResults results = sweepRunner.run( TABLE_NAME, ImmutableSweepBatchConfig.builder() .deleteBatchSize(DEFAULT_BATCH_SIZE) .candidateBatchSize(DEFAULT_BATCH_SIZE) .maxCellTsPairsToExamine(DEFAULT_BATCH_SIZE) .build(), PtBytes.EMPTY_BYTE_ARRAY); assertEquals(SweepResults.createEmptySweepResult(Optional.empty()), results); assertEquals(ImmutableSet.of(50L, 75L, 100L, 125L, 150L), getAllTsFromDefaultColumn("foo")); }
final TableReference tableToSweep = entry.getKey(); SweepResults accumulatedResults = SweepResults.createEmptySweepResult(Optional.of(entry.getValue()));
public static SweepResults createEmptySweepResultWithNoMoreToSweep() { return createEmptySweepResult(Optional.empty()); }
public static SweepResults createEmptySweepResultWithMoreToSweep() { return createEmptySweepResult(Optional.of(PtBytes.EMPTY_BYTE_ARRAY)); }
private SweepResults runFullSweepWithoutSavingResults( TableReference tableRef, byte[] startRow, SweepBatchConfig sweepBatchConfig) { SweepResults cumulativeResults = SweepResults.createEmptySweepResult(Optional.of(startRow)); while (cumulativeResults.getNextStartRow().isPresent()) { SweepResults results = runOneBatchWithoutSavingResults( tableRef, cumulativeResults.getNextStartRow().get(), sweepBatchConfig); specificTableSweeper.updateTimeMetricsOneIteration(results.getTimeInMillis(), results.getTimeElapsedSinceStartedSweeping()); cumulativeResults = cumulativeResults.accumulateWith(results); } return cumulativeResults; }
@Test(timeout = 50000) public void testSweepStrategyNothing() { createTable(SweepStrategy.NOTHING); putIntoDefaultColumn("foo", "bar", 50); putUncommitted("foo", "bad", 75); putIntoDefaultColumn("foo", "baz", 100); putIntoDefaultColumn("foo", "buzz", 125); putUncommitted("foo", "foo", 150); SweepResults results = sweepRunner.run( TABLE_NAME, ImmutableSweepBatchConfig.builder() .deleteBatchSize(DEFAULT_BATCH_SIZE) .candidateBatchSize(DEFAULT_BATCH_SIZE) .maxCellTsPairsToExamine(DEFAULT_BATCH_SIZE) .build(), PtBytes.EMPTY_BYTE_ARRAY); assertEquals(SweepResults.createEmptySweepResult(Optional.empty()), results); assertEquals(ImmutableSet.of(50L, 75L, 100L, 125L, 150L), getAllTsFromDefaultColumn("foo")); }
@Test(timeout = 50000) public void testSweeperFailsHalfwayThroughOnDeleteTable() { createTable(SweepStrategy.CONSERVATIVE); putIntoDefaultColumn("foo", "bar", 50); putIntoDefaultColumn("foo2", "bang", 75); putIntoDefaultColumn("foo3", "baz", 100); putIntoDefaultColumn("foo4", "buzz", 125); byte[] nextStartRow = partialSweep(150).getNextStartRow().get(); kvs.dropTable(TABLE_NAME); SweepResults results = sweepRunner.run( TABLE_NAME, ImmutableSweepBatchConfig.builder() .deleteBatchSize(DEFAULT_BATCH_SIZE) .candidateBatchSize(DEFAULT_BATCH_SIZE) .maxCellTsPairsToExamine(DEFAULT_BATCH_SIZE) .build(), nextStartRow); assertEquals(SweepResults.createEmptySweepResult(Optional.empty()), results); }
final TableReference tableToSweep = entry.getKey(); SweepResults accumulatedResults = SweepResults.createEmptySweepResult(Optional.of(entry.getValue()));