南大通用GBase 8s 数据同步:确保复制数据一致性

6 阅读5分钟

原文链接:www.gbase.cn/community/p…
更多精彩内容尽在南大通用GBase技术社区,南大通用致力于成为用户最信赖的数据库产品供应商。

创建复制前的数据如何同步?本文我们来介绍一下可用的两种方法:

第一种方法使用cdr check repl --repair

第二种方法使用cdr sync repl

两种方法机理不同,通过测试数据cdrtime字段来看,cdr check repl --repair像是重做了不一致的数据,所以cdrtime更新为最新时间;

而cdr sync repl,是同步了之前日志,所以cdrtime没有变化,仍然是之前操作时记录的时间。

第一种方法验证:

--er01,er02,er03全部都执行
create table t5(id int, col decimal(6,2), primary key(id)) with CRCOLS;
--er01节点执行
insert into t5 values(1,1.23);
insert into t5 values(2,3.14);
cdr define replicate -C timestamp -A -R testdb_t5 "testdb@er01:gbasedbt.t5"  "select * from t5" "testdb@er02:gbasedbt.t5"  "select * from t5" "testdb@er03:gbasedbt.t5"  "select * from t5"
cdr start repl testdb_t5
insert into t5 values(3,'2.45');
> select cdrserver,cdrtime,* from t5;

 cdrserver     cdrtime          id      col
         1  1757146632           1     1.23
         1  1757146644           2     3.14
         1  1757148074           3     2.45
3 row(s) retrieved.
>
--er02节点
> select cdrserver,cdrtime,* from t5;

 cdrserver     cdrtime          id      col
         1  1757148074           3     2.45
1 row(s) retrieved.
>
--er03节点
> select cdrserver,cdrtime,* from t5;

 cdrserver     cdrtime          id      col
         1  1757148074           3     2.45
1 row(s) retrieved.
>
--检查数据一致性
--er01节点执行
-sh-4.2$ cdr check repl -m er01 -r testdb_t5 er02 er03
Sep 06 2025 16:42:06 ------   Table scan for testdb_t5 start  --------
Node                  Rows     Extra   Missing  Mismatch Processed
---------------- --------- --------- --------- --------- ---------
er01                     3         0         0         0         0
er02                     1         0         2         0         0
er03                     1         0         2         0         0
WARNING: replicate is not in sync
Sep 06 2025 16:42:07 ------   Table scan for testdb_t5 end   ---------
command failed -- WARNING: replicate is not in sync (178)
-sh-4.2$
--检查数据一致性,并进行修复,下面命令同cdr check repl -R -m er01 -r testdb_t5 er02 er03
-sh-4.2$ cdr check repl --repair -m er01 -r testdb_t5 er02 er03
Sep 06 2025 16:47:06 ------   Table scan for testdb_t5 start  --------
Node                  Rows     Extra   Missing  Mismatch Processed
---------------- --------- --------- --------- --------- ---------
er01                     3         0         0         0         2
er02                     1         0         2         0         0
er03                     1         0         2         0         0

The repair operation completed. Validating the repaired rows ...
Validation completed successfully.
Sep 06 2025 16:47:06 ------   Table scan for testdb_t5 end   ---------
-sh-4.2$
--检查三个节点数据
--er01 cdrtime时间更新了
> select cdrserver,cdrtime,* from t5;

 cdrserver     cdrtime          id      col
         1  1757148426           1     1.23
         1  1757148426           2     3.14
         1  1757148074           3     2.45
3 row(s) retrieved.
>
--er02  同步了之前的数据!
> select cdrserver,cdrtime,* from t5;

 cdrserver     cdrtime          id      col
         1  1757148074           3     2.45
         1  1757148426           1     1.23
         1  1757148426           2     3.14
3 row(s) retrieved.
>
--er03 同步了之前的数据
> select cdrserver,cdrtime,* from t5;

 cdrserver     cdrtime          id      col
         1  1757148074           3     2.45
         1  1757148426           1     1.23
         1  1757148426           2     3.14
3 row(s) retrieved.
>

第二种方法验证:


--er01节点执行停止复制
cdr stop repl testdb_t5
insert into t5 values(4,5.78);
insert into t5 values(5,6.89);
> select cdrserver,cdrtime,* from t5;

 cdrserver     cdrtime          id      col
         1  1757148426           1     1.23
         1  1757148426           2     3.14
         1  1757148074           3     2.45
         1  1757149215           4     5.78
         1  1757149243           5     6.89
5 row(s) retrieved.
> !cdr list server
SERVER                 ID STATE    STATUS     QUEUE  CONNECTION CHANGED
-----------------------------------------------------------------------
er01                    1 Active   Local           0
er02                    2 Active   Connected       0 Sep  4 17:02:18
er03                    3 Active   Connected       0 Sep  4 17:02:37
>
--再启动复制
cdr start repl testdb_t5
--查看数据
--er01
> select cdrserver,cdrtime,* from t5;

 cdrserver     cdrtime          id      col
         1  1757148426           1     1.23
         1  1757148426           2     3.14
         1  1757148074           3     2.45
         1  1757149215           4     5.78
         1  1757149243           5     6.89
5 row(s) retrieved.
>
--er02
> select cdrserver,cdrtime,* from t5;

 cdrserver     cdrtime          id      col
         1  1757148074           3     2.45
         1  1757148426           1     1.23
         1  1757148426           2     3.14
3 row(s) retrieved.
>
--er03
> select cdrserver,cdrtime,* from t5;

 cdrserver     cdrtime          id      col
         1  1757148074           3     2.45
         1  1757148426           1     1.23
         1  1757148426           2     3.14
3 row(s) retrieved.
>
--er01节点检查数据一致性
-sh-4.2$ cdr check repl -m er01 -r testdb_t5 er02 er03
Sep 06 2025 17:04:51 ------   Table scan for testdb_t5 start  --------
Node                  Rows     Extra   Missing  Mismatch Processed
---------------- --------- --------- --------- --------- ---------
er01                     5         0         0         0         0
er02                     3         0         2         0         0
er03                     3         0         2         0         0
WARNING: replicate is not in sync
Sep 06 2025 17:04:52 ------   Table scan for testdb_t5 end   ---------
command failed -- WARNING: replicate is not in sync (178)
-sh-4.2$
--执行同步
-sh-4.2$ cdr sync repl -m er01 -r testdb_t5 er02 er03
Sep 06 2025 17:08:45 ------   Table scan for testdb_t5 start  --------
Starting synchronization scan for replicate
         testdb_t5
Ending synchronization scan for replicate
         testdb_t5
Sep 06 2025 17:08:45 ------   Table scan for testdb_t5 end   ---------
-sh-4.2$
--再检查数据一致性,此时三节点数据一致
-sh-4.2$ cdr check repl -m er01 -r testdb_t5 er02 er03
Sep 06 2025 17:09:17 ------   Table scan for testdb_t5 start  --------
Node                  Rows     Extra   Missing  Mismatch Processed
---------------- --------- --------- --------- --------- ---------
er01                     5         0         0         0         0
er02                     5         0         0         0         0
er03                     5         0         0         0         0
Sep 06 2025 17:09:17 ------   Table scan for testdb_t5 end   ---------
-sh-4.2$
--er01 cdrtime时间不变,说明cdr sync repl与cdr check repl –repair机理不同
> select cdrserver,cdrtime,* from t5;

 cdrserver     cdrtime          id      col
         1  1757148426           1     1.23
         1  1757148426           2     3.14
         1  1757148074           3     2.45
         1  1757149215           4     5.78
         1  1757149243           5     6.89
5 row(s) retrieved.
>
--er02 同步成功
> select cdrserver,cdrtime,* from t5;

 cdrserver     cdrtime          id      col
         1  1757148074           3     2.45
         1  1757148426           1     1.23
         1  1757148426           2     3.14
         1  1757149215           4     5.78
         1  1757149243           5     6.89
5 row(s) retrieved.
>
--er03 同步成功
> select cdrserver,cdrtime,* from t5;

 cdrserver     cdrtime          id      col
         1  1757148074           3     2.45
         1  1757148426           1     1.23
         1  1757148426           2     3.14
         1  1757149215           4     5.78
         1  1757149243           5     6.89
5row(s) retrieved.
>

本文的介绍了 GBase 8s 中两种数据同步方法的使用方法和效果。 cdr check repl --repair  适用于需要修复数据不一致性的场景,而  cdr sync repl  适用于需要同步之前日志数据的场景。根据实际需求选择合适的方法,可以确保数据在多个节点间的一致性。希望这些内容能帮助你在实际操作中更好地管理数据同步。如果你在使用过程中遇到任何问题,欢迎随时在社区中提问,我们在这里为你提供支持!

原文链接:www.gbase.cn/community/p…
更多精彩内容尽在南大通用GBase技术社区,南大通用致力于成为用户最信赖的数据库产品供应商。