-
Notifications
You must be signed in to change notification settings - Fork 307
DM: Extend MySQL and MariaDB support for newer versions #12628
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
base: master
Are you sure you want to change the base?
Changes from all commits
92c0406
a6afe34
00886e2
e08e6ca
62df4f2
066ac74
00d6121
3b6b577
bbdf2ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -19,6 +19,7 @@ import ( | |||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| gmysql "github.com/go-mysql-org/go-mysql/mysql" | ||||||||||||||||||||||||||||||||||||||
| "github.com/go-mysql-org/go-mysql/replication" | ||||||||||||||||||||||||||||||||||||||
| "github.com/google/uuid" | ||||||||||||||||||||||||||||||||||||||
| "github.com/pingcap/tiflow/dm/pkg/gtid" | ||||||||||||||||||||||||||||||||||||||
| "github.com/pingcap/tiflow/dm/pkg/terror" | ||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -118,12 +119,19 @@ func GenCommonGTIDEvent(flavor string, serverID uint32, latestPos uint32, gSet g | |||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| switch flavor { | ||||||||||||||||||||||||||||||||||||||
| case gmysql.MySQLFlavor: | ||||||||||||||||||||||||||||||||||||||
| uuidSet := singleGTID.(*gmysql.UUIDSet) | ||||||||||||||||||||||||||||||||||||||
| interval := uuidSet.Intervals[0] | ||||||||||||||||||||||||||||||||||||||
| mSet := singleGTID.(*gmysql.MysqlGTIDSet) | ||||||||||||||||||||||||||||||||||||||
| var sid uuid.UUID | ||||||||||||||||||||||||||||||||||||||
| var interval gmysql.Interval | ||||||||||||||||||||||||||||||||||||||
| for u, tags := range *mSet { | ||||||||||||||||||||||||||||||||||||||
| sid = u | ||||||||||||||||||||||||||||||||||||||
| for _, intervals := range tags { | ||||||||||||||||||||||||||||||||||||||
| interval = intervals[0] | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| if anonymous { | ||||||||||||||||||||||||||||||||||||||
| gtidEv, err = GenAnonymousGTIDEvent(header, latestPos, defaultGTIDFlags, defaultLastCommitted, defaultSequenceNumber) | ||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||
| gtidEv, err = GenGTIDEvent(header, latestPos, defaultGTIDFlags, uuidSet.SID.String(), interval.Start, defaultLastCommitted, defaultSequenceNumber) | ||||||||||||||||||||||||||||||||||||||
| gtidEv, err = GenGTIDEvent(header, latestPos, defaultGTIDFlags, sid.String(), interval.Start, defaultLastCommitted, defaultSequenceNumber) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| case gmysql.MariaDBFlavor: | ||||||||||||||||||||||||||||||||||||||
| mariaGTID := singleGTID.(*gmysql.MariadbGTID) | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -153,20 +161,21 @@ func GTIDIncrease(flavor string, gSet gmysql.GTIDSet) (gmysql.GTIDSet, error) { | |||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| switch flavor { | ||||||||||||||||||||||||||||||||||||||
| case gmysql.MySQLFlavor: | ||||||||||||||||||||||||||||||||||||||
| uuidSet := singleGTID.(*gmysql.UUIDSet) | ||||||||||||||||||||||||||||||||||||||
| uuidSet.Intervals[0].Start++ | ||||||||||||||||||||||||||||||||||||||
| uuidSet.Intervals[0].Stop++ | ||||||||||||||||||||||||||||||||||||||
| gtidSet := new(gmysql.MysqlGTIDSet) | ||||||||||||||||||||||||||||||||||||||
| gtidSet.Sets = map[string]*gmysql.UUIDSet{uuidSet.SID.String(): uuidSet} | ||||||||||||||||||||||||||||||||||||||
| clone = gtidSet | ||||||||||||||||||||||||||||||||||||||
| mSet := clone.(*gmysql.MysqlGTIDSet) | ||||||||||||||||||||||||||||||||||||||
| for u, tags := range *mSet { | ||||||||||||||||||||||||||||||||||||||
| for tag, intervals := range tags { | ||||||||||||||||||||||||||||||||||||||
| intervals[0].Start++ | ||||||||||||||||||||||||||||||||||||||
| intervals[0].Stop++ | ||||||||||||||||||||||||||||||||||||||
| (*mSet)[u][tag] = intervals | ||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| clone = mSet | ||||||||||||||||||||||||||||||||||||||
| case gmysql.MariaDBFlavor: | ||||||||||||||||||||||||||||||||||||||
| mariaGTID := singleGTID.(*gmysql.MariadbGTID) | ||||||||||||||||||||||||||||||||||||||
| mariaGTID.SequenceNumber++ | ||||||||||||||||||||||||||||||||||||||
| gtidSet := new(gmysql.MariadbGTIDSet) | ||||||||||||||||||||||||||||||||||||||
| gtidSet.Sets = map[uint32]map[uint32]*gmysql.MariadbGTID{ | ||||||||||||||||||||||||||||||||||||||
| mariaGTID.DomainID: { | ||||||||||||||||||||||||||||||||||||||
| mariaGTID.ServerID: mariaGTID, | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
| gtidSet.Sets = map[uint32]*gmysql.MariadbGTID{ | ||||||||||||||||||||||||||||||||||||||
| mariaGTID.DomainID: mariaGTID, | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| clone = gtidSet | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
174
to
180
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the MariaDB flavor case,
Suggested change
|
||||||||||||||||||||||||||||||||||||||
| default: | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -187,36 +196,40 @@ func verifySingleGTID(flavor string, gSet gmysql.GTIDSet) (interface{}, error) { | |||||||||||||||||||||||||||||||||||||
| if !ok { | ||||||||||||||||||||||||||||||||||||||
| return nil, terror.ErrBinlogGTIDMySQLNotValid.Generate(gSet) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| if len(mysqlGTIDs.Sets) != 1 { | ||||||||||||||||||||||||||||||||||||||
| return nil, terror.ErrBinlogOnlyOneGTIDSupport.Generate(len(mysqlGTIDs.Sets), gSet) | ||||||||||||||||||||||||||||||||||||||
| if len(*mysqlGTIDs) != 1 { | ||||||||||||||||||||||||||||||||||||||
| return nil, terror.ErrBinlogOnlyOneGTIDSupport.Generate(len(*mysqlGTIDs), gSet) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| var sid uuid.UUID | ||||||||||||||||||||||||||||||||||||||
| var tags map[gmysql.Tag]gmysql.IntervalSlice | ||||||||||||||||||||||||||||||||||||||
| for sid, tags = range *mysqlGTIDs { | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| var uuidSet *gmysql.UUIDSet | ||||||||||||||||||||||||||||||||||||||
| for _, uuidSet = range mysqlGTIDs.Sets { | ||||||||||||||||||||||||||||||||||||||
| _ = sid | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+202
to
+206
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||||||||||||||||||
| if len(tags) != 1 { | ||||||||||||||||||||||||||||||||||||||
| return nil, terror.ErrBinlogOnlyOneGTIDSupport.Generate(len(tags), gSet) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| intervals := uuidSet.Intervals | ||||||||||||||||||||||||||||||||||||||
| if intervals.Len() != 1 { | ||||||||||||||||||||||||||||||||||||||
| return nil, terror.ErrBinlogOnlyOneIntervalInUUID.Generate(intervals.Len(), gSet) | ||||||||||||||||||||||||||||||||||||||
| var intervals gmysql.IntervalSlice | ||||||||||||||||||||||||||||||||||||||
| for _, intervals = range tags { | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| if len(intervals) != 1 { | ||||||||||||||||||||||||||||||||||||||
| return nil, terror.ErrBinlogOnlyOneIntervalInUUID.Generate(len(intervals), gSet) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| interval := intervals[0] | ||||||||||||||||||||||||||||||||||||||
| if interval.Stop != interval.Start+1 { | ||||||||||||||||||||||||||||||||||||||
| return nil, terror.ErrBinlogIntervalValueNotValid.Generate(interval, gSet) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| return uuidSet, nil | ||||||||||||||||||||||||||||||||||||||
| return mysqlGTIDs, nil | ||||||||||||||||||||||||||||||||||||||
| case gmysql.MariaDBFlavor: | ||||||||||||||||||||||||||||||||||||||
| mariaGTIDs, ok := gSet.(*gmysql.MariadbGTIDSet) | ||||||||||||||||||||||||||||||||||||||
| if !ok { | ||||||||||||||||||||||||||||||||||||||
| return nil, terror.ErrBinlogGTIDMariaDBNotValid.Generate(gSet) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| gtidCount := 0 | ||||||||||||||||||||||||||||||||||||||
| var mariaGTID *gmysql.MariadbGTID | ||||||||||||||||||||||||||||||||||||||
| for _, set := range mariaGTIDs.Sets { | ||||||||||||||||||||||||||||||||||||||
| gtidCount += len(set) | ||||||||||||||||||||||||||||||||||||||
| for _, mariaGTID = range set { | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| gtidCount := len(mariaGTIDs.Sets) | ||||||||||||||||||||||||||||||||||||||
| if gtidCount != 1 { | ||||||||||||||||||||||||||||||||||||||
| return nil, terror.ErrBinlogOnlyOneGTIDSupport.Generate(gtidCount, gSet) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| var mariaGTID *gmysql.MariadbGTID | ||||||||||||||||||||||||||||||||||||||
| for _, mariaGTID = range mariaGTIDs.Sets { | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| return mariaGTID, nil | ||||||||||||||||||||||||||||||||||||||
| default: | ||||||||||||||||||||||||||||||||||||||
| return nil, terror.ErrBinlogGTIDSetNotValid.Generate(gSet, flavor) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
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.
The logic for extracting the single SID and Interval from a
MysqlGTIDSetis repeated here and innewGenerator(ingenerator.go). Since DM requires these sets to have exactly one entry (as enforced byverifySingleGTID), consider moving this extraction logic into a helper function to improve code reuse and maintainability.