What is redis cluster split brain?
Redis cluster brain splitting means that due to network problems, the redis master node, the redis slave node and the sentinel cluster are in different network partitions. At this time, the sentinel cluster cannot sense the existence of the master, so Promote the slave node to the master node. (Recommended learning: redis video tutorial )
There are two different master nodes at this time, just like a brain split into two.
In the cluster split-brain problem, if the client continues to write data based on the original master node, the new master node will not be able to synchronize the data. When the network problem is resolved, the sentinel cluster will replace the original master node with the original master node. The node is reduced to a slave node. At this time, synchronizing data from the new master will cause a large amount of data loss.
Solution
There are two parameters in the redis configuration file
min-slaves-to-write 3 min-slaves-max-lag 10
The first parameter Represents the minimum number of slaves connected to the master
The second parameter indicates the maximum delay time for the slave to connect to the master
If the number of slaves connected to the master is less than the first parameter, and the ping delay If the time is less than or equal to the second parameter, then the master will reject the write request. After configuring these two parameters, if a cluster brain split occurs, the original master node will reject the write request from the client, which can reduce the amount of data synchronization. of data lost.
Note: The parameters in the newer version of the redis.conf file have become
min-replicas-to-write 3 min-replicas-max-lag 10
The data loss problem in the case of asynchronous replication in redis can also use these two parameters
The above is the detailed content of How to prevent split-brain in redis cluster. For more information, please follow other related articles on the PHP Chinese website!