1. Two cases of data loss

The active/standby switchover may cause data loss.

1.1. Data Loss caused by Asynchronous Replication

Because master -> slave replication is asynchronous, some data may break down before it is replicated to the slave, and some data may be lost

1.2 Data loss caused by split-brain

Split brain means that one of the maser’s machines suddenly disconnects from the normal network and cannot be connected to other slave machines, but in fact the master is still running. At this point, the sentry might think that the master is down, open elections, and switch the other slaves to master. At this point, There are two masters in the cluster, which is called split brain. In this case, although a slave is switched to the master, data written to the old master may be lost before the slave is switched to the new master. Therefore, when the master recovers again, The slave will be attached to the new master as a slave, its own data will be cleared, and data will be copied from the new master

2. Resolve data loss caused by asynchronous replication and split data

# redis.conf configures min-rabes-to-write 1 min-rabes-max-lag 10Copy the code

The above two configurations reduce data loss caused by asynchronous replication and split brain

Reduce data loss in asynchronous replication

With min-rabes-max-lag this configuration ensures that if the slave replicated data and ack delay was too long, it would think that too much data was lost after the master went down and would reject the write request, thus allowing the master to go down due to some data loss.

2.2 Reduce data loss of split-brain

If a master has a split brain and loses contact with other slaves, these two configurations ensure that if the master cannot continue to send data to a specified number of slaves and the slave does not send itself an ACK message for more than 10 seconds, the write request will be rejected. In this way, the old master will not accept new data from the client, thus avoiding data loss. The configuration ensures that if the master loses a connection with any slave and finds no ack from the slave 10 seconds later, the new write request will be rejected. Therefore, in the split brain scenario, the data will be lost for a maximum of 10 seconds.

More exciting, Weixin pays attention to “SpringForAll Community”

This article is published by OpenWrite!