cassadnra gossip协议实现

 

Gossip is a peer-to-peer communication protocol in which nodes periodically exchange state information about themselves and about other nodes they know about. The gossip process runs every second and exchanges state messages with up to three other nodes in the cluster. The nodes exchange information about themselves and about the other nodes that they have gossiped about, so all nodes quickly learn about all other nodes in the cluster. A gossip message has a version associated with it, so that during a gossip exchange, older information is overwritten with the most current state for a particular node.

gossip是一种节点和节点之间的通信协议,借助这个协议节点之间定期的把自己的状态和它知道的其他节点的状态发送给其他节点; gossip线程每隔1秒执行一次,并且每次最多跟3个node交换信息; gossip协议的内容包括一个版本信息,因为有了这个版本信息,所以老的信息就会被新的信息覆盖掉; 也就是老的节点状态会被新的节点状态所覆盖; 

在cassandra里每次的gossip通信都称为heartbeat, 也就是每次的heartbeat就是一个完整的gossip过程。每次的heartbeat都有一个heartbeatversion,这里的heartbeatversion其实是一个AtomicInteger, 每次在heartbeat的时候,都会+1,当然节点只能更新当前节点的heartbeatversion. 不能去更新其他节点的heartbeatversion;

To prevent problems in gossip communications, use the same list of seed nodes for all nodes in a cluster. This is most critical the first time a node starts up. By default, a node remembers other nodes it has gossiped with between subsequent restarts. The seed node designation has no purpose other than bootstrapping the gossip process for new nodes joining the cluster. Seed nodes are not a single point of failure, nor do they have any other special purpose in cluster operations beyond the bootstrapping of nodes.

 为了防止gossip通信时候的问题,一个cluster里的所有节点的seed都应当使用相同的node list. 这在一个节点第一次启动的时候特别重要。默认情况下,节点会记住跟它gossip过得节点信息。 对于新加入的节点,seed node list只有在启动的时候才有作用。不能让seed node不是单点故障,除了bootstrap之外也没有其他作用; 

注意这里的描述,对于new node, seed节点只有在bootstraping的时候才起作用。但是不要认为seed只有在启动的时候才起作用,其实在后面的gossip的时候,也会要用到;

Attention: In multiple data-center clusters, the seed list should include at least one node from each data center (replication group). More than a single seed node per data center is recommended for fault tolerance. Otherwise, gossip has to communicate with another data center when bootstrapping a node. Making every node a seed node is not recommended because of increased maintenance and reduced gossip performance. Gossip optimization is not critical, but it is recommended to use a small seed list (approximately three nodes per data center).
注意: 对于包含多个DC的cluster, seed list应对包含每个DC里的至少一个node. 为了容错的需要, 推荐seed node list里包含有每个DC的多余一个node; 另外,在bootstraping的时候,gossip也会跟其他DC node通信。但是也不推荐把所有的node都加到seed node list里来,因为这会增加维护的负担。gossip协议的优化并不是决定性的,但是推荐每个数据中心大概3个nodes
posted @ 2017-07-16 16:50  jobforlife  阅读(624)  评论(0编辑  收藏  举报