Redis notes 05

Source: Internet
Author: User
Tags failover redis cluster redis server

Sentinel

1. Sentinel is just a Redis server running in a special mode that uses a different command table than normal mode, so the commands that Sentinel mode can use are different from the commands that ordinary Redis servers can use.

2. Sentinel reads the user-specified configuration file, creates the appropriate instance structure for each master server to be monitored, and creates a command and subscription connection to the primary server, where the command connection is used to send command requests to the primary server.

The subscription connection is used to receive messages for the specified channel.

3. Sentinel obtains the address information for all slave servers from the primary server by sending the info command to the primary server, creating the appropriate instance structure for these from the server, and connecting to these slave-server commands to connect and subscribe to the connection.

4. In general, Sentinel sends an info command to the monitored primary and slave servers at a frequency of every 10 seconds, when the primary server is offline, or Sentinel is failing over the primary server.

Sentinel changes the frequency of the Send Info command from the server to once per second.

5. For multiple Sentinel monitors of the same primary and slave servers, they announce their presence to other sentinel by sending messages to the _sentinel_:hello channel of the monitored server at a frequency of every two seconds.

6. Each Sentinel will also receive information from other Sentinel messages from the _sentinel_:hello channel and, based on this information, create the appropriate instance structure for the other sentinel, as well as a command connection.

7. Sentinel only creates command connections and subscription connections to the primary and slave servers, and only the command connection is created between Sentinel and Sentinel.

8. Sentinel sends a ping to the instance (including the primary server, slave server, Other Sentinel) at a frequency per second and determines whether the instance is online, based on the instance's response to the ping, and when an instance continues to sentinel in a specified length of time

When sending an invalid reply, Sentinel will judge this instance as a subjective downline.

9. When Sentinel judges a primary service as a subjective downline, it asks other Sentinel monitors for the same primary server to see if they agree that the primary server has entered a subjective offline state.

10. When Sentinel collects enough subjective downline polls, it judges the primary server as an objective downline and initiates a failover operation against the primary server.

11. After the primary server is offline, the server is filtered through a series of filtering criteria, and the replication offsets are compared, and if they are equal, the primary key is more.

Cluster

1. The node adds the other nodes to the cluster in which they are located by shaking hands

2. The 16,384 slots in the cluster can be assigned to each node in the cluster, each node records which slots are assigned to itself, and which slots are assigned to the other nodes.

3. When a command request is received, the node checks to see if it is responsible for the slot in which the key is being processed, and if not, the node returns a moved error to the client, and the information moved the error can direct the client to

To the node that is responsible for the relevant slot.

4. The re-sharding of Redis clusters is performed by Redis-trib, and the key to re-sharding is to transfer all key-value pairs belonging to a slot from one node to another.

5. If Node A is migrating slot I to Node B, when node A fails to find the database key specified by the command in its own database, Node A will return an ask error to the client, directing the client to Node B to continue querying the specified database key.

6. The moved error indicates that the responsibility for the slot has been transferred from one node to another, and the Ask error is only two nodes using a temporary measure in the migration slot process.

7. The slave node in the cluster is used to replicate the primary node and continue processing the command request instead of the master node when the primary node is offline.

8. Nodes in the cluster communicate by sending and receiving messages, and common messages include meet, PING, PONG, PUBLISH, and fail five.

9. The Redis cluster is a distributed database scheme provided by Redis, where the cluster is partitioned for database sharing and provides replication and failover capabilities.

10. A redis cluster is usually composed of multiple nodes, and the work of connecting the nodes can be done using the CLUSTER MEET command: CLUSTER MEET <port> <port>. Send the cluster meet command to a node to let node

The node is handshaking with the node specified by the IP and port, and when the handshake succeeds, the node node adds the nodes specified by IP and port to the cluster where the node is currently located.

One. Redis needs to set custer_enabled to Yes to start cluster mode.

The Redis cluster preserves key-value pairs in the database by sharding: The entire database of the cluster is divided into 16,384 slots (slots), each of which belongs to one of the entire 16,384 slots, and each node in the cluster can process 0 to 16,384 slots.

When the 16,384 slots in the database have nodes in process, the cluster is on-line. If a slot is not being processed, then the cluster is in the offline state (fail).

13. With the CLUSTER addslots command, we can assign one or more slots to the node responsible for: CLUSTER addslots <slot> [Slots ...] Example: CLUSTER addslots 0 1 2 3 ... 5000

The slots of the CLUSTERNODE structure (the tag node is responsible for slots, if the value is 1, is responsible, the value is 0, is not responsible) and the Numslot (number of slots) attribute records which slots the node is responsible for processing.

15. The node sends its own slots array to other nodes in the group via messages. Other nodes store information in their own clusternode

The slots array in the CLUSTERSTATE structure records all 16,384 slot assignment information in the cluster.

The clusterstate.slots Array records assignment information for all slots in the cluster, while the clusternode.slots array only records slot assignment information for the nodes represented by the Clusternode structure, which is a key difference between the two slots data.

18. Send to a node: CLUSTER repicate <node_id> allows the node receiving the command to become the slave node of the node specified node_id and begin copying the primary node.

Redis notes 05

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.