当前位置:网站首页>Redis Cluster - the bottom principle of building clusters
Redis Cluster - the bottom principle of building clusters
2022-06-13 07:33:00 【A hard-working dog】
Redis colony
Redis Clusters are Redis The distributed database solution provided , Clustering is done by fragmentation (sharding) To share data , It also provides replication and failover capabilities .
node
One Redis A cluster usually consists of multiple nodes ( Running in cluster mode Reids The server )
// The work of connecting various nodes can use CLUSTER MEET <IP><port>
Send... To a node CLUSTER MEET command , It can make node Node and ip and port Handshake with the specified node (handshake), If the handshake is successful , that node The node will ip and port The specified node is added to node In the cluster .
Data structure of cluster
clusterNode The structure holds the current state of a node : Such as the creation time of the node 、 Node name 、 The current configuration level element of the node 、 Node IP And port numbers, etc .
One for each node clusterNode Structure to keep track of your state , And for all other nodes in the cluster ( Including master node and slave node ) Create a corresponding clusterNode structure , To record the status of other nodes .
struct clusterNode{
// Time of node creation
mstime_t ctime;
// Node name , from 40 It's made up of 16 hexadecimal characters
char name[REDIS_CLUSTER_NAMELEN];
// Node identification , Use different identity values to record the role of the node , And the current state of the node
int flags;
// The current configuration era for the node , For failover
uint64_t configEpoch;
// Node ip Address
char Ip[Redis_ip_str_len];
// The port number of the node
int port;
// Save the information needed to connect nodes
clusterLink *link;
}struct clusterLink{
// Time when the connection was created
mstime_t ctime;
//TCP socket descriptor
int fd;
// Output buffer , Save messages waiting to be sent to other nodes
sds sndbuf;
// Input buffer , Save messages received from other nodes
sds rcvbuf;
// The node associated with this connection , If not, for null
struct clusternode * node;
}Each node holds a clusterState structure , This structure records the current status of the current node cluster
typedf struct clusterState{
// Pointer to the current node
clusterNode *myself;
// The current configuration era for the node , For failover
uint64_t configEpoch;
// The current state of the cluster : Online or offline
int state;
// The number of nodes in the cluster that handle at least one slot
int size;
// Cluster node list ( Include myself)
// The key of the dictionary is the name of the node , The value of the dictionary is... Corresponding to the node clusterNode The pointer
dict *nodes;
}clusterState
CLUSTER MEET Implementation of commands
Client to node A send out CLUSTER MEET command , Let node A The nodes B Add to cluster , Node receiving command A Will be on node B A handshake , To confirm each other's existence .
CLUSTER MEET <ip><port>
1. node A Will be for the node B Create a clusterNode structure ,, And add the structure to your own clusterState.Nodes In the dictionary 2. after , node A Based on the CLUSTER MEET The command is given IP And port number , To the node B Send a MEET news 3. If all goes well , node B Will receive node A Sent MEET news , node B For the node A Create a ClusterNode structure , And add the structure to your own clusterState.Nodes In the dictionary 4. after , node B To the node A Return a PONG news 5. If all goes well , Then the node A At the receiving node B Back to PONG news , Through this article PONG Message node A You can know the node B I have successfully received the one I sent MEET news 6. after , node A To the node B Return a PING news 7. If all goes well , node B Will receive node A Back to PING news , Through this article PING Message node B You can know the node A You have successfully received your returned PONG news , Shake hands with success . 8. After the node A The node will be B Information through Gossip The protocol is propagated to other nodes in the cluster , Let other nodes also be associated with nodes B A handshake , Last node B Will be recognized by all nodes in the cluster .

边栏推荐
- B. I Hate 1111 (记忆化搜索 数论
- C # Advanced Programming - Feature Section
- Table access among Oracle database users
- Considerations for using redis transactions
- Local file upload FTP or remote directory
- How idea breaks point debugging
- 量化框架backtrader之一文读懂Analyzer分析器
- How app inventor accesses resource files in assets directory
- Pdf to word
- First graphical interface (modified version)
猜你喜欢

How to write an amazing design document?

Priority analysis of list variables in ansible playbook and how to separate and summarize list variables

Learning notes of balanced binary tree -- one two pandas

It's called the next generation monitoring system. Let's see how awesome it is

The password does not take effect after redis is set

Tidb data migration (DM) Introduction

Consistency under distributed

How worker threads in the thread pool are recycled

Ticdc introduction

Logback log framework learning and problems
随机推荐
Personal JS learning notes
C drawing table and sending mail function
[Yu Yue education] econometrics reference materials of Jiujiang University
Ticdc introduction
【硬记】脏读、不可重复读、幻读场景核心区别
Try to use renderdoc to view the shader code of UE
How to stop PHP FPM service in php7
GCC compilation process, function library related compilation process
全志V3S环境编译开发流程
The management practice of leading enterprises has proved that what is the core of sustainable development of enterprises?
C # using multithreading
Precautions for passing parameters with byte array
Fundamentals of assembly language: register and addressing mode
Database connection under WinForm
Compilation and development process of Quanzhi v3s environment
C # Advanced Programming - Feature Section
redis-2. Redis string type & bitmap
[log4j2 log framework] sensitive character filtering
Adding certificates to different systems
C language: how to give an alias to a global variable?