Redis – Sentry (handling of data loss)


As mentioned in redis – sentinel (high availability), sentinel does not guarantee zero data loss, but it also provides a method to minimize data loss.
The first data loss scenario is shown in the following figure. When data is lost, the replication of redis is asynchronous, that is, it is the AP model. Compared with the CP model, the performance of AP simulation is better, but the data consistency can not be guaranteed. Therefore, the client returns correctly after the master writes data, and the master synchronizes the data asynchronously to the slave.
Redis - Sentry (handling of data loss)
In the second data loss scenario, as shown in the following figure, there is a brain crack. Although the master is normal, the sentinel cluster cannot communicate with him. At this time, it will think that the master is down and perform failover. However, before notifying the client, the client will always write data to the old master, and the old master will restart and connect to the new master after network processing, The old data will be deleted, resulting in the loss of this part of the data.
Redis - Sentry (handling of data loss)
Redis provides the following two configurations to minimize data loss:

min-replicas-to-write 1
min-replicas-max-lag 10

This means that if at least one slave has not been synchronized for 10 seconds, the master will suspend receiving requests. Therefore, it will not be said that the master writes data all the time and the slave is not synchronized. If the above two scenarios occur, the data will be lost for up to 10 seconds. On the other hand, after 10 seconds, the availability is reduced and the data consistency is improved. The AP model is temporarily changed into the CP model.