在定义好复制服务器以及复制以后,执行 cdr start replicate可以将源库中的初始数据同步到目标服务器。该方法优点是过程简单,缺点是同步速度较慢。适用于数据量小的复制环境。相关的参数是CDR_QUEUEMEM。
同步的操作为在目标服务器上增加源服务器上存在而目标服务器中不存在的行和修改源服务器与目标服务器均存在但不一致的行。针对目标服务器上存在而源服务器中不存在的行的同步策略:
选项
说明
delete
根据参照完整性约束从目标服务器中删除行和从属行
keep
保留目标服务器上的行
merge
在目标服务器上保留行并将其复制到源服务器
测试环境:
两个实例中同时创建一个数据库testdb,并创建表t1-t5,均建有主键约束,然后分别向表中插入原始数据,如下:
表
group1
group2
t1
select * from t1;
a b
1 1
2 2
4 4
5 5
select * from t1;
a b
1 1
2 1
3 3
5 5
t2
select * from t2;
a b
1 1
5 5
2 2
4 4
select * from t2;
a b
1 1
2 1
3 3
5 5
t3
select * from t3;
a b
1 1
2 2
4 4
5 5
select * from t3;
a b
1 1
2 1
3 3
5 5
t4
select * from t4;
a b
1 1
2 2
4 4
5 5
6 6
select * from t4;
a b
1 1
2 1
3 3
5 5
6 6
t5
select * from t5;
a b
1 1
2 2
4 4
5 5
select * from t5;
a b
1 1
2 1
3 3
5 5
定义复制:
cdr define replicate --conflict=ignore rep_testdb_t1 "testdb@group1:gbasedbt.t1" "select * from t1" "testdb@group2:gbasedbt.t1" "select * from t1"
cdr define replicate --conflict=ignore rep_testdb_t2 "testdb@group1:gbasedbt.t2" "select * from t2" "testdb@group2:gbasedbt.t2" "select * from t2"
cdr define replicate --conflict=ignore rep_testdb_t3 "testdb@group1:gbasedbt.t3" "select * from t3" "testdb@group2:gbasedbt.t3" "select * from t3"
cdr define replicate --conflict=ignore rep_testdb_t4 "testdb@group1:gbasedbt.t4" "select * from t4" "testdb@group2:gbasedbt.t4" "select * from t4"
cdr define replicate --conflict=ignore rep_testdb_t5 "testdb@group1:gbasedbt.t5" "select * from t5" "testdb@group2:gbasedbt.t5" "select * from t5"
此时查看复制状态均为Inactive
[gbasedbt@gbase42 ~]$ cdr list repl rep_testdb_t1 rep_testdb_t2 rep_testdb_t3 rep_testdb_t4 rep_testdb_t5
DEFINED REPLICATES ATTRIBUTES
------------------------------
REPLICATE: rep_testdb_t1
STATE: Inactive ON:group2
CONFLICT: Ignore
FREQUENCY: immediate
QUEUE SIZE: 0
PARTICIPANT: testdb:gbasedbt.t1
OPTIONS: transaction,fullrow
REPLID: 131079 / 0x20007
REPLMODE: PRIMARY ON:group2
APPLY-AS: GBASEDBT ON:group2
REPLTYPE: Master
REPLICATE: rep_testdb_t2
STATE: Inactive ON:group2
CONFLICT: Ignore
FREQUENCY: immediate
QUEUE SIZE: 0
PARTICIPANT: testdb:gbasedbt.t2
OPTIONS: transaction,fullrow
REPLID: 131080 / 0x20008
REPLMODE: PRIMARY ON:group2
APPLY-AS: GBASEDBT ON:group2
REPLTYPE: Master
REPLICATE: rep_testdb_t3
STATE: Inactive ON:group2
CONFLICT: Ignore
FREQUENCY: immediate
QUEUE SIZE: 0
PARTICIPANT: testdb:gbasedbt.t3
OPTIONS: transaction,fullrow
REPLID: 131081 / 0x20009
REPLMODE: PRIMARY ON:group2
APPLY-AS: GBASEDBT ON:group2
REPLTYPE: Master
REPLICATE: rep_testdb_t4
STATE: Inactive ON:group2
CONFLICT: Ignore
FREQUENCY: immediate
QUEUE SIZE: 0
PARTICIPANT: testdb:gbasedbt.t4
OPTIONS: transaction,fullrow
REPLID: 131082 / 0x2000a
REPLMODE: PRIMARY ON:group2
APPLY-AS: GBASEDBT ON:group2
REPLTYPE: Master
REPLICATE: rep_testdb_t5
STATE: Inactive ON:group1
CONFLICT: Ignore
FREQUENCY: immediate
QUEUE SIZE: 0
PARTICIPANT: testdb:gbasedbt.t5
OPTIONS: transaction,fullrow
REPLID: 131083 / 0x2000b
REPLMODE: PRIMARY ON:group1
APPLY-AS: GBASEDBT ON:group1
REPLTYPE: Master
启动复制:
cdr start repl rep_testdb_t1
cdr start repl rep_testdb_t2 --syncdatasource=group1 --extratargetrows=delete
cdr start repl rep_testdb_t3 --syncdatasource=group1 --extratargetrows=keep
cdr start repl rep_testdb_t4 --syncdatasource=group1 --extratargetrows=merge
cdr start repl rep_testdb_t5 --syncdatasource=group1
原始数据对比:
表
启动复制前group1
启动复制前group2
启动复制后group1
启动复制后group2
t1
select * from t1;
a b
1 1
2 2
4 4
5 5
select * from t1;
a b
1 1
2 1
3 3
5 5
select * from t1;
a b
1 1
2 2
4 4
5 5
select * from t1;
a b
1 1
2 1
3 3
5 5
t2
select * from t2;
a b
1 1
5 5
2 2
4 4
select * from t2;
a b
1 1
2 1
3 3
5 5
select * from t2;
a b
1 1
5 5
2 2
4 4
select * from t2;
a b
1 1
2 2
5 5
4 4
t3
select * from t3;
a b
1 1
2 2
4 4
5 5
select * from t3;
a b
1 1
2 1
3 3
5 5
select * from t3;
a b
1 1
2 2
4 4
5 5
select * from t3;
a b
1 1
2 2
3 3
5 5
4 4
t4
select * from t4;
a b
1 1
2 2
4 4
5 5
6 6
select * from t4;
a b
1 1
2 1
3 3
5 5
6 6
select * from t4;
a b
1 1
2 2
4 4
5 5
6 6
3 3
select * from t4;
a b
1 1
2 2
3 3
5 5
6 6
4 4
t5
select * from t5;
a b
1 1
2 2
4 4
5 5
select * from t5;
a b
1 1
2 1
3 3
5 5
select * from t5;
a b
1 1
2 2
4 4
5 5
select * from t5;
a b
1 1
2 2
5 5
4 4
结论:
- 不使用-S 参数指定数据源,则不开启原始同步,对复制启动前的数据不做处理;
- 使用-S参数指定数据源,目标端多余行(以主键为依据)的删除,此时目标端与源端数据保持一致;
- 使用-S参数指定数据源,目标端多余行的保留,此时目标端数据为源端数据+目标端多余行;
- 使用-S参数指定数据源,目标端多余行的合并,此时目标端与源端数据一致,均为源端数据+目标端多余行;
- 使用-S参数指定数据源,缺省对目标端多余行的行为为删除
- GBase 8s 数据库的复制技术不仅提高了数据的可用性,还通过灵活的冲突处理策略,满足了多样化的业务需求。掌握这些技术,将有助于构建更加健壮和灵活的数据架构。
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。