private SweepOutcome grabLocksAndRun(SingleLockService locks) throws InterruptedException { try { locks.lockOrRefresh(); if (locks.haveLocks()) { return runOnce(); } else { log.debug("Skipping sweep because sweep is running elsewhere."); closeTableLockIfHeld(); return SweepOutcome.UNABLE_TO_ACQUIRE_LOCKS; } } catch (RuntimeException e) { specificTableSweeper.updateSweepErrorMetric(); log.info("Sweep failed", e); return SweepOutcome.ERROR; } }
@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)); }
@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())); }
.timeSweepStarted(Long.MAX_VALUE) .build()); backgroundSweeper.runOnce();
backgroundSweeper.runOnce();
@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())); }
.timeSweepStarted(0L) .build()); backgroundSweeper.runOnce(); Mockito.verify(priorityStore).update( any(),
private SweepOutcome grabLocksAndRun(SingleLockService locks) throws InterruptedException { try { locks.lockOrRefresh(); if (locks.haveLocks()) { return runOnce(); } else { log.debug("Skipping sweep because sweep is running elsewhere."); closeTableLockIfHeld(); return SweepOutcome.UNABLE_TO_ACQUIRE_LOCKS; } } catch (RuntimeException e) { specificTableSweeper.updateSweepErrorMetric(); log.info("Sweep failed", e); return SweepOutcome.ERROR; } }
.timeSweepStarted(50L) .build()); backgroundSweeper.runOnce();
otherThread.runOnce();