redis cluster cluster architecture Comments (nine) -redis cluster overall architecture

redis cluster overall architecture:

Here Insert Picture Description

1, in this figure, each server node redis, between any two nodes which are communicating with each other. The client can be connected to any node, then access any node in the cluster, and access to its other operations.

2, the cluster node properties

Each Master node in the cluster is responsible for storing the data state of the cluster, including nodes corresponding relationship with the slots. Master nodes can automatically discover other nodes, a node failure detection, when a Master node fails, the cluster can verify the Slave promoted to Master. FIG related information is the node, the sending node will be the timing information to other nodes:
Here Insert Picture Description

From left to right they are:

Node ID, IP address and port, the node flag is sent last time ping, pong received last time, the connection state, the node is responsible for processing hash slot.

3, the nodes communicate via Gossip

cluster 服务端节点直接使用 gossip 协议进行节点间通信,可以自动识别出ip/port的变化,并通过Gossip(最终一致性,分布式服务数据同步算法)协议广播给其他节点知道。Gossip也称“病毒感染算法”、“谣言传播算法”。

(1) The main use of cluster meet, ping, pong three commands to complete.

(2) meet or communication initiated by the ping command.

(3) meet for the first time the command is mainly used for communication between nodes (? To be confirmed).

Handshake between (4) node, similar to the three-way handshake tcp, will ensure that the person know that they have received the message.

(5) the timing of the task which will send ping clusterCron communication to a random node (marked offline, suspected offline, i.e. other nodes learn survival).

(6) at a timing when the heartbeat communication, ship with two random nodes on the information, slot information including IP, port, and the node contains

(7) The node receives the heartbeat message, the node determines whether the additional information in the local record,

本地无记录,会发其 meet 通信(握手);
本地有记录,会进行更新(判断 epoch)。

(8) Data Structure

使用 bitmap 来表示一个节点持有的槽位信息;
集群消息处理函数 clusterProcessPacket。

4, the data slice cluster Redis

Redis cluster does not use consistent hash, but the introduction of the hash slot concept.

16384 Cluster Redis hash slots, each key by the CRC16 checksum of modulo 16384 to determine which channel is placed. Each node of the cluster is responsible for a portion of the slot hash, for example, there are three such current cluster node, :

  • A node comprising 0 to 5500 hash slot number.
  • Node B 5501 to contain the hash slot number 11000.
  • 11001 to the node C contains the hash slot number 16384.
这种结构很容易添加或者删除节点. 比如如果我想新添加个节点D, 我需要从节点 A, B, C中得部分槽到D上. 如果我想移除节点A,需要将A中的槽移到B和C节点上,然后将没有任何槽的A节点从集群中移除即可. 由于从一个节点将哈希槽移动到另一个节点并不会停止服务,所以无论添加删除或者改变某个节点的哈希槽的数量都不会造成集群不可用的状态。

The following principles for redis cluster-depth explanation.

Published 155 original articles · won praise 23 · views 110 000 +

Guess you like

Origin blog.csdn.net/makyan/article/details/104798407