分片副本管理
提示
仅企业版支持
副本管理对于线上服务至关重要,CnosDB提供如下一些副本管理相关命令:
- 副本分布查看
- 增加副本
- 删除副本
- 提升节点为主
- 销毁复制组
副本以及分片相关概念可以参见 数据分片与复制
查看副本分布
show replicas
show replicas
返回复制组相关信息,包括分布在哪些节点、开始结束时间、所属的数据库名字等,如下所示:
my_db ❯ show replicas;
+------------+----------+--------------+-------------------------+-------------------------+
| replica_id | location | database | start_time | end_time |
+------------+----------+--------------+-------------------------+-------------------------+
| 2 | 1001* | usage_schema | 2023-12-19 00:00:00 UTC | 2024-12-18 00:00:00 UTC |
| 5 | 1001* | my_db | 2022-11-02 23:00:00 UTC | 2022-11-03 07:20:00 UTC |
+------------+----------+--------------+-------------------------+-------------------------+
*
标识复制组的主节点所位于的节点ID
增加副本
replica add
replica add
复制组在指定节点增加一个副本,如下所示:
my_db ❯ replica add replica_id 5 node_id 2001;
Query took 0.058 seconds.
my_db ❯ show replicas;
+------------+------------+--------------+-------------------------+-------------------------+
| replica_id | location | database | start_time | end_time |
+------------+------------+--------------+-------------------------+-------------------------+
| 2 | 1001* | usage_schema | 2023-12-19 00:00:00 UTC | 2024-12-18 00:00:00 UTC |
| 5 | 1001*,2001 | my_db | 2022-11-02 23:00:00 UTC | 2022-11-03 07:20:00 UTC |
+------------+------------+--------------+-------------------------+-------------------------+
复制组5在2001节点增加了一个副本;主节点是1001,从节点是2001
提升节点为主
replica promote
replica promote
提升一个从节点为主节点,这在更换机器等运维过程中可能会用到,如下所示:
my_db ❯ replica promote replica_id 5 node_id 2001;
Query took 0.854 seconds.
my_db ❯ show replicas;
+------------+------------+--------------+-------------------------+-------------------------+
| replica_id | location | database | start_time | end_time |
+------------+------------+--------------+-------------------------+-------------------------+
| 2 | 1001* | usage_schema | 2023-12-19 00:00:00 UTC | 2024-12-18 00:00:00 UTC |
| 5 | 1001,2001* | my_db | 2022-11-02 23:00:00 UTC | 2022-11-03 07:20:00 UTC |
+------------+------------+--------------+-------------------------+-------------------------+
Query took 0.010 seconds.
提升复制组5在2001节点为主节点;主节点变成2001,1001降为从节点
删除副本
replica remove
replica remove
删除一个副本,主从副本都支持删除;如果删除的是主节点则会从剩余节点随机挑选一个为新的主,如下所示:
my_db ❯ replica remove replica_id 5 node_id 2001;
Query took 0.036 seconds.
my_db ❯ show replicas;
+------------+----------+--------------+-------------------------+-------------------------+
| replica_id | location | database | start_time | end_time |
+------------+----------+--------------+-------------------------+-------------------------+
| 2 | 1001* | usage_schema | 2023-12-19 00:00:00 UTC | 2024-12-18 00:00:00 UTC |
| 5 | 1001* | my_db | 2022-11-02 23:00:00 UTC | 2022-11-03 07:20:00 UTC |
+------------+----------+--------------+-------------------------+-------------------------+
Query took 0.011 seconds.
删除复制组5在2001副本,剩余的副本自动变为主节点
【如果只有一个副本不允许删除,可以通过下面的销毁复制组达到删除目的】
销毁复制组
replica destory
replica destory
销毁整个复制组,如下所示:
my_db ❯ replica destory replica_id 5;
Query took 0.027 seconds.
my_db ❯ show replicas;
+------------+----------+--------------+-------------------------+-------------------------+
| replica_id | location | database | start_time | end_time |
+------------+----------+--------------+-------------------------+-------------------------+
| 2 | 1001* | usage_schema | 2023-12-19 00:00:00 UTC | 2024-12-18 00:00:00 UTC |
+------------+----------+--------------+-------------------------+-------------------------+
销毁复制组5,如果是只有一个副本的复制可以通过销毁方式达到删除目的