Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(BranchBarrier): fix QueryPrepared method not return real insert exception #82

Merged

Conversation

wooln
Copy link
Contributor

@wooln wooln commented Dec 6, 2024

QueryPrepared调用的DbUtils.InsertBarrier里面有try了,返回插入行数+异常的元组,当插入遇到意料外的异常(如账号权现不能写),之前它还会往下走,导致reason.Equals出现null引用,虽然最终也是异常,但尽量返回真正的异常。

参考了go client的实现:

// QueryPrepared queries prepared data
func (bb *BranchBarrier) QueryPrepared(db *sql.DB) error {
	_, err := dtmimp.InsertBarrier(db, bb.TransType, bb.Gid, dtmimp.MsgDoBranch0, dtmimp.MsgDoOp, dtmimp.MsgDoBarrier1, dtmimp.OpRollback, bb.DBType, bb.BarrierTableName)
	var reason string
	if err == nil {
		sql := fmt.Sprintf("select reason from %s where gid=? and branch_id=? and op=? and barrier_id=?", dtmimp.BarrierTableName)
		sql = dtmimp.GetDBSpecial(bb.DBType).GetPlaceHoldSQL(sql)
		logger.Debugf("queryrow: %s", sql, bb.Gid, dtmimp.MsgDoBranch0, dtmimp.MsgDoOp, dtmimp.MsgDoBarrier1)
		err = db.QueryRow(sql, bb.Gid, dtmimp.MsgDoBranch0, dtmimp.MsgDoOp, dtmimp.MsgDoBarrier1).Scan(&reason)
	}
	if reason == dtmimp.OpRollback {
		return ErrFailure
	}
	return err
}

@catcherwong catcherwong merged commit a6eb0f2 into dtm-labs:main Dec 7, 2024
0 of 3 checks passed
@wooln wooln deleted the bugfix-QueryPrepared-catch-exception branch December 8, 2024 13:01
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants