南大通用GBase 8a通过rebalance to实现回退重分布表操作

GBase 8a数据库支持在线扩容,其中重分布步骤rebalance,将老数据重分布到新的分布策略(distirbution id),在某些情况下,也可以通过rebalance to 将新策略数据,回退到老的策略上。

参考

GBase 8a 扩容操作详细实例

GBase 8a 扩容操作意外处理方案

GBase 8a集群扩容注意事项

命令

rebalance {instance|database dbname|table tbname} [to distributionID]

说明

该重分布命令,默认是将老的分布策略(distributionid 较小的),重分布到新的(较大的),在某些情况下,也存在要回退的可能性,比如随机分布表默认是快速重分布,但现场因为磁盘空间问题做的扩容,参数忘记设置了,而此时只有部分表做了重分布操作。后续有2个解决方案:

1、继续重分布,将所有操作做完,然后再新建一个distribution, 设置好参数,重新做一次重分布。
2、清掉现有任务,将已经重分布完成的表(data_distirbution_id已经变成新的),回退到老的版本。然后设置参数,重新开始重分布。

如果已经完成的任务比例很小,而整个重分布过程要耗时很久,比如几天,几星期,那么方案1将需要双倍的时间,此时方案2就成了更好的选择。

样例

清理现有任务,避免后续的重分布。

gbase> delete from rebalancing_status;
Query OK, 70 rows affected (Elapsed: 00:00:00.26)

gbase> select * from rebalancing_status;
Empty set (Elapsed: 00:00:00.01)

查看现有已经完成的表

如下看到有3个表的data_distribution_id=3。

gbase> select * from gbase.table_distribution order by data_distribution_id;;
+------------------------------------+------------+-------------------------+-------------+-------------+------------------+--------------------+-------------+----------------------+---------+--------------+
| index_name                         | dbName     | tbName                  | isReplicate | hash_column | lmt_storage_size | table_storage_size | is_nocopies | data_distribution_id | vc_id   | mirror_vc_id |
+------------------------------------+------------+-------------------------+-------------+-------------+------------------+--------------------+-------------+----------------------+---------+--------------+
| testdb.t1                          | testdb     | t1                      | NO          | NULL        |             NULL |               NULL | NO          |                    1 | vc00001 | vc00002      |
| testmirror.t1                      | testmirror | t1                      | NO          | NULL        |             NULL |               NULL | NO          |                    1 | vc00001 | vc00002      |
| testdb.t2                          | testdb     | t2                      | NO          | NULL        |             NULL |               NULL | NO          |                    1 | vc00001 | vc00002      |
| testdb.t3                          | testdb     | t3                      | NO          | NULL        |             NULL |               NULL | NO          |                    1 | vc00001 | vc00002      |
| testdb.t_encrypt                   | testdb     | t_encrypt               | NO          | NULL        |             NULL |               NULL | NO          |                    1 | vc00001 | vc00002      |
....
| gclusterdb.rebalancing_status      | gclusterdb | rebalancing_status      | NO          | index_name  |             NULL |               NULL | NO          |                    3 | vc00001 | NULL         |
| gclusterdb.dual                    | gclusterdb | dual                    | YES         | NULL        |             NULL |               NULL | NO          |                    3 | vc00001 | NULL         |
| testdb.t4                          | testdb     | t4                      | NO          | NULL        |             NULL |               NULL | NO          |                    3 | vc00001 |              |
+------------------------------------+------------+-------------------------+-------------+-------------+------------------+--------------------+-------------+----------------------+---------+--------------+
82 rows in set (Elapsed: 00:00:00.00)

回退到老的分布策略

通过rebalance table to 方法,将表回退到1,注意其中的gclusterdb.rebalancing_status不能手工回退。

gbase> rebalance table testdb.t4 to 1;
Query OK, 0 rows affected (Elapsed: 00:00:00.05)

gbase> rebalance table gclusterdb.dual to 1;
Query OK, 0 rows affected (Elapsed: 00:00:00.06)

gbase> rebalance table gclusterdb.rebalancing_status to 1;
ERROR 1707 (HY000): gcluster command error: system table can't be rebalanced.


gbase> select * from gbase.table_distribution order by data_distribution_id;;
+------------------------------------+------------+-------------------------+-------------+-------------+------------------+--------------------+-------------+----------------------+---------+--------------+
| index_name                         | dbName     | tbName                  | isReplicate | hash_column | lmt_storage_size | table_storage_size | is_nocopies | data_distribution_id | vc_id   | mirror_vc_id |
+------------------------------------+------------+-------------------------+-------------+-------------+------------------+--------------------+-------------+----------------------+---------+--------------+
| gclusterdb.dual                    | gclusterdb | dual                    | YES         | NULL        |             NULL |               NULL | NO          |                    1 | vc00001 | NULL         |
| gclusterdb.rebalancing_status      | gclusterdb | rebalancing_status      | NO          | index_name  |             NULL |               NULL | NO          |                    1 | vc00001 | NULL         |
| testdb.t1                          | testdb     | t1                      | NO          | NULL        |             NULL |               NULL | NO          |                    1 | vc00001 | vc00002      |
| testmirror.t1                      | testmirror | t1                      | NO          | NULL        |             NULL |               NULL | NO          |                    1 | vc00001 | vc00002      |
| testdb.t2                          | testdb     | t2                      | NO          | NULL        |             NULL |               NULL | NO          |                    1 | vc00001 | vc00002      |
| testdb.t3                          | testdb     | t3                      | NO          | NULL        |             NULL |               NULL | NO          |                    1 | vc00001 | vc00002      |
| testdb.t4                          | testdb     | t4                      | NO          | NULL        |             NULL |               NULL | NO          |                    1 | vc00001 |              |
| testdb.t_encrypt                   | testdb     | t_encrypt               | NO          | NULL        |             NULL |               NULL | NO          |                    1 | vc00001 | vc00002      |
。。。。。
+------------------------------------+------------+-------------------------+-------------+-------------+------------------+--------------------+-------------+----------------------+---------+--------------+
82 rows in set (Elapsed: 00:00:00.00)

再次清理重分布任务表

gbase> select * from gclusterdb.rebalancing_status;
+-----------------+------------+------------+----------+----------------------------+----------------------------+-----------+------------+----------+------------+-----------------+
| index_name      | db_name    | table_name | tmptable | start_time                 | end_time                   | status    | percentage | priority | host       | distribution_id |
+-----------------+------------+------------+----------+----------------------------+----------------------------+-----------+------------+----------+------------+-----------------+
| testdb.t4       | testdb     | t4         |          | 2021-03-22 15:52:12.401000 | 2021-03-22 15:52:12.809000 | COMPLETED |        100 |        5 | 10.0.2.101 |               1 |
| gclusterdb.dual | gclusterdb | dual       |          | 2021-03-22 15:52:42.051000 | 2021-03-22 15:52:42.515000 | COMPLETED |        100 |        5 | 10.0.2.101 |               1 |
+-----------------+------------+------------+----------+----------------------------+----------------------------+-----------+------------+----------+------------+-----------------+
2 rows in set (Elapsed: 00:00:00.02)

gbase> delete from rebalancing_status;
Query OK, 2 rows affected (Elapsed: 00:00:00.26)

gbase> select * from rebalancing_status;
Empty set (Elapsed: 00:00:00.01)

重新开始重分布

参考重分布方案,不再重复。