From 4efcae212bbcbf65027f6fb271cd5f2dd8874c04 Mon Sep 17 00:00:00 2001 From: Radovan Zvoncek Date: Mon, 13 Apr 2015 15:52:23 +0200 Subject: [PATCH] Catch AssertionError if a keyspace doesn't exist This can happen if somebody changes Cassandra schema if a cluster is already registered in the Reaper. Without catching, the thread was silently dying. --- .../spotify/reaper/cassandra/JmxProxy.java | 10 ++++++++-- .../spotify/reaper/service/RepairRunner.java | 19 ++++++------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/spotify/reaper/cassandra/JmxProxy.java b/src/main/java/com/spotify/reaper/cassandra/JmxProxy.java index 383a50277..cd51e4e81 100644 --- a/src/main/java/com/spotify/reaper/cassandra/JmxProxy.java +++ b/src/main/java/com/spotify/reaper/cassandra/JmxProxy.java @@ -170,9 +170,15 @@ public BigInteger apply(String s) { }); } - public Map, List> getRangeToEndpointMap(String keyspace) { + public Map, List> 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()); + } } /** diff --git a/src/main/java/com/spotify/reaper/service/RepairRunner.java b/src/main/java/com/spotify/reaper/service/RepairRunner.java index ff678a734..c58b88d25 100644 --- a/src/main/java/com/spotify/reaper/service/RepairRunner.java +++ b/src/main/java/com/spotify/reaper/service/RepairRunner.java @@ -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; @@ -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; @@ -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); @@ -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 parallelRanges; @@ -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