当前位置:网站首页>About redis master-slave replication
About redis master-slave replication
2022-06-27 17:32:00 【Clan life push】
Master slave copy
Master slave copy , It means to put one Redis Server data , Copy to other Redis The server . The former is called the main node (master), The latter is called the slave node (slave); Data replication is one-way , From master to slave only .
Master slave replication is divided into three stages
Connect from node , Request full replication ,
Master node execution bgsave The instruction generates the current data rdb snapshot , Send data to the slave node , And create a buffer , This buffer records all write commands from the current time
Clear your original data from the node , receive rdb And load , Synchronize the database to the master node to execute bgsave The state of
The master node sends the instructions of the buffer mentioned above to the slave node , Execute these instructions from the node , So that the database is up to date
Incremental master-slave replication
Both master and slave nodes maintain an offset offset, This offset Represents the number of bytes sent by the master node to the slave node . When the master-slave node offset In unison , We can think that the two databases are in the same state .
The slave node is disconnected for some reason during the connection process , Restore connection , At this point, incremental replication is requested .
The master node maintains a replication backlog buffer , He is a first in, first out queue , Each time a write command is sent to the slave node, the command will also be sent to the buffer , The buffer also stores offset.
After the connection is restored from the node , Go to the copy backlog buffer to view your own offset Whether in buffer in , If in , Just start from the recording position , Do incremental replication . If not here buffer in , Then perform a full copy
How to handle expired data
There are two types of expired data processing
- Lazy deletion : The server will not actively delete , When the client query data is , If the data is out of date , Then the server determines whether to delete
- Delete periodically : Delete expired data regularly , But operate release frequently , Loading memory will affect server performance , Therefore, it is necessary to limit the frequency and execution time of deletion .
Do not delete data from the node , Therefore, the expired data will not be deleted when the slave node reads the expired data , Only null will be returned .
Sentinel mode
brief introduction
Generalize , The sentry is divided into three questions : monitor , Elector , notice .
monitor : Monitor the health of the node , And make timely adjustments
Elector : When the master node is down , The sentinel chooses the master
notice : Notify the client of the current master node address
The sentry cluster
In order to prevent network fluctuations from causing a single sentinel to misjudge , Therefore, the concept of sentinel cluster mode is introduced
How did the Sentinels find each other ?
Through the master node , Subscribe to news , And find each other , Resume the connection between sentinels
How to know from the library ?
To be improved
Judge the offline rule
Divided into two
- Subjective offline : Just need a single sentry to think offline , This node is considered offline , Used to judge from the offline of a node .
- Objective offline : The sentinel cluster needs to vote to determine whether the node is offline , When the number of tickets exceeds the set value , To judge the offline , It is used to judge the downline of the master node .
Elector
It's based on
- Select the node with high server configuration as the primary node
- Select the node with the longest running time , The longer it takes to run , The more stable the node is
- Select according to the configuration file
The process
- The selected node is the master node
- Other nodes connect to this node
- The original master node becomes a slave node
边栏推荐
- Kubernetes basic self-study series | introduction to ingress API
- 树莓派初步使用
- 数组表示若干个区间的集合,请你合并所有重叠的区间,并返回 一个不重叠的区间数组,该数组需恰好覆盖输入中的所有区间 。【LeetCodeHot100】
- P4251 [scoi2015] small convex play matrix (still a little confused)
- Simulated process scheduling
- Adaoracle supports multi chain distributed Oracle with wide area node quotation
- Part 30 supplement (30) ECMAScript object
- C language set operation
- ROS "topic" programming implementation
- Defiato is an innovation that combines user-friendly features of a centralized platform with defi services
猜你喜欢

Community sharing jumpserver in the eyes of senior open source users: a fortress machine for "Crazy" iteration

一个机器人位于一个 m x n 网格的左上角 。机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角。问总共有多少条不同的路径?【LeetCodeHot100】

d3dx9_ What if 27.dll is lost? d3dx9_ How to repair 27.dll?

About MySQL: the phenomenon and background of the problem

leetcode 142. Circular linked list II

How to improve it electronic equipment performance management

继手机之后 报道称三星也削减了电视等家电产品线的产量

Mihayou sued Minmetals trust, which was exposed to product thunderstorms
![[leetcode] 2. Add two numbers (user-defined listnode), medium](/img/27/1e7ce0e08d7428f0f594a3477e35df.jpg)
[leetcode] 2. Add two numbers (user-defined listnode), medium

2022 Liaoning latest fire facility operator simulation test question bank and answers
随机推荐
The two trump brand products of Langjiu are resonating in Chengdu, continuously driving the consumption wave of bottled liquor
leetcode 19. Delete the penultimate node of the linked list
Oracle TRUNC function processing date format
Community sharing jumpserver in the eyes of senior open source users: a fortress machine for "Crazy" iteration
wheel ui
全面解析零知识证明:消解扩容难题 重新定义「隐私安全」
电子智慧套装教程
D use in
Related configuration commands of Huawei LACP
(5) SPI application design and simulation verification 1 - logic sorting
Explain the distributed computing of Apache skywalking OAP in detail
Ten common methods of arrays tools
ROS "topic" programming implementation
leetcode 200. Number of islands
Kubernetes basic self-study series | introduction to ingress API
# Cesium实现卫星在轨绕行
[multithreading] thread communication scheduling, waiting set wait(), notify()
Delete duplicate elements in the sorting linked list
Solving Poisson equation by tensorflow
简历如何去写?