Clean up gossiper logic for old versions Patch by brandonwilliams, reviewed by aleksey for CASSANDRA-9370
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/23d7a558 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/23d7a558 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/23d7a558 Branch: refs/heads/trunk Commit: 23d7a558ee824a22d382e1b645814638a2cd2985 Parents: 94a68a1 Author: Brandon Williams <brandonwilli...@apache.org> Authored: Tue Jun 2 08:42:28 2015 -0500 Committer: Brandon Williams <brandonwilli...@apache.org> Committed: Tue Jun 2 08:42:28 2015 -0500 ---------------------------------------------------------------------- CHANGES.txt | 1 + src/java/org/apache/cassandra/gms/Gossiper.java | 16 ------ .../cassandra/service/StorageService.java | 54 +++++++++----------- 3 files changed, 26 insertions(+), 45 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/23d7a558/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 165f76b..41f5cfb 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 2.2 + * Clean up gossiper logic for old versions (CASSANDRA-9370) * ant test-all results incomplete when parsed (CASSANDRA-9463) * Disallow frozen<> types in function arguments and return types for clarity (CASSANDRA-9411) http://git-wip-us.apache.org/repos/asf/cassandra/blob/23d7a558/src/java/org/apache/cassandra/gms/Gossiper.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/gms/Gossiper.java b/src/java/org/apache/cassandra/gms/Gossiper.java index 0c449ec..e131da6 100644 --- a/src/java/org/apache/cassandra/gms/Gossiper.java +++ b/src/java/org/apache/cassandra/gms/Gossiper.java @@ -798,24 +798,8 @@ public class Gossiper implements IFailureDetectionEventListener, GossiperMBean return endpointStateMap.entrySet(); } - public boolean usesHostId(InetAddress endpoint) - { - if (MessagingService.instance().knowsVersion(endpoint)) - return true; - else if (getEndpointStateForEndpoint(endpoint).getApplicationState(ApplicationState.NET_VERSION) != null) - return true; - return false; - } - - public boolean usesVnodes(InetAddress endpoint) - { - return usesHostId(endpoint) && getEndpointStateForEndpoint(endpoint).getApplicationState(ApplicationState.TOKENS) != null; - } - public UUID getHostId(InetAddress endpoint) { - if (!usesHostId(endpoint)) - throw new RuntimeException("Host " + endpoint + " does not use new-style tokens!"); return UUID.fromString(getEndpointStateForEndpoint(endpoint).getApplicationState(ApplicationState.HOST_ID).value); } http://git-wip-us.apache.org/repos/asf/cassandra/blob/23d7a558/src/java/org/apache/cassandra/service/StorageService.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/service/StorageService.java b/src/java/org/apache/cassandra/service/StorageService.java index bfbf1a8..8afb93f 100644 --- a/src/java/org/apache/cassandra/service/StorageService.java +++ b/src/java/org/apache/cassandra/service/StorageService.java @@ -1825,8 +1825,7 @@ public class StorageService extends NotificationBroadcasterSupport implements IE tokenMetadata.addBootstrapTokens(tokens, endpoint); PendingRangeCalculatorService.instance.update(); - if (Gossiper.instance.usesHostId(endpoint)) - tokenMetadata.updateHostId(Gossiper.instance.getHostId(endpoint), endpoint); + tokenMetadata.updateHostId(Gossiper.instance.getHostId(endpoint), endpoint); } /** @@ -1855,39 +1854,36 @@ public class StorageService extends NotificationBroadcasterSupport implements IE updatePeerInfo(endpoint); // Order Matters, TM.updateHostID() should be called before TM.updateNormalToken(), (see CASSANDRA-4300). - if (Gossiper.instance.usesHostId(endpoint)) + UUID hostId = Gossiper.instance.getHostId(endpoint); + InetAddress existing = tokenMetadata.getEndpointForHostId(hostId); + if (replacing && Gossiper.instance.getEndpointStateForEndpoint(DatabaseDescriptor.getReplaceAddress()) != null && (hostId.equals(Gossiper.instance.getHostId(DatabaseDescriptor.getReplaceAddress())))) + logger.warn("Not updating token metadata for {} because I am replacing it", endpoint); + else { - UUID hostId = Gossiper.instance.getHostId(endpoint); - InetAddress existing = tokenMetadata.getEndpointForHostId(hostId); - if (replacing && Gossiper.instance.getEndpointStateForEndpoint(DatabaseDescriptor.getReplaceAddress()) != null && (hostId.equals(Gossiper.instance.getHostId(DatabaseDescriptor.getReplaceAddress())))) - logger.warn("Not updating token metadata for {} because I am replacing it", endpoint); - else + if (existing != null && !existing.equals(endpoint)) { - if (existing != null && !existing.equals(endpoint)) + if (existing.equals(FBUtilities.getBroadcastAddress())) { - if (existing.equals(FBUtilities.getBroadcastAddress())) - { - logger.warn("Not updating host ID {} for {} because it's mine", hostId, endpoint); - tokenMetadata.removeEndpoint(endpoint); - endpointsToRemove.add(endpoint); - } - else if (Gossiper.instance.compareEndpointStartup(endpoint, existing) > 0) - { - logger.warn("Host ID collision for {} between {} and {}; {} is the new owner", hostId, existing, endpoint, endpoint); - tokenMetadata.removeEndpoint(existing); - endpointsToRemove.add(existing); - tokenMetadata.updateHostId(hostId, endpoint); - } - else - { - logger.warn("Host ID collision for {} between {} and {}; ignored {}", hostId, existing, endpoint, endpoint); - tokenMetadata.removeEndpoint(endpoint); - endpointsToRemove.add(endpoint); - } + logger.warn("Not updating host ID {} for {} because it's mine", hostId, endpoint); + tokenMetadata.removeEndpoint(endpoint); + endpointsToRemove.add(endpoint); } - else + else if (Gossiper.instance.compareEndpointStartup(endpoint, existing) > 0) + { + logger.warn("Host ID collision for {} between {} and {}; {} is the new owner", hostId, existing, endpoint, endpoint); + tokenMetadata.removeEndpoint(existing); + endpointsToRemove.add(existing); tokenMetadata.updateHostId(hostId, endpoint); + } + else + { + logger.warn("Host ID collision for {} between {} and {}; ignored {}", hostId, existing, endpoint, endpoint); + tokenMetadata.removeEndpoint(endpoint); + endpointsToRemove.add(endpoint); + } } + else + tokenMetadata.updateHostId(hostId, endpoint); } for (final Token token : tokens)