@@ -15,6 +15,7 @@ import (
15
15
"github.com/satori/go.uuid"
16
16
gomysql "github.com/siddontang/go-mysql/mysql"
17
17
"os"
18
+ "sync"
18
19
"sync/atomic"
19
20
"time"
20
21
)
@@ -43,6 +44,7 @@ type ApplierIncr struct {
43
44
TotalDeltaCopied int64
44
45
45
46
gtidSet * gomysql.MysqlGTIDSet
47
+ gtidSetLock * sync.RWMutex
46
48
gtidItemMap base.GtidItemMap
47
49
GtidUpdateHook func (* common.BinlogCoordinateTx )
48
50
@@ -53,7 +55,8 @@ type ApplierIncr struct {
53
55
54
56
func NewApplierIncr (subject string , mysqlContext * common.MySQLDriverConfig ,
55
57
logger hclog.Logger , gtidSet * gomysql.MysqlGTIDSet , memory2 * int64 ,
56
- db * gosql.DB , dbs []* sql.Conn , shutdownCh chan struct {}) (* ApplierIncr , error ) {
58
+ db * gosql.DB , dbs []* sql.Conn , shutdownCh chan struct {},
59
+ gtidSetLock * sync.RWMutex ) (* ApplierIncr , error ) {
57
60
58
61
a := & ApplierIncr {
59
62
logger : logger ,
@@ -67,6 +70,7 @@ func NewApplierIncr(subject string, mysqlContext *common.MySQLDriverConfig,
67
70
memory2 : memory2 ,
68
71
printTps : os .Getenv (g .ENV_PRINT_TPS ) != "" ,
69
72
gtidSet : gtidSet ,
73
+ gtidSetLock : gtidSetLock ,
70
74
tableItems : make (mapSchemaTableItems ),
71
75
}
72
76
@@ -206,11 +210,15 @@ func (a *ApplierIncr) heterogeneousReplay() {
206
210
txSid := binlogEntry .Coordinates .GetSid ()
207
211
208
212
gtidSetItem := a .gtidItemMap .GetItem (binlogEntry .Coordinates .SID )
209
- intervals := base .GetIntervals (a .gtidSet , txSid )
210
- if base .IntervalSlicesContainOne (intervals , binlogEntry .Coordinates .GNO ) {
211
- // entry executed
212
- a .logger .Debug ("skip an executed tx" , "sid" , txSid , "gno" , binlogEntry .Coordinates .GNO )
213
- continue
213
+ {
214
+ a .gtidSetLock .RLock ()
215
+ intervals := base .GetIntervals (a .gtidSet , txSid )
216
+ if base .IntervalSlicesContainOne (intervals , binlogEntry .Coordinates .GNO ) {
217
+ // entry executed
218
+ a .logger .Info ("skip an executed tx" , "sid" , txSid , "gno" , binlogEntry .Coordinates .GNO )
219
+ continue
220
+ }
221
+ a .gtidSetLock .RUnlock ()
214
222
}
215
223
// endregion
216
224
// this must be after duplication check
@@ -224,7 +232,7 @@ func (a *ApplierIncr) heterogeneousReplay() {
224
232
225
233
a .logger .Debug ("gtidSetItem" , "NRow" , gtidSetItem .NRow )
226
234
if gtidSetItem .NRow >= cleanupGtidExecutedLimit {
227
- err = a .cleanGtidExecuted (binlogEntry .Coordinates .SID , base . StringInterval ( intervals ) )
235
+ err = a .cleanGtidExecuted (binlogEntry .Coordinates .SID , txSid )
228
236
if err != nil {
229
237
a .OnError (TaskStateDead , err )
230
238
return
@@ -256,32 +264,12 @@ func (a *ApplierIncr) heterogeneousReplay() {
256
264
a .logger .Warn ("DTLE_BUG: len(a.mtsManager.m) should be 0" )
257
265
}
258
266
}
259
- if binlogEntry .Coordinates .SeqenceNumber > a .mtsManager .lastEnqueue + 1 {
260
- if a .mtsManager .lastEnqueue == 0 {
261
- a .logger .Debug ("first TX" , "seq_num" , binlogEntry .Coordinates .SeqenceNumber )
262
- if binlogEntry .Coordinates .SeqenceNumber > 0 {
263
- a .mtsManager .lastEnqueue = binlogEntry .Coordinates .SeqenceNumber - 1
264
- a .mtsManager .lastCommitted = a .mtsManager .lastEnqueue
265
- }
266
- } else {
267
- err := fmt .Errorf ("found non-continuous tx seq_num. last %v this %v" ,
268
- a .mtsManager .lastEnqueue , binlogEntry .Coordinates .SeqenceNumber )
269
- a .logger .Error (err .Error ())
270
- a .OnError (TaskStateDead , err )
271
- return
272
- }
267
+ // If there are TXs skipped by udup source-side
268
+ for a .mtsManager .lastEnqueue + 1 < binlogEntry .Coordinates .SeqenceNumber {
269
+ a .mtsManager .lastEnqueue += 1
270
+ a .mtsManager .chExecuted <- a .mtsManager .lastEnqueue
273
271
}
274
- hasDDL := func () bool {
275
- for i := range binlogEntry .Events {
276
- dmlEvent := & binlogEntry .Events [i ]
277
- switch dmlEvent .DML {
278
- case common .NotDML :
279
- return true
280
- default :
281
- }
282
- }
283
- return false
284
- }()
272
+ hasDDL := binlogEntry .HasDDL ()
285
273
// DDL must be executed separatedly
286
274
if hasDDL || prevDDL {
287
275
a .logger .Debug ("MTS found DDL. WaitForAllCommitted" ,
@@ -290,11 +278,7 @@ func (a *ApplierIncr) heterogeneousReplay() {
290
278
return // shutdown
291
279
}
292
280
}
293
- if hasDDL {
294
- prevDDL = true
295
- } else {
296
- prevDDL = false
297
- }
281
+ prevDDL = hasDDL
298
282
299
283
if ! a .mtsManager .WaitForExecution (binlogEntry ) {
300
284
return // shutdown
0 commit comments