-
Notifications
You must be signed in to change notification settings - Fork 294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
optimize : tccfence log table deleted should be optimized #745
base: master
Are you sure you want to change the base?
Conversation
佬们,能教教孩子吗 我注意到 java 那里实现方式是先找一千个需要删除的日志,记录 xid 再进行删除,如此循环直到找不出日志为止。 然后我注意到再 go 里面 fence 里有个channel : traversalCleanChannel是用来放需要删除日志的 xid和 brandId 的。我有考虑过直接通过定时任务查询需要删除的日志,把他们的 xid 和 brandId 放进这个 channel 中。但是我感觉这样通过 channel 一次删除一条日志的效率太低了。 所以我就重新写了一个定时任务,在每天零点的时候执行,也没有查找日志再删除,而是直接进行日志删除,并采用循环直到没有日志需要删除。 最后我的问题是:
|
for { | ||
deletedRowCount, err := handler.tccFenceDao.DeleteTCCFenceDOByMdfDate(tx, timeBefore, limitDelete) | ||
if err != nil { | ||
fmt.Printf("Error occurred during TCC fence clean task: %v\n", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
日志统一使用 log 来输出
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这种方式还有个问题,如果网络抖动一次,当前的删除工作就终止的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果采用评论区说的,使用channel,见听到一定条数删除一次,看看会有啥啥问题不
# Conflicts: # go.mod # go.sum
|
// updateStatusByBranchIdAndXid The enum UpdateStatusByBranchIdAndXid | ||
updateStatusByBranchIdAndXid = "update " + localTccLogPlaced + " set status = ?, gmt_modified = ? where xid = ? and branch_id = ? and status = ? " | ||
|
||
// deleteByBranchIdAndXid The enum DeleteByBranchIdAndXid | ||
deleteByBranchIdAndXid = "delete from " + localTccLogPlaced + " where xid = ? and branch_id = ? " | ||
|
||
// deleteByBranchIdsAndXids The enum DeleteByBranchIdsAndXids | ||
deleteByBranchIdsAndXids = "delete from " + localTccLogPlaced + " where (xid,branch_id) in (" + pramPlaceHolder + ")" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
做清除动作的时候根据xid去做就好了吧?会有同一个xid里的一部分分支要清除,另一部分还留着的诉求吗?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
因为我看之前有删除的 sql 语句就是根据 xid 和 branchid 进行删除的。并且之前PrepareFence 方法中,insertTCCFenceLog 失败后也会把他的 xid 和 branchid放入channel 中用于执行删除语句,所以我是根据 xid 和 branchid 来删除的。
What this PR does:
Delete the logs generated by fence and use limit to restrict the number of deletions each time.
Which issue(s) this PR fixes:
Fixes #699
Special notes for your reviewer: null
Does this PR introduce a user-facing change?: no