0
0
Redisquery~10 mins

Resharding hash slots in Redis - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Resharding hash slots
Start: Cluster with N nodes
Identify hash slots to move
For each slot to move
Set slot state to importing on target node
Set slot state to migrating on source node
Migrate keys in slot from source to target
Update slot ownership to target node
Repeat for all slots
Cluster resharding complete
This flow shows how hash slots are moved from one Redis cluster node to another to balance data.
Execution Sample
Redis
CLUSTER SETSLOT 1234 IMPORTING <target-node-id>
CLUSTER SETSLOT 1234 MIGRATING <source-node-id>
MIGRATE <target-ip> <target-port> "" 0 5000 KEYS key1 key2
CLUSTER SETSLOT 1234 NODE <target-node-id>
Commands to move hash slot 1234 from source node to target node by setting states and migrating keys.
Execution Table
StepActionSlot State Source NodeSlot State Target NodeKeys MigratedResult
1Identify slot 1234 to moveOwnedNot ownedNoneReady to move slot 1234
2Set slot 1234 IMPORTING on target nodeOwnedIMPORTINGNoneTarget node ready to receive keys
3Set slot 1234 MIGRATING on source nodeMIGRATINGIMPORTINGNoneSource node ready to send keys
4Migrate keys key1, key2 from source to targetMIGRATINGIMPORTINGkey1, key2Keys moved successfully
5Set slot 1234 ownership to target nodeNot ownedOwnedAll keysSlot ownership updated
6Repeat for other slots or finishN/AN/AN/AResharding complete
💡 All selected slots moved and ownership updated; cluster balanced
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4After Step 5Final
Slot 1234 State on Source NodeOwnedOwnedMIGRATINGMIGRATINGNot ownedNot owned
Slot 1234 State on Target NodeNot ownedIMPORTINGIMPORTINGIMPORTINGOwnedOwned
Keys in Slot 1234 on Source Nodekey1, key2key1, key2key1, key2NoneNoneNone
Keys in Slot 1234 on Target NodeNoneNoneNonekey1, key2key1, key2key1, key2
Key Moments - 3 Insights
Why do we set the slot state to IMPORTING on the target node before migrating keys?
Setting IMPORTING on the target node signals it to accept keys for that slot, ensuring keys are not lost during migration (see execution_table step 2).
What happens if we migrate keys before setting MIGRATING on the source node?
Without MIGRATING state on source, the source node might not allow key migration, causing errors or data inconsistency (see execution_table step 3).
Why do we update slot ownership only after migrating all keys?
Updating ownership too early could cause clients to send commands to the wrong node, leading to errors or lost data (see execution_table step 5).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step does the source node stop owning the slot?
AStep 3
BStep 5
CStep 4
DStep 6
💡 Hint
Check the 'Slot State Source Node' column in execution_table rows
According to variable_tracker, after migrating keys, where are the keys located?
AStill on source node
BOn both source and target nodes
COnly on target node
DDeleted from both nodes
💡 Hint
Look at 'Keys in Slot 1234 on Target Node' and 'Keys in Slot 1234 on Source Node' after Step 4
If we skipped setting IMPORTING on the target node, what would likely happen?
ATarget node rejects incoming keys
BKeys migrate successfully anyway
CSource node refuses to migrate keys
DSlot ownership updates immediately
💡 Hint
Refer to key_moments about IMPORTING state importance and execution_table step 2
Concept Snapshot
Resharding hash slots moves data between Redis cluster nodes.
Steps: set IMPORTING on target, MIGRATING on source, migrate keys, update slot ownership.
This ensures no data loss and consistent cluster state.
Always migrate keys before changing ownership.
Use CLUSTER SETSLOT and MIGRATE commands.
Full Transcript
Resharding hash slots in Redis cluster involves moving data slots from one node to another to balance load. The process starts by identifying which slots to move. Then, the target node is set to IMPORTING state for those slots, signaling readiness to receive keys. The source node sets the slot to MIGRATING state, allowing keys to be sent. Keys belonging to the slot are migrated from source to target. After all keys are moved, the slot ownership is updated to the target node. This sequence prevents data loss and ensures clients access the correct node. The execution table shows each step's slot states and keys moved. Variable tracking confirms keys move from source to target. Key moments clarify why states must be set in order. The visual quiz tests understanding of slot ownership changes, key locations, and state importance. The snapshot summarizes the commands and order needed for safe resharding.