role
When a fault occurs, the master/slave switch can be automatically performed, and the program does not need to restart.Redis Sentinel cluster is regarded as a Zookeeper cluster, which is the heart of cluster high availability. It is generally composed of 3~5 nodes, so that the cluster can operate normally even with the failure of some nodes. It is responsible for continuously monitoring the health of the primary and secondary nodes. When the primary node fails, it automatically selects an optimal (priority > Data volume > RUN ID) to switch the secondary node to the primary node. When a client connects to a cluster, it first connects to Sentinel, which queries the address of the primary node, and then connects to the primary node for data interaction. When the primary node fails, the client asks for the address again. Sentinel tells the client the latest primary node address. The application will then automatically complete the node switch without a restart. For example, if the primary node in the figure above fails, the cluster may automatically adjust to the structure shown in the figure below.As you can see from this diagram, the master node is down, the original master/slave replication is down, and the client is down with the damaged master node. The secondary node is promoted to the new primary node, and other secondary nodes establish replication relationships with the new primary node. Clients continue to interact with each other through the new master node. Sentinel continuously monitors the node that has failed, and when it recovers, the cluster adjusts to the image below.At this point, the primary node that was previously suspended is now a secondary node, and the replication relationship is established from the new primary node.
Message loss
Redis uses asynchronous replication between master and slave nodes, which means that when the master node is down, the slave node may not receive all the synchronization messages, and the unsynchronized messages will be lost. If the master-slave latency is particularly high, the loss of data is likely to be particularly high. Sentinel does not guarantee complete message loss, but it does try to minimize message loss. It has two options to limit the master-slave delay. Min-slave-to-write 1 min-slave-max-lag 10 The first parameter indicates that the master node must have at least one slave node that performs normal replication. Otherwise, the external write service is stopped and the availability is lost. Normal replication is controlled by the second parameter, which is measured in seconds, indicating that if no feedback is received from the node every 10 seconds, it means that the synchronization from the node is abnormal, that the network is disconnected, or that no feedback has been received.