CDC和DSG复制的原理是把页改动的Log转换成逻辑日志去目标端重做。比如源端一条sql update完全一样的两行数据,那CDC会把两行的改动转换成两个update sql,第一条sql执行完就把两行数据都更新了,那么第二条再去执行就会报错找不到该行。所以复制软件要求必须要有主键,不存在完全相同的两行数据。
测试场景1:预定没有失败,原因是两行不是完全相同的行
CDC源端:
$ db2 "insert into test values(88888888,'8888-0001','8888-0001')"
DB20000I The SQL command completed successfully.
$ db2 "insert into t
$ db2 "insert into test values(88888888,'8888-0002','8888-0002')"
DB20000I The SQL command completed successfully.
$ db2 "update test set id=66666666 where id=88888888"
DB20000I The SQL command completed successfully.
$
CDC目标端:
[db2inst1@t3-ucm-ucm-rdb ~]$ db2 "select * from test"
ID NAME1 NAME2
----------- ---------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------
66666666 8888-0001 8888-0001
66666666 8888-0002 8888-0002
2 record(s) selected.
测试场景2:CDC报如下错误,符合预期。CDC目标端在一个事务里执行两条sql,第一条sql更新了两行,第二条sql再执行的时候发现找不到ID: [88888888] NAME1: [8888-0001] NAME2: [8888-0001]这一行了。然后事务回滚,两条都失败了
无法更新表 DB2INST1.TEST 中的行。ID: [88888888] NAME1: [8888-0001] NAME2: [8888-0001] 。
IBM InfoSphere Data Replication 已应用一批 2 行,JDBC 驱动程序发回报告已对这批中的条目 1 更新 0 行。这可能意味着,无法在数据库中找到这批中的该行。请查看文档,关闭批处理或减小批处理大小,然后重试操作以缩小无法应用的行数。
CDC源端:
$ db2 "delete from test"
DB20000I The SQL command completed successfully.
$ db2 "insert into test values(88888888,'8888-0001','8888-0001')"
DB20000I The SQL command completed successfully.
$ db2 "insert into test values(88888888,'8888-0001','8888-0001')"
DB20000I The SQL command completed successfully.
$ db2 "update test set id=66666666 where id=88888888"
DB20000I The SQL command completed successfully.
CDC目标端:
[db2inst1@t3-ucm-ucm-rdb ~]$ db2 "select * from test"
ID NAME1 NAME2
----------- ---------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------
88888888 8888-0001 8888-0001
88888888 8888-0001 8888-0001
2 record(s) selected.