迁移数据库分片
如何将数据库分片迁移到 Redis Software 集群中的其他节点。
Redis 企业软件 |
---|
要将数据库分片迁移到集群中的其他节点,您可以使用rladmin migrate
命令或 REST API 请求。
分片迁移的使用案例
在以下情况下,将数据库分片迁移到其他节点:
-
在节点删除之前。
-
在出现延迟问题或节点之间的负载分配不均匀时手动平衡数据库。
-
管理节点资源,例如内存使用情况。
分片迁移的注意事项
对于具有复制功能的数据库:
-
迁移分片不会导致中断,因为主分片仍然可用。
-
如果您尝试迁移主分片,则它将被降级为副本分片,并且副本分片将在迁移之前提升为主分片。如果您将
"preserve_roles": true
在请求中,迁移完成后将进行第二次故障转移,以将迁移的分片的角色更改回主分片。
对于没有复制的数据库,在迁移完成之前,迁移的分片将不可用。
在这两种情况下,连接的客户端都不应断开连接。
如果在同一节点上放置了太多主分片,则可能会影响数据库性能。
迁移特定分片
要迁移特定的数据库分片,请使用以下方法之一:
-
rladmin migrate shard <shard_id> target_node <node_id>
-
Migrate shard REST API request:
Specify the ID of the shard to migrate in the request path and the destination node's ID as the
target_node_uid
in the request body. See the request reference for more options.POST /v1/shards/<shard_id>/actions/migrate { "target_node_uid": <node_id> }
Example JSON response body:
{ "action_uid": "<action_id>", "description": "Migrate was triggered" }
You can track the action's progress with a
GET /v1/actions/<action_uid>
request.
Migrate multiple shards
To migrate multiple database shards, use one of the following methods:
-
rladmin migrate shard <shard_id1> <shard_id2> <shard_id3> target_node <node_id>
-
Migrate multiple shards REST API request:
Specify the IDs of the shards to migrate in the shard_uids
list and the destination node's ID as the target_node_uid
in the request body. See the request reference for more options.
POST /v1/shards/actions/migrate
{
"shard_uids": ["<shard_id1>","<shard_id2>","<shard_id3>"],
"target_node_uid": <node_id>
}
Example JSON response body:
{
"action_uid": "<action_id>",
"description": "Migrate was triggered"
}
You can track the action's progress with a GET /v1/actions/<action_uid>
request.
Migrate all shards from a node
To migrate all shards from a specific node to another node, run rladmin migrate all_shards
:
rladmin migrate node <origin_node_id> all_shards target_node <node_id>
Migrate primary shards
You can use the rladmin migrate all_master_shards
command to migrate all primary shards for a specific database or node to another node in the cluster.
To migrate a specific database's primary shards:
rladmin migrate db db:<id> all_master_shards target_node <node_id>
To migrate all primary shards from a specific node:
rladmin migrate node <origin_node_id> all_master_shards target_node <node_id>
Migrate replica shards
You can use the rladmin migrate all_slave_shards
command to migrate all replica shards for a specific database or node to another node in the cluster.
To migrate a specific database's replica shards:
rladmin migrate db db:<id> all_slave_shards target_node <node_id>
To migrate all replica shards from a specific node:
rladmin migrate node <origin_node_id> all_slave_shards target_node <node_id>
On this page