From ba9a69ea21b6cf2e70408ba62522a4a58b695e3f Mon Sep 17 00:00:00 2001 From: Stefania Alborghetti Date: Thu, 16 Jul 2015 10:04:58 +0800 Subject: [PATCH] checkForEndpointCollision fails for legitimate collisions, finalized list of statuses and nits, CASSANDRA-9765 --- .../org/apache/cassandra/gms/Gossiper.java | 39 +++++++------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/src/java/org/apache/cassandra/gms/Gossiper.java b/src/java/org/apache/cassandra/gms/Gossiper.java index 8eecc98d75..8c36223986 100644 --- a/src/java/org/apache/cassandra/gms/Gossiper.java +++ b/src/java/org/apache/cassandra/gms/Gossiper.java @@ -703,20 +703,19 @@ public class Gossiper implements IFailureDetectionEventListener, GossiperMBean public boolean isSafeForBootstrap(InetAddress endpoint) { EndpointState epState = endpointStateMap.get(endpoint); - String state = getApplicationState(epState); - logger.info("{} state : {}", endpoint, state); // if there's no previous state, or the node was previously removed from the cluster, we're good if (epState == null || isDeadState(epState)) return true; - // these states are not allowed to join the cluster - List states = new ArrayList() {{ + String status = getGossipStatus(epState); + + // these states are not allowed to join the cluster as it would not be safe + final List unsafeStatuses = new ArrayList() {{ add(""); // failed bootstrap but we did start gossiping - add(VersionedValue.STATUS_NORMAL); // node is legit in the cluster or was stopped kill -9 - //add(VersionedValue.STATUS_BOOTSTRAPPING); // failed bootstrap + add(VersionedValue.STATUS_NORMAL); // node is legit in the cluster or it was stopped with kill -9 add(VersionedValue.SHUTDOWN); }}; // node was shutdown - return !states.contains(state); + return !unsafeStatuses.contains(status); } private void doStatusCheck() @@ -1039,31 +1038,23 @@ public class Gossiper implements IFailureDetectionEventListener, GossiperMBean public boolean isDeadState(EndpointState epState) { - String state = getApplicationState(epState); - if (state.isEmpty()) + String status = getGossipStatus(epState); + if (status.isEmpty()) return false; - for (String deadstate : DEAD_STATES) - { - if (state.equals(deadstate)) - return true; - } - return false; + + return DEAD_STATES.contains(status); } public boolean isSilentShutdownState(EndpointState epState) { - String state = getApplicationState(epState); - if (state.isEmpty()) + String status = getGossipStatus(epState); + if (status.isEmpty()) return false; - for (String deadstate : SILENT_SHUTDOWN_STATES) - { - if (state.equals(deadstate)) - return true; - } - return false; + + return SILENT_SHUTDOWN_STATES.contains(status); } - private static String getApplicationState(EndpointState epState) + private static String getGossipStatus(EndpointState epState) { if (epState == null || epState.getApplicationState(ApplicationState.STATUS) == null) return "";