public static SweepResults createEmptySweepResult(Optional<byte[]> startRow) { return builder() .cellTsPairsExamined(0) .staleValuesDeleted(0) .minSweptTimestamp(Long.MAX_VALUE) .nextStartRow(startRow) .timeInMillis(0) .timeSweepStarted(System.currentTimeMillis()) .build(); }
@JsonIgnore default SweepResults getPreviousResults() { return SweepResults.builder() .staleValuesDeleted(staleValuesDeleted()) .cellTsPairsExamined(cellTsPairsExamined()) .minSweptTimestamp(minimumSweptTimestamp()) .nextStartRow(Optional.of(startRow())) .timeInMillis(timeInMillis()) .timeSweepStarted(startTimeInMillis()) .build(); } }
@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)); } }
totalCellsExamined += results.getCellTsPairsExamined(); if (!results.getNextStartRow().isPresent()) { return Optional.of(SweepResults.builder() .staleValuesDeleted(totalStaleValuesDeleted) .cellTsPairsExamined(totalCellsExamined)
@Test public void testMetricsRecordedAfterIncompleteRunForOneIterationOnly() { setNoProgress(); setNextTableToSweep(TABLE_REF); SweepResults intermediateResults = SweepResults.builder() .staleValuesDeleted(2) .cellTsPairsExamined(10) .minSweptTimestamp(12345L) .nextStartRow(Optional.of(new byte[] {1, 2, 3})) .timeInMillis(10L) .timeSweepStarted(20L) .build(); setupTaskRunner(intermediateResults); backgroundSweeper.runOnce(); ArgumentCaptor<Long> sweepTime = ArgumentCaptor.forClass(Long.class); ArgumentCaptor<Long> totalTimeElapsed = ArgumentCaptor.forClass(Long.class); Mockito.verify(sweepMetrics).updateSweepTime( sweepTime.capture(), totalTimeElapsed.capture()); Assertions.assertThat(intermediateResults.getTimeInMillis()).isEqualTo(sweepTime.getValue()); Assertions.assertThat(intermediateResults.getTimeElapsedSinceStartedSweeping()) .isCloseTo(totalTimeElapsed.getValue(), Percentage.withPercentage(5d)); }
return SweepResults.builder() .previousStartRow(Optional.of(startRow)) .nextStartRow(Arrays.equals(startRow, lastRow) ? Optional.empty() : Optional.of(lastRow))
/** * Returns a new {@link SweepResults} representing cumulative results from this instance and {@code other}. * The operation is commutative. */ public SweepResults accumulateWith(SweepResults other) { return SweepResults.builder() .nextStartRow(maxRowOptional(getNextStartRow(), other.getNextStartRow())) .cellTsPairsExamined(getCellTsPairsExamined() + other.getCellTsPairsExamined()) .staleValuesDeleted(getStaleValuesDeleted() + other.getStaleValuesDeleted()) .minSweptTimestamp(Math.min(getMinSweptTimestamp(), other.getMinSweptTimestamp())) .timeInMillis(getTimeInMillis() + other.getTimeInMillis()) .timeSweepStarted(Math.min(getTimeSweepStarted(), other.getTimeSweepStarted())) .build(); }
@Test public void testPutZeroWriteCountAfterFreshIncompleteRun() { setNoProgress(); setNextTableToSweep(TABLE_REF); setupTaskRunner(SweepResults.builder() .staleValuesDeleted(2) .cellTsPairsExamined(10) .minSweptTimestamp(12345L) .nextStartRow(Optional.of(new byte[] {1, 2, 3})) .timeInMillis(10L) .timeSweepStarted(20L) .build()); backgroundSweeper.runOnce(); Mockito.verify(priorityStore).update( any(), eq(TABLE_REF), eq(ImmutableUpdateSweepPriority.builder() .newWriteCount(0L) .build())); }
setNoProgress(); setNextTableToSweep(TABLE_REF); setupTaskRunner(SweepResults.builder() .staleValuesDeleted(2) .cellTsPairsExamined(10)
.build()); SweepResults intermediateResults = SweepResults.builder() .staleValuesDeleted(2) .cellTsPairsExamined(10)
@Test public void testWritePriorityAfterCompleteFreshRun() { setNoProgress(); setNextTableToSweep(TABLE_REF); setupTaskRunner(SweepResults.builder() .staleValuesDeleted(2) .cellTsPairsExamined(10) .minSweptTimestamp(12345L) .timeInMillis(10L) .timeSweepStarted(20L) .build()); backgroundSweeper.runOnce(); Mockito.verify(priorityStore).update( any(), eq(TABLE_REF), eq(ImmutableUpdateSweepPriority.builder() .newStaleValuesDeleted(2) .newCellTsPairsExamined(10) .newMinimumSweptTimestamp(12345L) .newLastSweepTimeMillis(currentTimeMillis) .newWriteCount(0L) .build())); }
.startTimeInMillis(20L) .build()); setupTaskRunner(SweepResults.builder() .staleValuesDeleted(2) .cellTsPairsExamined(10)
.startTimeInMillis(20L) .build()); setupTaskRunner(SweepResults.builder() .staleValuesDeleted(2) .cellTsPairsExamined(10)
.build()); setNoProgress(OTHER_TABLE); setupTaskRunner(OTHER_TABLE, SweepResults.builder() .staleValuesDeleted(2) .cellTsPairsExamined(10)
public static SweepResults createEmptySweepResult(Optional<byte[]> startRow) { return builder() .cellTsPairsExamined(0) .staleValuesDeleted(0) .minSweptTimestamp(Long.MAX_VALUE) .nextStartRow(startRow) .timeInMillis(0) .timeSweepStarted(System.currentTimeMillis()) .build(); }
@JsonIgnore default SweepResults getPreviousResults() { return SweepResults.builder() .staleValuesDeleted(staleValuesDeleted()) .cellTsPairsExamined(cellTsPairsExamined()) .minSweptTimestamp(minimumSweptTimestamp()) .nextStartRow(Optional.of(startRow())) .timeInMillis(timeInMillis()) .timeSweepStarted(startTimeInMillis()) .build(); } }
totalCellsExamined += results.getCellTsPairsExamined(); if (!results.getNextStartRow().isPresent()) { return Optional.of(SweepResults.builder() .staleValuesDeleted(totalStaleValuesDeleted) .cellTsPairsExamined(totalCellsExamined)
/** * Returns a new {@link SweepResults} representing cumulative results from this instance and {@code other}. * The operation is commutative. */ public SweepResults accumulateWith(SweepResults other) { return SweepResults.builder() .nextStartRow(maxRowOptional(getNextStartRow(), other.getNextStartRow())) .cellTsPairsExamined(getCellTsPairsExamined() + other.getCellTsPairsExamined()) .staleValuesDeleted(getStaleValuesDeleted() + other.getStaleValuesDeleted()) .minSweptTimestamp(Math.min(getMinSweptTimestamp(), other.getMinSweptTimestamp())) .timeInMillis(getTimeInMillis() + other.getTimeInMillis()) .timeSweepStarted(Math.min(getTimeSweepStarted(), other.getTimeSweepStarted())) .build(); }