luky116 commented on code in PR #745:
URL:
https://github.com/apache/incubator-seata-go/pull/745#discussion_r1894589501
##########
pkg/rm/tcc/fence/handler/tcc_fence_wrapper_handler.go:
##########
@@ -163,6 +165,40 @@ func (handler *tccFenceWrapperHandler)
InitLogCleanChannel() {
})
}
+func (handler *tccFenceWrapperHandler) InitLogCleanTask(tx *sql.Tx) {
+ handler.logTaskOnce.Do(func() {
+ // Create a ticker that will fire initially based on the time
remaining until the next midnight (00:00:00).
+ go func() {
+ ticker := time.NewTicker(getDurationUntilNextZero())
+ defer ticker.Stop()
+
+ for {
+ select {
+ case <-ticker.C:
+ now := time.Now()
+ // Get the start time of the day before
the current day (00:00:00) and assign it to timeBefore with the same location
as now.
+ timeBefore := time.Date(now.Year(),
now.Month(), now.Day()-1, 0, 0, 0, 0, now.Location())
+
+ for {
+ deletedRowCount, err :=
handler.tccFenceDao.DeleteTCCFenceDOByMdfDate(tx, timeBefore, limitDelete)
+ if err != nil {
+ fmt.Printf("Error
occurred during TCC fence clean task: %v\n", err)
Review Comment:
这种方式还有个问题,如果网络抖动一次,当前的删除工作就终止的
##########
pkg/rm/tcc/fence/handler/tcc_fence_wrapper_handler.go:
##########
@@ -163,6 +165,40 @@ func (handler *tccFenceWrapperHandler)
InitLogCleanChannel() {
})
}
+func (handler *tccFenceWrapperHandler) InitLogCleanTask(tx *sql.Tx) {
+ handler.logTaskOnce.Do(func() {
+ // Create a ticker that will fire initially based on the time
remaining until the next midnight (00:00:00).
+ go func() {
+ ticker := time.NewTicker(getDurationUntilNextZero())
+ defer ticker.Stop()
+
+ for {
+ select {
+ case <-ticker.C:
+ now := time.Now()
+ // Get the start time of the day before
the current day (00:00:00) and assign it to timeBefore with the same location
as now.
+ timeBefore := time.Date(now.Year(),
now.Month(), now.Day()-1, 0, 0, 0, 0, now.Location())
+
+ for {
+ deletedRowCount, err :=
handler.tccFenceDao.DeleteTCCFenceDOByMdfDate(tx, timeBefore, limitDelete)
+ if err != nil {
+ fmt.Printf("Error
occurred during TCC fence clean task: %v\n", err)
Review Comment:
如果采用评论区说的,使用channel,见听到一定条数删除一次,看看会有啥啥问题不
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]