ITPub博客

首页 > Linux操作系统 > Linux操作系统 > replicat的handcollisions和reperror

replicat的handcollisions和reperror

原创 Linux操作系统 作者:myownstars 时间:2013-05-21 13:35:01 0 删除 编辑

Replicat处理DML时可能会出现数据冲突,根据场景不同,可分别使用handcollision和reperror处理

 

HANDLECOLLISIONS

是我们使用goldengate过程中常有的一个REPLICAT参数,该参数依赖于主键或唯一索引处理冲突数据,常用于初始化阶段。

对于无主键或唯一索引的表无法处理冲突,且可能导致重复记录。

注意打开此参数则所有数据错误不管reperror如何配置均不再写discard文件,即所有数据冲突信息被默认规则处理,没有任何日志,因此日常复制不建议使用该参数;

可予以考虑的特殊场景为只需新增数据,无需复制历史数据。

 

使用HANDLECOLLISIONS的几个场景:

1.    target丢失delete记录(missing delete),忽略该问题并不记录到discardfile

2.    target丢失update记录(missing update)

     更新的键值是主键=》 update转换成INSERT ,默认情况下插入记录不完整

     更新的键值是非主键=》 忽略该问题并不记录到discardfile

3.    重复插入已存在的主键值到target表中,这将被replicat转换为UPDATE现有主键值的行的其他非主键列

另:该参数仅处理数据本身的Insert/Delete冲突,如果出现两端映射或其它结构性问题Replicat进程依然会abend,不能被忽略

 

此外对于主键的更新操作,若在target使用HANDLECOLLISIONS且该update丢失,在会转换为INSERT该主键的操作,注意默认情况下插入的记录不完整,FETCHOPTIONS FETCHPKUPDATECOLS将捕获完整的redo image镜像到trail中,这保证把primary key的更新通过HANDLECOLLISIONS转换为对target的一个完整记录的插入。

 

我们可以通过send 命令动态取消HANDLECOLLISIONS

GGSCI (XIANGBLI-CN) 29> send rep2, NOHANDLECOLLISIONS

Sending NOHANDLECOLLISIONS request to REPLICAT REP2 ...

REP2 NOHANDLECOLLISIONS set for 1 tables and 0 wildcard entries

http://www.askmaclean.com/archives/%e4%ba%86%e8%a7%a3goldengate-replicat%e7%9a%84handlecollisions%e5%8f%82%e6%95%b0.html

 

REPERROR

包含如下action,

 ABEND: roll back the transaction and stop processing.

 DISCARD: log the error to the discard file and continue processing.

 EXCEPTION: send the error for exceptions processing (see “Handling errors as exceptions”.

 IGNORE: ignore the error and continue processing.

 RETRYOP [MAXRETRIES ]: retry the operation, optionally up to a specific number of times.

 TRANSABORT [, MAXRETRIES ] [, DELAY[C]SECS ]: abort the transaction and reposition to the beginning, optionally up to a specific number of times at specific intervals.

 RESET: remove all previous REPERROR rules and restore the default of ABEND.

 TRANSDISCARD: discard the entire replicated source transaction if any operation within that transaction, including the commit, causes a Replicat error that is listed in the

             error specification. This option is useful when integrity constraint checking is disabled on the target.

 TRANSEXCEPTION: perform. exceptions mapping for every record in the replicated source transaction, according to its exceptions-mapping statement, if any operation within

             that transaction (including the commit) causes a Replicat error that is listed in the error specification.

其中后两个为事务相关

事务错误处理又受如下参数影响

 

Batchsql和grouptransops

将不同事务sql打包进行批量处理,出错时首先尝试使用不同处理模式

如错误依旧存在则如下处理

1 回滚batch sql,逐个transaction进行处理

2 对失败的事务进行transdiscard或transexception处理

3 处理完毕后恢复batchsql/grouptransops模式

 

Maxtranops

将大事务分割成若干小事务处理,此举虽提升性能但破坏了事务完整性;

如果事务分割成N个且第一个成功提交而后续事务失败,则无法回滚第一个分事务;

 

Statsreplicat命令会显示由transdiscard/transexception处理的行数

 

Reperror命令语法如下

REPERROR { (

{DEFAULT | DEFAULT2 | | },

{ABEND | DISCARD | EXCEPTION | IGNORE |

RETRYOP [MAXRETRIES ] |

TRANSABORT [, MAXRETRIES] [, DELAYSECS | DELAYCSECS ] |

TRANSDISCARD |

TRANSEXCEPTION

}) |

RESET }

可使用两个default参数,作用如下

default

Sets a global response to all errors except those for which explicit REPERROR statements are specified.

default2

Provides a backup default action when the response for DEFAULT is set to EXCEPTION. Use DEFAULT2 when an exceptions MAP

statement is not specified for a MAP statement for which errors are anticipated.

 

对于exception/transexception,可将错误值捕获到异常表中

Map exceptiononly/mapexception

其中exceptiononly只适用于特定的表,即不能使用wildcards

 

异常表

须确保trail记录包含所有映射至异常表的列,可在extract参数文件配置如下参数:

Nocompressdeletes:delete语句包含该行所有列

Getupdatebefores:可捕获行的前镜像并写入trail

 

--使用两个map,第一个用于常规操作,第二个则处理异常

REPERROR (DEFAULT, EXCEPTION)

MAP ggs.equip_account, TARGET ggs.equip_account2,

COLMAP (USEDEFAULTS);

MAP ggs.equip_account, TARGET ggs.equip_account_exception,

EXCEPTIONSONLY,

INSERTALLRECORDS

COLMAP (USEDEFAULTS,

DML_DATE = @DATENOW(),

OPTYPE = @GETENV("LASTERR", "OPTYPE"),

DBERRNUM = @GETENV("LASTERR", "DBERRNUM"),

DBERRMSG = @GETENV("LASTERR", "DBERRMSG"));

 

MAP src.trx*, TARGET trg.*,

MAPEXCEPTION (TARGET fin.trxexceptions,

COLMAP (USEDEFAULTS,

ACCT_NO = ACCT_NO,

OPTYPE = @GETENV (“LASTERR”, “OPTYPE”),

DBERR = @GETENV (“LASTERR”, “DBERRNUM”),

DBERRMSG = @GETENV (“LASTERR”, “DBERRMSG”)

)

);

 

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/15480802/viewspace-761610/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2010-03-18

  • 博文量
    375
  • 访问量
    3320736