Overview of the Gossip protocolNodes in the Cassandra cluster do not have primary and secondary points, and they communicate through a protocol called gossip. Through the gossip protocol, they can know what nodes are in the cluster and how they are state. Each gossip message has a version number on it, the nodes can compare to the received messages to see which messages I need to update, what messages I have and others don't, and then talk to each other to make sure they get the same information, which is like real-life gossip (chew), One, wildfire, the last known. When Cassandra starts, the gossip service starts, and the gossip service starts a task Gossiptask that periodically communicates with the other nodes. Gossiptask is an internal class that is located under the Org.apache.cassandra.gms.Gossip class, and its run method is as follows:
[Java] View plain copy print? Public void run () { messagingservice.instance (). Waituntillistening (); /* Update the local heartbeat counter. */ endpointstatemap.get (Fbutilities.getbroadcastaddress ()). Getheartbeatstate (). Updateheartbeat (); final List<GossipDigest> gDigests = new ArrayList< Gossipdigest> (); gossiper.instance.makerandomgossipdigest ( gdigests); if (gdigests.size () > 0) { GossipDigestSyn Digestsynmessage = new gossipdigestsyn (Databasedescriptor.getclustername (), databasedescriptor.getpartitionername (), gdigests); messageout<gossipdigestsyn> message = new messageout<goSsipdigestsyn> (messagingservice.verb.gossip_digest_syn, digestSynMessage, gossipdigestsyn.serializer); /* gossip to some random live member */ boolean Gossipedtoseed = dogossiptolivemember (message); /* gossip to some unreachable member with some probability to check if he is back up */ dogossiptounreachablemember (message); if (!gossipedtoseed | | liveendpoints.size () < seeds.size ()) dogossiptoseed (message); dostatuscheck (); } } Mainly done a few things: 1, gossiptask after gossip started and will not run immediately, blocking on the listengate this condition variable, when the gossip service calls listen to start running; 2, first update the heartbeat version number of this node, Then constructs the message that needs to be sent to other nodes Gdigests 3, from the surviving node randomly select a node to send, from the failure node randomly select a send. If the current number of surviving nodes is less than the number of seeds, send a message to one of the seed nodes; 4, check the node status. For further analysis of the seed node and node State, this section focuses on the gossip protocol itself. Gossiptask is used to send gossip information to other nodes, Cassandra also provides socketthread such a thread to receive messages, The code that receives the message is in the Org.apache.cassandra.net.IncomingTcpConnection class. Either sending or receiving gossip messages is implemented by calling the Org.apache.cassandra.net.MessagingService Sendoneway method. A gossip communication is divided into three phases, as shown in the figure:
Each phase corresponds to a message class, the three message classes have a corresponding processor, the processor registration is done in the Org.apache.cassandra.service.StorageService class, refer to the following code:
[Java]View Plain copy print? Messagingservice.instance (). Registerverbhandlers (MessagingService.Verb.GOSSIP_DIGEST_SYN, new Gossipdigestsynverbhandler ()); Messagingservice.instance (). Registerverbhandlers (MessagingService.Verb.GOSSIP_DIGEST_ACK, new Gossipdigestackverbhandler ()); Messagingservice.instance (). Registerverbhandlers (MessagingService.Verb.GOSSIP_DIGEST_ACK2, new Gossipdigestack2verbhandler ()); It can be seen that these three messages correspond to three message types Gossip_digest_syn, Gossip_digest_ack, and Gossip_digest_ack2 respectively.
Each phase is analyzed in detail below.
GossipdigestsynmessageThe Gossiptask Run method sends a Gossip_digest_syn type of message (Gossipdigestsynmessage), which is given to its corresponding processor Gossipdigestackverbhandler processing, The specific process in the DoVerb () method, the core code is as follows:
[Java]View Plain copy print? public void DoVerb (messagein<gossipdigestsyn> message, int id) {//...check
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.