Skip to content

Commit

Permalink
Unregister repair runner whenever run terminates
Browse files Browse the repository at this point in the history
  • Loading branch information
Bj0rnen committed Apr 21, 2015
1 parent 5fb028b commit 3b30858
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/spotify/reaper/core/RepairRun.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ public enum RunState {
public boolean isActive() {
return this == RUNNING || this == PAUSED;
}

public boolean isTerminated() {
return this == DONE || this == ERROR || this == ABORTED || this == DELETED;
}
}

public static class Builder {
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/com/spotify/reaper/service/RepairRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ public void run() {

try {
Optional<RepairRun> repairRun = context.storage.getRepairRun(repairRunId);
if (!repairRun.isPresent()) {
if ((!repairRun.isPresent() || repairRun.get().getRunState().isTerminated()) &&
context.repairManager.repairRunners.containsKey(repairRunId)) {
// this might happen if a run is deleted while paused etc.
LOG.warn("RepairRun \"" + repairRunId + "\" does not exist. Killing "
+ "RepairRunner for this run instance.");
Expand All @@ -155,10 +156,6 @@ public void run() {
case PAUSED:
context.repairManager.scheduleRetry(this);
break;
case DONE:
// We're done. Let go of thread.
context.repairManager.removeRunner(this);
break;
}
} catch (ReaperException | RuntimeException e) {
LOG.error("RepairRun FAILURE");
Expand All @@ -175,8 +172,8 @@ public void run() {
.endTime(DateTime.now())
.build(repairRunId));
}
context.repairManager.removeRunner(this);
}
context.repairManager.removeRunner(this);
}
}

Expand Down Expand Up @@ -207,6 +204,7 @@ private void end() {
.endTime(DateTime.now())
.lastEvent("All done")
.build(repairRun.getId()));
context.repairManager.removeRunner(this);
}
}

Expand Down Expand Up @@ -298,6 +296,7 @@ private void repairSegment(final int rangeIndex, final long segmentId, RingRange
.lastEvent(String.format("No coordinators for range %s", tokenRange.toString()))
.endTime(DateTime.now())
.build(repairRunId));
context.repairManager.removeRunner(this);
}
return;
}
Expand Down

0 comments on commit 3b30858

Please sign in to comment.