Skip to content

Commit

Permalink
Catch AssertionError if a keyspace doesn't exist
Browse files Browse the repository at this point in the history
This can happen if somebody changes Cassandra schema if a cluster is
already registered in the Reaper. Without catching, the thread was
silently dying.
  • Loading branch information
Radovan Zvoncek committed Apr 13, 2015
1 parent ed3b043 commit 4efcae2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
10 changes: 8 additions & 2 deletions src/main/java/com/spotify/reaper/cassandra/JmxProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,15 @@ public BigInteger apply(String s) {
});
}

public Map<List<String>, List<String>> getRangeToEndpointMap(String keyspace) {
public Map<List<String>, List<String>> getRangeToEndpointMap(String keyspace)
throws ReaperException {
checkNotNull(ssProxy, "Looks like the proxy is not connected");
return ssProxy.getRangeToEndpointMap(keyspace);
try {
return ssProxy.getRangeToEndpointMap(keyspace);
} catch (AssertionError e) {
LOG.error(e.getMessage());
throw new ReaperException(e.getMessage());
}
}

/**
Expand Down
19 changes: 6 additions & 13 deletions src/main/java/com/spotify/reaper/service/RepairRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Optional;

import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.FutureCallback;
Expand All @@ -29,7 +28,6 @@
import com.spotify.reaper.core.RepairRun;
import com.spotify.reaper.core.RepairSegment;
import com.spotify.reaper.core.RepairUnit;

import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -38,11 +36,8 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicLongArray;

import javax.annotation.Nullable;

public class RepairRunner implements Runnable {

private static final Logger LOG = LoggerFactory.getLogger(RepairRunner.class);
Expand All @@ -51,7 +46,6 @@ public class RepairRunner implements Runnable {
private final long repairRunId;
private final String clusterName;
private JmxProxy jmxConnection;
// private Long currentlyRunningSegmentId;
private final AtomicLongArray currentlyRunningSegments;
private final List<RingRange> parallelRanges;

Expand All @@ -70,9 +64,8 @@ public RepairRunner(AppContext context, long repairRunId)
this.clusterName = cluster.get().getName();
JmxProxy jmx = this.context.jmxConnectionFactory.connectAny(cluster.get());

int parallelRepairs =
getPossibleParallelRepairsCount(
jmx.getRangeToEndpointMap(repairUnit.get().getKeyspaceName()));
String keyspace = repairUnit.get().getKeyspaceName();
int parallelRepairs = getPossibleParallelRepairsCount(jmx.getRangeToEndpointMap(keyspace));
currentlyRunningSegments = new AtomicLongArray(parallelRepairs);
for(int i=0;i<parallelRepairs;i++) {
currentlyRunningSegments.set(i, -1);
Expand Down Expand Up @@ -205,10 +198,10 @@ private void end() {
LOG.info("Repairs for repair run #{} done", repairRunId);
RepairRun repairRun = context.storage.getRepairRun(repairRunId).get();
boolean success = context.storage.updateRepairRun(repairRun.with()
.runState(RepairRun.RunState.DONE)
.endTime(DateTime.now())
.lastEvent("All done")
.build(repairRun.getId()));
.runState(RepairRun.RunState.DONE)
.endTime(DateTime.now())
.lastEvent("All done")
.build(repairRun.getId()));
if (!success) {
LOG.error("failed updating repair run " + repairRun.getId());
}
Expand Down

0 comments on commit 4efcae2

Please sign in to comment.