Skip to content
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

Update method now may receive strings with GTID sets #569

Merged
merged 2 commits into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions mysql/mariadb_gtid.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,9 @@ func ParseMariadbGTIDSet(str string) (GTIDSet, error) {
if str == "" {
return s, nil
}

sp := strings.Split(str, ",")

//todo, handle redundant same uuid
for i := 0; i < len(sp); i++ {
err := s.Update(sp[i])
if err != nil {
return nil, errors.Trace(err)
}
err := s.Update(str)
if err != nil {
return nil, err
}
return s, nil
}
Expand All @@ -147,13 +141,19 @@ func (s *MariadbGTIDSet) AddSet(gtid *MariadbGTID) error {

// Update updates mariadb gtid set
func (s *MariadbGTIDSet) Update(GTIDStr string) error {
gtid, err := ParseMariadbGTID(GTIDStr)
if err != nil {
return err
sp := strings.Split(GTIDStr, ",")
//todo, handle redundant same uuid
for i := 0; i < len(sp); i++ {
gtid, err := ParseMariadbGTID(sp[i])
if err != nil {
return errors.Trace(err)
}
err = s.AddSet(gtid)
if err != nil {
return errors.Trace(err)
}
}

err = s.AddSet(gtid)
return errors.Trace(err)
return nil
}

func (s *MariadbGTIDSet) String() string {
Expand Down
1 change: 1 addition & 0 deletions mysql/mariadb_gtid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func (t *mariaDBTestSuite) TestMariaDBGTIDSetUpdate(c *check.C) {
{false, "1-2-2", map[uint32]string{1: "1-2-2", 2: "2-2-2"}},
{false, "1-2-1", map[uint32]string{1: "1-2-1", 2: "2-2-2"}},
{false, "3-2-1", map[uint32]string{1: "1-1-1", 2: "2-2-2", 3: "3-2-1"}},
{false, "3-2-1,4-2-1", map[uint32]string{1: "1-1-1", 2: "2-2-2", 3: "3-2-1", 4: "4-2-1"}},
}

for _, cs := range cases {
Expand Down
8 changes: 4 additions & 4 deletions mysql/mysql_gtid.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,13 @@ func (s *MysqlGTIDSet) AddSet(set *UUIDSet) {
}

func (s *MysqlGTIDSet) Update(GTIDStr string) error {
uuidSet, err := ParseUUIDSet(GTIDStr)
gtidSet, err := ParseMysqlGTIDSet(GTIDStr)
if err != nil {
return err
}

s.AddSet(uuidSet)

for _, uuidSet := range gtidSet.(*MysqlGTIDSet).Sets {
s.AddSet(uuidSet)
}
return nil
}

Expand Down
23 changes: 23 additions & 0 deletions mysql/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,29 @@ func (t *mysqlTestSuite) TestMysqlUpdate(c *check.C) {
c.Assert(err, check.IsNil)

c.Assert(strings.ToUpper(g1.String()), check.Equals, "3E11FA47-71CA-11E1-9E33-C80AA9429562:21-58")

g1, err = ParseMysqlGTIDSet(`
519CE70F-A893-11E9-A95A-B32DC65A7026:1-1154661,
5C9CA52B-9F11-11E9-8EAF-3381EC1CC790:1-244,
802D69FD-A3B6-11E9-B1EA-50BAB55BA838:1-1221371,
F2B50559-A891-11E9-B646-884FF0CA2043:1-479261
`)
c.Assert(err, check.IsNil)

err = g1.Update(`
802D69FD-A3B6-11E9-B1EA-50BAB55BA838:1221110-1221371,
F2B50559-A891-11E9-B646-884FF0CA2043:478509-479266
`)
c.Assert(err, check.IsNil)

g2, err := ParseMysqlGTIDSet(`
519CE70F-A893-11E9-A95A-B32DC65A7026:1-1154661,
5C9CA52B-9F11-11E9-8EAF-3381EC1CC790:1-244,
802D69FD-A3B6-11E9-B1EA-50BAB55BA838:1-1221371,
F2B50559-A891-11E9-B646-884FF0CA2043:1-479266
`)
c.Assert(err, check.IsNil)
c.Assert(g2.Equal(g1), check.IsTrue)
}

func (t *mysqlTestSuite) TestMysqlGTIDContain(c *check.C) {
Expand Down