Skip to content

Commit

Permalink
Use refresh state in incremental schedules (#552)
Browse files Browse the repository at this point in the history
  • Loading branch information
masokol authored Aug 21, 2023
1 parent bc5bfe2 commit 1d4e8b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,16 @@ public Iterator<ScheduledTask> iterator()
}

/**
* Decides if the job is runnable.
*
* @return true if enough time has passed and there is something to repair.
* Check if there's anything to repair, if not then just move the last run.
*/
@Override
public boolean runnable()
public void refreshState()
{
if (super.runnable())
boolean nothingToRepair = getProgress() >= 1.0;
if (nothingToRepair)
{
boolean nothingToRepair = getProgress() >= 1.0;
if (nothingToRepair)
{
myLastSuccessfulRun = System.currentTimeMillis();
return false;
}
return true;
myLastSuccessfulRun = System.currentTimeMillis();
}
return false;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ public void testRunnableNothingRepaired()
{
doReturn(0.0d).when(myCassandraMetrics).getPercentRepaired(myTableReference);
IncrementalRepairJob job = getIncrementalRepairJob();
job.refreshState();

assertThat(job).isNotNull();
assertThat(job.runnable()).isTrue();
Expand All @@ -228,6 +229,7 @@ public void testRunnableHalfRepaired()
{
doReturn(50.0d).when(myCassandraMetrics).getPercentRepaired(myTableReference);
IncrementalRepairJob job = getIncrementalRepairJob();
job.refreshState();

assertThat(job).isNotNull();
assertThat(job.runnable()).isTrue();
Expand All @@ -238,6 +240,7 @@ public void testRunnableEverythingRepaired()
{
doReturn(100.0d).when(myCassandraMetrics).getPercentRepaired(myTableReference);
IncrementalRepairJob job = getIncrementalRepairJob();
job.refreshState();

assertThat(job).isNotNull();
assertThat(job.runnable()).isFalse();
Expand All @@ -249,6 +252,7 @@ public void testRunnableIntervalNotYetPassed()
long lastRepairedAt = System.currentTimeMillis();
doReturn(lastRepairedAt).when(myCassandraMetrics).getMaxRepairedAt(myTableReference);
IncrementalRepairJob job = getIncrementalRepairJob();
job.refreshState();

assertThat(job).isNotNull();
assertThat(job.runnable()).isFalse();
Expand Down

0 comments on commit 1d4e8b4

Please sign in to comment.