|
| 1 | +--- |
| 2 | +acl_categories: |
| 3 | +- '@admin' |
| 4 | +- '@slow' |
| 5 | +- '@dangerous' |
| 6 | +arguments: |
| 7 | +- arguments: |
| 8 | + - arguments: |
| 9 | + - display_text: start-slot |
| 10 | + name: start-slot |
| 11 | + type: integer |
| 12 | + - display_text: end-slot |
| 13 | + name: end-slot |
| 14 | + type: integer |
| 15 | + multiple: true |
| 16 | + name: import |
| 17 | + token: IMPORT |
| 18 | + type: block |
| 19 | + - arguments: |
| 20 | + - display_text: task-id |
| 21 | + name: task-id |
| 22 | + token: ID |
| 23 | + type: string |
| 24 | + - display_text: all |
| 25 | + name: all |
| 26 | + token: ALL |
| 27 | + type: pure-token |
| 28 | + name: cancel |
| 29 | + token: CANCEL |
| 30 | + type: oneof |
| 31 | + - arguments: |
| 32 | + - display_text: task-id |
| 33 | + name: task-id |
| 34 | + optional: true |
| 35 | + token: ID |
| 36 | + type: string |
| 37 | + - display_text: all |
| 38 | + name: all |
| 39 | + optional: true |
| 40 | + token: ALL |
| 41 | + type: pure-token |
| 42 | + name: status |
| 43 | + token: STATUS |
| 44 | + type: block |
| 45 | + name: subcommand |
| 46 | + type: oneof |
| 47 | +arity: -4 |
| 48 | +categories: |
| 49 | +- docs |
| 50 | +- develop |
| 51 | +- stack |
| 52 | +- oss |
| 53 | +- rs |
| 54 | +- rc |
| 55 | +- oss |
| 56 | +- kubernetes |
| 57 | +- clients |
| 58 | +command_flags: |
| 59 | +- admin |
| 60 | +- stale |
| 61 | +- no_async_loading |
| 62 | +complexity: O(N) where N is the total number of the slots between the start slot and |
| 63 | + end slot arguments. |
| 64 | +description: Start, monitor, and cancel atomic slot migration tasks. |
| 65 | +group: cluster |
| 66 | +hidden: false |
| 67 | +linkTitle: CLUSTER MIGRATION |
| 68 | +since: 8.4.0 |
| 69 | +summary: Start, monitor, and cancel atomic slot migration tasks. |
| 70 | +syntax_fmt: "CLUSTER MIGRATION <IMPORT\_start-slot end-slot [start-slot end-slot ...]\n\ |
| 71 | + \ | CANCEL\_<ID\_task-id | ALL> | STATUS\_<ID\_task-id | ALL>" |
| 72 | +syntax_str: '' |
| 73 | +title: CLUSTER MIGRATION |
| 74 | +--- |
| 75 | + |
| 76 | +The `CLUSTER MIGRATION` command provides atomic slot migration functionality for Redis Cluster. This command allows you to import slots from other nodes, monitor the progress of migration tasks, and cancel ongoing migrations. |
| 77 | + |
| 78 | +## Required arguments |
| 79 | + |
| 80 | +<details open><summary><code>subcommand</code></summary> |
| 81 | + |
| 82 | +The subcommand specifies the operation to perform: |
| 83 | + |
| 84 | +- `IMPORT <start-slot> <end-slot> [<start-slot> <end-slot> ...]`: Executes on the destination master. Accepts multiple slot ranges and triggers atomic migration for the specified ranges. Returns a task ID that you can use to monitor the status of the task. |
| 85 | + |
| 86 | +- `CANCEL <ID <task-id> | ALL>`: Cancels an ongoing migration task by its ID or cancels all tasks if `ALL` is specified. Note: Cancelling a task on the source node does not stop the migration on the destination node, which will continue retrying until it is also cancelled there. |
| 87 | + |
| 88 | +- `STATUS [ID <task-id> | ALL]`: Displays the status of current and completed atomic slot migration tasks. If a specific task ID is provided, it returns detailed information for that task only. If `ALL` is specified, it returns the status of all ongoing and completed tasks. |
| 89 | + |
| 90 | +</details> |
| 91 | + |
| 92 | +## Examples |
| 93 | + |
| 94 | +Import slots 0-1000 and 2000-3000 to the current node: |
| 95 | + |
| 96 | +```bash |
| 97 | +CLUSTER MIGRATION IMPORT 0 1000 2000 3000 |
| 98 | +``` |
| 99 | + |
| 100 | +Check the status of all migration tasks: |
| 101 | + |
| 102 | +```bash |
| 103 | +CLUSTER MIGRATION STATUS ALL |
| 104 | +``` |
| 105 | + |
| 106 | +Check the status of a specific migration task: |
| 107 | + |
| 108 | +```bash |
| 109 | +CLUSTER MIGRATION STATUS ID 24cf41718b20f7f05901743dffc40bc9b15db339 |
| 110 | +``` |
| 111 | + |
| 112 | +Cancel a specific migration task: |
| 113 | + |
| 114 | +```bash |
| 115 | +CLUSTER MIGRATION CANCEL ID 24cf41718b20f7f05901743dffc40bc9b15db339 |
| 116 | +``` |
| 117 | + |
| 118 | +Cancel all migration tasks: |
| 119 | + |
| 120 | +```bash |
| 121 | +CLUSTER MIGRATION CANCEL ALL |
| 122 | +``` |
| 123 | + |
| 124 | +## Return information |
| 125 | + |
| 126 | +{{< multitabs id="return-info" |
| 127 | + tab1="RESP2" |
| 128 | + tab2="RESP3" >}} |
| 129 | + |
| 130 | +For the `IMPORT` subcommand: |
| 131 | +[Bulk string reply](../../develop/reference/protocol-spec#bulk-strings): task ID on success, or error message on failure. |
| 132 | + |
| 133 | +For the `CANCEL` subcommand: |
| 134 | +[Integer reply](../../develop/reference/protocol-spec#integers): number of cancelled tasks. |
| 135 | + |
| 136 | +For the `STATUS` subcommand: |
| 137 | +[Array reply](../../develop/reference/protocol-spec#arrays): a list of migration task details. Each task is represented as an array containing field-value pairs: |
| 138 | +- `id`: Task identifier |
| 139 | +- `slots`: Slot range being imported or migrated |
| 140 | +- `source`: Source node ID |
| 141 | +- `dest`: Destination node ID |
| 142 | +- `operation`: Operation type ("import" or "migrate") |
| 143 | +- `state`: Current state ("completed", "in_progress", etc.) |
| 144 | +- `last_error`: Last error message (empty if none) |
| 145 | +- `retries`: Number of retry attempts |
| 146 | +- `create_time`: Task creation timestamp |
| 147 | +- `start_time`: Task start timestamp |
| 148 | +- `end_time`: Task completion timestamp (if completed) |
| 149 | +- `write_pause_ms`: Write pause duration in milliseconds |
| 150 | + |
| 151 | +-tab-sep- |
| 152 | + |
| 153 | +For the `IMPORT` subcommand: |
| 154 | +[Bulk string reply](../../develop/reference/protocol-spec#bulk-strings): task ID on success, or error message on failure. |
| 155 | + |
| 156 | +For the `CANCEL` subcommand: |
| 157 | +[Integer reply](../../develop/reference/protocol-spec#integers): number of cancelled tasks. |
| 158 | + |
| 159 | +For the `STATUS` subcommand: |
| 160 | +[Array reply](../../develop/reference/protocol-spec#arrays): a list of migration task details. Each task is represented as an array containing field-value pairs: |
| 161 | +- `id`: Task identifier |
| 162 | +- `slots`: Slot range being migrated |
| 163 | +- `source`: Source node ID |
| 164 | +- `dest`: Destination node ID |
| 165 | +- `operation`: Operation type (typically "migrate") |
| 166 | +- `state`: Current state ("completed", "in_progress", etc.) |
| 167 | +- `last_error`: Last error message (empty if none) |
| 168 | +- `retries`: Number of retry attempts |
| 169 | +- `create_time`: Task creation timestamp |
| 170 | +- `start_time`: Task start timestamp |
| 171 | +- `end_time`: Task completion timestamp (if completed) |
| 172 | +- `write_pause_ms`: Write pause duration in milliseconds |
| 173 | + |
| 174 | +{{< /multitabs >}} |
| 175 | + |
| 176 | +## Notes |
| 177 | + |
| 178 | +- The atomic slot migration feature is available starting from Redis 8.4.0. |
| 179 | +- Cancelling a task on the source node does not automatically stop the migration on the destination node. |
| 180 | +- In `CLUSTER MIGRATION STATUS` output, the "state" field will show `completed` for successful operations. |
| 181 | +- Tasks with empty "last_error" fields indicate no errors occurred during the migration process. |
| 182 | + |
| 183 | +## Key visibility during migration |
| 184 | + |
| 185 | +During atomic slot migration operations, keys in unowned slotsmay be filtered out from the following commands while importing or trimming is in progress: |
| 186 | + |
| 187 | +- [`KEYS`]({{< relref "/commands/keys" >}}) |
| 188 | +- [`SCAN`]({{< relref "/commands/scan" >}}) |
| 189 | +- [`RANDOMKEY`]({{< relref "/commands/randomkey" >}}) |
| 190 | +- [`CLUSTER GETKEYSINSLOT`]({{< relref "/commands/cluster-getkeysinslot" >}}) |
| 191 | +- [`DBSIZE`]({{< relref "/commands/dbsize" >}}) |
| 192 | +- [`CLUSTER COUNTKEYSINSLOT`]({{< relref "/commands/cluster-countkeysinslot" >}}) |
| 193 | + |
| 194 | +The [`INFO KEYSPACE`]({{< relref "/commands/info" >}}) command will continue to reflect the actual number of keys, including those being imported. |
| 195 | + |
| 196 | +## Related configuration |
| 197 | + |
| 198 | +- `cluster-slot-migration-handoff-max-lag-bytes`: After slot snapshot completion, if remaining replication stream size falls below this threshold, the source node pauses writes to hand off slot ownership. Higher values trigger handoff earlier but may cause longer write pauses. Lower values result in shorter write pauses but may be harder to reach with steady incoming writes (default: 1MB). |
| 199 | +- `cluster-slot-migration-write-pause-timeout`: Maximum duration that the source node pauses writes during ASM handoff. If the destination fails to take over slots within this timeout, the source assumes migration failed and resumes writes (default: 10 seconds). |
0 commit comments