Skip to content

Commit b3fc2b7

Browse files
taylorchusiddontang
authored andcommitted
move gtid update after all event handlers are executed (go-mysql-org#379)
It is a common use case that we have a separate goroutine to update gtid set. We have to ensure that gtid saver sees updated gtid only after all the tasks are done in event handlers.
1 parent 8b8699f commit b3fc2b7

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

canal/sync.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"time"
77

88
"github.com/pingcap/errors"
9-
"github.com/satori/go.uuid"
9+
uuid "github.com/satori/go.uuid"
1010
"github.com/siddontang/go-log/log"
1111
"github.com/siddontang/go-mysql/mysql"
1212
"github.com/siddontang/go-mysql/replication"
@@ -92,14 +92,14 @@ func (c *Canal) runSyncBinlog() error {
9292
}
9393
continue
9494
case *replication.XIDEvent:
95-
if e.GSet != nil {
96-
c.master.UpdateGTIDSet(e.GSet)
97-
}
9895
savePos = true
9996
// try to save the position later
10097
if err := c.eventHandler.OnXID(pos); err != nil {
10198
return errors.Trace(err)
10299
}
100+
if e.GSet != nil {
101+
c.master.UpdateGTIDSet(e.GSet)
102+
}
103103
case *replication.MariadbGTIDEvent:
104104
// try to save the GTID later
105105
gtid, err := mysql.ParseMariadbGTIDSet(e.GTID.String())
@@ -119,9 +119,6 @@ func (c *Canal) runSyncBinlog() error {
119119
return errors.Trace(err)
120120
}
121121
case *replication.QueryEvent:
122-
if e.GSet != nil {
123-
c.master.UpdateGTIDSet(e.GSet)
124-
}
125122
var (
126123
mb [][]byte
127124
db []byte
@@ -159,6 +156,9 @@ func (c *Canal) runSyncBinlog() error {
159156
if err = c.eventHandler.OnDDL(pos, e); err != nil {
160157
return errors.Trace(err)
161158
}
159+
if e.GSet != nil {
160+
c.master.UpdateGTIDSet(e.GSet)
161+
}
162162
default:
163163
continue
164164
}

0 commit comments

Comments
 (0)