Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Redis cluster refragmentation (add / remove nodes) [theory]

2025-03-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Principle of redis cluster resharding: (adding or removing nodes)

Take adding nodes as an example:

We only need to redistribute hash slots that have been allocated to nodes.

Note: When hash slot is reallocated, if key-value exists in the slot, key-value will also be allocated together.

For example:

Node1 hash slot: 0-5000

Node2 hash slot: 5001-10000

Node3 hash slot: 10001-16383

Now add node4:

We can adjust the hash slot of node3 to: 10001-15000, and the hash slot of node4:15001-16383

You can also divide a portion of the hash slots from each of the three existing nodes and give them to the new node.

Refragmentation of redis clusters is performed by redis cluster management software redis-trib,

However, it does not support automatic fragmentation and needs to calculate which nodes to allocate slots from.

When redis cluster is re-fragmented, the client gets the data principle:

When resharding, the cluster does not need to go offline, and both source and target nodes can continue to process command requests.

During hash slot migration (some key-values in node3, some key-values in node4)

If the client sends node3 a command related to database key:

1) Node3 will first look up the requested key in its own database,

If found, execute the command sent by the client directly.

2) If it is not found, node3 returns an ASK error to the client, directing the client to node4,

And the client needs to send again the key-related command it wants to execute.

3) The client goes to node4 and sends the ASKING command first and then the key-related command it wants to execute again.

If you directly send the key related command you want to execute, node4 does not process it at this time.

Because the slot where the key is located has not been migrated yet, and the slot still belongs to node3, an error will be returned to the client.

But if you send ASKING first, node4 will not be able to execute the key command

Not only will it check whether the slot to which the key belongs to itself,

It also checks the migration_slots_to array (moving to its own slot)

Determine if the key-related slot is moving to itself, and if so, execute the key-related command.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report