redis re slicing

Why does re segmentation occur
redis cluster will be fragmented again after the following conditions occur:

  1. New nodes join
  2. There are nodes that need to be offline
  3. The data distribution of some nodes is uneven and needs to be readjusted

How to re segment needs to be used manually for re segmentation Trib tool, the process is as follows:

  1. Execute the command/ redis-trib.rb reshard ip:port
    After executing this command, the console will display the information of all nodes in the cluster, including ip,port, slots in each node, master/slave role of each node, and ID of each node. similar:
$ ./redis-trib.rb reshard
Connecting to node OK
Connecting to node OK
Connecting to node OK
Connecting to node OK
Connecting to node OK
Connecting to node OK
>>> Performing Cluster Check (using node
M: 9991306f0e50640a5684f1958fd754b38fa034c9
slots:0-5460 (5461 slots) master
M: 393c6df5eb4b4cec323f0e4ca961c8b256e3460a
slots:10922-16383 (5462 slots) master
S: 3375be2ccc321932e8853234ffa87ee9fde973ff
slots: (0 slots) slave
M: e68e52cee0550f558b03b342f2f0354d2b8a083b
slots:5461-10921 (5461 slots) master
S: 48b728dbcedff6bf056231eb44990b7d1c35c3e0
slots: (0 slots) slave
S: 345ede084ac784a5c030a0387f8aaa9edfc59af3
slots: (0 slots) slave
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
How many slots do you want to move (from 1 to 16384)? 1000

It will also ask how many slots we need to migrate. In the example, we migrate 1000

  1. Specify the destination node for the migration
    Here, we need to enter the ID of the target node rather than the ip+port of the target node
$ ./redis-trib.rb reshard
What is the receiving node ID? 9991306f0e50640a5684f1958fd754b38fa034c9

We have selected the node 9991306f0e50640a5684f198fd754b38fa034c9

  1. Specify the source node for the migration
    That is, which nodes we want to migrate 1000 slots to the target node. If we do not specify a specific node but enter all, all the primary nodes in the cluster will become the source nodes. Redis trib will take a part of the slots from each source node to gather up 1000, and then move to the target node:
$ ./redis-trib.rb reshard
Please enter all the source node IDs.
Type 'all' to use all the nodes as source nodes for the hash slots.
Type 'done' once you entered all the source nodes IDs.
Source node #1:all

After entering all, redis trib will list which slot s are migrated from which nodes. If there is no problem, we need to confirm:

$ ./redis-trib.rb reshard
Moving slot 11421 from 393c6df5eb4b4cec323f0e4ca961c8b256e3460a
Moving slot 11422 from 393c6df5eb4b4cec323f0e4ca961c8b256e3460a
Moving slot 5461 from e68e52cee0550f558b03b342f2f0354d2b8a083b
Moving slot 5469 from e68e52cee0550f558b03b342f2f0354d2b8a083b
Moving slot 5959 from e68e52cee0550f558b03b342f2f0354d2b8a083b
Do you want to proceed with the proposed reshard plan (yes/no)? yes

Enter yes to confirm the migration.
After the migration, redis trib will send cluster setslot < slot > node < target to all nodes in the cluster_ ID > command, so that all nodes in the cluster will update the correspondence between the latest slots and nodes.

ASK error and automatic steering
During the migration process, the redis cluster will continue to respond to user requests, but if the key involved just belongs to the slot being migrated, an ask error will appear. Of course, this ask error will not be returned to the user. The cluster will automatically turn according to the IP and port in the response ask information.


  1. After the node changes, it needs to be re segmented
  2. Re partition, use the redis trib tool to specify the migration target node, the number of slots to be migrated, and the source node to be migrated
  3. User requests are also processed during migration

Reference article: Redis cluster re fragmentation

Keywords: redis-cluster

Added by scoppc on Wed, 05 Jan 2022 13:07:50 +0200