GBase 8a的镜像集群,一般建议采用相同的拓扑结构(相同的机器数量,相同的分布策略)。如果用于实时备份场景,也可以考虑用大容量磁盘,少量节点做备份用镜像。
目录导航
测试环境
3节点集群。其中前两个节点是VC1,设置为p 1 每个节点1个主分片);第三个节点是VC2,设置为 p2 d 0(每个节点2个主分片)。
两个VC做镜像的前提
- 主分片数量相同,都是2个;不考虑副本
- hashmap相同(vc2采用 initnodedatamap from vc1做的初始化)
gcadmin
[gbase@gbase_rh7_001 gcinstall_9.5.2.45.5]$ gcadmin
CLUSTER STATE: ACTIVE
=============================================================
| GBASE COORDINATOR CLUSTER INFORMATION |
=============================================================
| NodeName | IpAddress | gcware | gcluster | DataState |
-------------------------------------------------------------
| coordinator1 | 10.0.2.101 | OPEN | OPEN | 0 |
-------------------------------------------------------------
=============================================
| GBASE VIRTUAL CLUSTER INFORMATION |
=============================================
| VcName | DistributionId | comment |
---------------------------------------------
| vc1 | 1 | vc_101 |
---------------------------------------------
| vc2 | 2 | vc_102 |
---------------------------------------------
2 virtual cluster: vc1, vc2
1 coordinator node
0 free data node
vc1的信息
2台机器,每个机器一个主分片。
[gbase@gbase_rh7_001 gcinstall_9.5.2.45.5]$ gcadmin showcluster vc vc1
CLUSTER STATE: ACTIVE
VIRTUAL CLUSTER MODE: NORMAL
=============================================
| GBASE VIRTUAL CLUSTER INFORMATION |
=============================================
| VcName | DistributionId | comment |
---------------------------------------------
| vc1 | 1 | vc_101 |
---------------------------------------------
=========================================================================================================
| VIRTUAL CLUSTER DATA NODE INFORMATION |
=========================================================================================================
| NodeName | IpAddress | DistributionId | gnode | syncserver | DataState |
---------------------------------------------------------------------------------------------------------
| node1 | 10.0.2.101 | 1 | OPEN | OPEN | 0 |
---------------------------------------------------------------------------------------------------------
| node2 | 10.0.2.102 | 1 | OPEN | OPEN | 0 |
---------------------------------------------------------------------------------------------------------
2 data node
[gbase@gbase_rh7_001 gcinstall_9.5.2.45.5]$ gcadmin showdistribution vc vc1
Distribution ID: 1 | State: new | Total segment num: 2
Primary Segment Node IP Segment ID Duplicate Segment node IP
========================================================================================================================
| 10.0.2.101 | 1 | 10.0.2.102 |
------------------------------------------------------------------------------------------------------------------------
| 10.0.2.102 | 2 | 10.0.2.101 |
========================================================================================================================
[gbase@gbase_rh7_001 gcinstall_9.5.2.45.5]$
VC2的信息
1台机器,有2个主分片。
[gbase@gbase_rh7_001 gcinstall_9.5.2.45.5]$ gcadmin showcluster vc vc2
CLUSTER STATE: ACTIVE
VIRTUAL CLUSTER MODE: NORMAL
=============================================
| GBASE VIRTUAL CLUSTER INFORMATION |
=============================================
| VcName | DistributionId | comment |
---------------------------------------------
| vc2 | 2 | vc_102 |
---------------------------------------------
=========================================================================================================
| VIRTUAL CLUSTER DATA NODE INFORMATION |
=========================================================================================================
| NodeName | IpAddress | DistributionId | gnode | syncserver | DataState |
---------------------------------------------------------------------------------------------------------
| node1 | 10.0.2.115 | 2 | OPEN | OPEN | 0 |
---------------------------------------------------------------------------------------------------------
1 data node
[gbase@gbase_rh7_001 gcinstall_9.5.2.45.5]$ gcadmin showdistribution vc vc2
Distribution ID: 2 | State: new | Total segment num: 2
Primary Segment Node IP Segment ID Duplicate Segment node IP
========================================================================================================================
| 10.0.2.115 | 1 | |
------------------------------------------------------------------------------------------------------------------------
| 10.0.2.115 | 2 | |
========================================================================================================================
[gbase@gbase_rh7_001 gcinstall_9.5.2.45.5]$
创建镜像库
初始化并设置vc1到vc2的镜像。
gbase> use vc vc1;
Query OK, 0 rows affected (Elapsed: 00:00:00.00)
gbase> initnodedatamap;
Query OK, 1 row affected (Elapsed: 00:00:00.51)
gbase> use vc vc2;
Query OK, 0 rows affected (Elapsed: 00:00:00.00)
gbase> initnodedatamap from vc1;
Query OK, 1 row affected, 1 warning (Elapsed: 00:00:00.36)
gbase> show warnings;
+---------+------+----------------------------------------------------------+
| Level | Code | Message |
+---------+------+----------------------------------------------------------+
| Warning | 1042 | It is risky that some suffix is not in the backup state. |
+---------+------+----------------------------------------------------------+
1 row in set (Elapsed: 00:00:00.00)
gbase> create database vc1.testdb;
Query OK, 1 row affected (Elapsed: 00:00:00.01)
gbase> create database vc2.testdb;
Query OK, 1 row affected (Elapsed: 00:00:00.00)
gbase> alter database vc1.testdb set default mirror=vc2;
Query OK, 1 row affected (Elapsed: 00:00:00.00)
gbase> show mirror databases;
+--------------------+-----+-----------+
| Database | VC | MIRROR_VC |
+--------------------+-----+-----------+
| information_schema | | |
| performance_schema | | |
| gbase | | |
| gctmpdb | | |
| gclusterdb | vc2 | |
| testdb | vc2 | vc1 |
+--------------------+-----+-----------+
6 rows in set (Elapsed: 00:00:00.00)
测试镜像表
gbase> use vc vc1;
Query OK, 0 rows affected (Elapsed: 00:00:00.00)
gbase> use testdb;
Query OK, 0 rows affected (Elapsed: 00:00:00.00)
gbase> create table t1(id int,name varchar(100));
Query OK, 0 rows affected (Elapsed: 00:00:00.21)
gbase> insert into t1 values(1,'From vc1');
Query OK, 1 row affected (Elapsed: 00:00:00.13)
gbase> select * from vc1.testd.t1;
ERROR 1146 (42S02): Table 'vc1.testd.t1' doesn't exist
gbase> select * from vc1.testdb.t1;
+------+----------+
| id | name |
+------+----------+
| 1 | From vc1 |
+------+----------+
1 row in set (Elapsed: 00:00:00.01)
gbase> select * from vc2.testdb.t1;
+------+----------+
| id | name |
+------+----------+
| 1 | From vc1 |
+------+----------+
1 row in set (Elapsed: 00:00:00.01)
gbase> ^CAborted
总结
镜像集群,和主分片数量有关,双方必须有相同的主分片数;和hashmap有关,双方nodedatamap表里的data_distribution_id的数量必须相同,且内容必须相同。
经测试,当前版本对distribution的数量没有严格检查,如果只创建distribution,但没有initnodedatamap,此时不影响镜像。但如果做了initnodedatamap,则两面的nodedatamap将不一样,建镜像会报错。
可以用下面的SQL语句检查。看每个hashkey,nodeid组合的数量(group by hashkey,nodeid)做count(*), 如果每个hashkey和nodeid。
其中的id是你镜像vc当前在用的distribution编号,可以在gcadmin showdistribution vc VCNAME 看到。
select distinct(res.r), count(res.r) from (select count(*) r from gbase.nodedatamap t where t.data_distribution_id in (1,2) group by t.hashkey, t.nodeid) res group by res.r;
+---+--------------+
| r | count(res.r) |
+---+--------------+
| 2 | 65536 |
+---+--------------+
1 row in set (Elapsed: 00:00:00.42)