From 23dd57230d9ef539a622291d92d92e4e4dfc9f01 Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Thu, 5 Nov 2009 13:35:57 +0000 Subject: [PATCH] add synchronized to register/unregister methods and remove unused code. patch by Stu Hood and jbellis for CASSANDRA-527 git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@833046 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/cassandra/gms/Gossiper.java | 98 ++----------------- 1 file changed, 8 insertions(+), 90 deletions(-) diff --git a/src/java/org/apache/cassandra/gms/Gossiper.java b/src/java/org/apache/cassandra/gms/Gossiper.java index a6f401dffd..d2d6c5b73e 100644 --- a/src/java/org/apache/cassandra/gms/Gossiper.java +++ b/src/java/org/apache/cassandra/gms/Gossiper.java @@ -112,8 +112,6 @@ public synchronized static Gossiper instance() private InetAddress localEndPoint_; private long aVeryLongTime_; private Random random_ = new Random(); - /* round robin index through live endpoint set */ - private int rrIndex_ = 0; /* subscribers for interest in EndPointState change */ private List subscribers_ = new ArrayList(); @@ -145,24 +143,16 @@ private Gossiper() } /** Register with the Gossiper for EndPointState notifications */ - public void register(IEndPointStateChangeSubscriber subscriber) + public synchronized void register(IEndPointStateChangeSubscriber subscriber) { subscribers_.add(subscriber); } - public void unregister(IEndPointStateChangeSubscriber subscriber) + public synchronized void unregister(IEndPointStateChangeSubscriber subscriber) { subscribers_.remove(subscriber); } - public Set getAllMembers() - { - Set allMbrs = new HashSet(); - allMbrs.addAll(getLiveMembers()); - allMbrs.addAll(getUnreachableMembers()); - return allMbrs; - } - public Set getLiveMembers() { Set liveMbrs = new HashSet(liveEndpoints_); @@ -259,32 +249,6 @@ void evictFromMembership(InetAddress endpoint) unreachableEndpoints_.remove(endpoint); } - /* No locking required since it is called from a method that already has acquired a lock */ - @Deprecated - void makeGossipDigest(List gDigests) - { - /* Add the local endpoint state */ - EndPointState epState = endPointStateMap_.get(localEndPoint_); - int generation = epState.getHeartBeatState().getGeneration(); - int maxVersion = getMaxEndPointStateVersion(epState); - gDigests.add( new GossipDigest(localEndPoint_, generation, maxVersion) ); - - for ( InetAddress liveEndPoint : liveEndpoints_ ) - { - epState = endPointStateMap_.get(liveEndPoint); - if ( epState != null ) - { - generation = epState.getHeartBeatState().getGeneration(); - maxVersion = getMaxEndPointStateVersion(epState); - gDigests.add( new GossipDigest(liveEndPoint, generation, maxVersion) ); - } - else - { - gDigests.add( new GossipDigest(liveEndPoint, 0, 0) ); - } - } - } - /** * No locking required since it is called from a method that already * has acquired a lock. The gossip digest is built based on randomization @@ -339,8 +303,7 @@ Message makeGossipDigestSynMessage(List gDigests) throws IOExcepti ByteArrayOutputStream bos = new ByteArrayOutputStream(Gossiper.MAX_GOSSIP_PACKET_SIZE); DataOutputStream dos = new DataOutputStream( bos ); GossipDigestSynMessage.serializer().serialize(gDigestMessage, dos); - Message message = new Message(localEndPoint_, Gossiper.GOSSIP_STAGE, GOSSIP_DIGEST_SYN_VERB, bos.toByteArray()); - return message; + return new Message(localEndPoint_, Gossiper.GOSSIP_STAGE, GOSSIP_DIGEST_SYN_VERB, bos.toByteArray()); } Message makeGossipDigestAckMessage(GossipDigestAckMessage gDigestAckMessage) throws IOException @@ -350,8 +313,7 @@ Message makeGossipDigestAckMessage(GossipDigestAckMessage gDigestAckMessage) thr GossipDigestAckMessage.serializer().serialize(gDigestAckMessage, dos); if (logger_.isTraceEnabled()) logger_.trace("@@@@ Size of GossipDigestAckMessage is " + bos.toByteArray().length); - Message message = new Message(localEndPoint_, Gossiper.GOSSIP_STAGE, GOSSIP_DIGEST_ACK_VERB, bos.toByteArray()); - return message; + return new Message(localEndPoint_, Gossiper.GOSSIP_STAGE, GOSSIP_DIGEST_ACK_VERB, bos.toByteArray()); } Message makeGossipDigestAck2Message(GossipDigestAck2Message gDigestAck2Message) throws IOException @@ -359,25 +321,7 @@ Message makeGossipDigestAck2Message(GossipDigestAck2Message gDigestAck2Message) ByteArrayOutputStream bos = new ByteArrayOutputStream(Gossiper.MAX_GOSSIP_PACKET_SIZE); DataOutputStream dos = new DataOutputStream(bos); GossipDigestAck2Message.serializer().serialize(gDigestAck2Message, dos); - Message message = new Message(localEndPoint_, Gossiper.GOSSIP_STAGE, GOSSIP_DIGEST_ACK2_VERB, bos.toByteArray()); - return message; - } - - boolean sendGossipToLiveNode(Message message) - { - int size = liveEndpoints_.size(); - List eps = new ArrayList(liveEndpoints_); - - if ( rrIndex_ >= size ) - { - rrIndex_ = -1; - } - - InetAddress to = eps.get(++rrIndex_); - if (logger_.isTraceEnabled()) - logger_.trace("Sending a GossipDigestSynMessage to " + to + " ..."); - MessagingService.instance().sendUdpOneWay(message, to); - return seeds_.contains(to); + return new Message(localEndPoint_, Gossiper.GOSSIP_STAGE, GOSSIP_DIGEST_ACK2_VERB, bos.toByteArray()); } /** @@ -779,28 +723,6 @@ synchronized void isAlive(InetAddress addr, EndPointState epState, boolean value epState.isAGossiper(true); } - /* These are helper methods used from GossipDigestSynVerbHandler */ - Map getEndPointGossipDigestMap(List gDigestList) - { - Map epMap = new HashMap(); - for( GossipDigest gDigest : gDigestList ) - { - epMap.put( gDigest.getEndPoint(), gDigest ); - } - return epMap; - } - - /* This is a helper method to get all EndPoints from a list of GossipDigests */ - InetAddress[] getEndPointsFromGossipDigest(List gDigestList) - { - Set set = new HashSet(); - for ( GossipDigest gDigest : gDigestList ) - { - set.add( gDigest.getEndPoint() ); - } - return set.toArray( new InetAddress[0] ); - } - /* Request all the state for the endpoint in the gDigest */ void requestAll(GossipDigest gDigest, List deltaGossipDigestList, int remoteGeneration) { @@ -883,7 +805,7 @@ synchronized void examineGossiper(List gDigestList, List