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

sort mariadb gtid set #545

Merged
merged 6 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
22 changes: 21 additions & 1 deletion mysql/mariadb_gtid.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mysql
import (
"bytes"
"fmt"
"sort"
"strconv"
"strings"

Expand Down Expand Up @@ -157,7 +158,26 @@ func (s *MariadbGTIDSet) Update(GTIDStr string) error {
}

func (s *MariadbGTIDSet) String() string {
return hack.String(s.Encode())
if len(s.Sets) == 1 {
for _, set := range s.Sets {
return set.String()
}
}

var buf bytes.Buffer
sets := make([]string, 0, len(s.Sets))
for _, set := range s.Sets {
sets = append(sets, set.String())
}
sort.Strings(sets)

sep := ""
lance6716 marked this conversation as resolved.
Show resolved Hide resolved
for _, set := range sets {
buf.WriteString(sep)
buf.WriteString(set)
sep = ","
}
return hack.String(buf.Bytes())
}

// Encode encodes mariadb gtid set
Expand Down
9 changes: 9 additions & 0 deletions mysql/mariadb_gtid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,12 @@ func (t *mariaDBTestSuite) TestMariaDBGTIDSetClone(c *check.C) {
c.Assert(gtidSet.Clone(), check.DeepEquals, gtidSet)
}
}

func (t *mariaDBTestSuite) TestMariaDBGTIDSetSortedString(c *check.C) {
gtidSetStr := "2-2-2,1-1-1,3-2-1"
lance6716 marked this conversation as resolved.
Show resolved Hide resolved
sorted := "1-1-1,2-2-2,3-2-1"

gtidSet, err := ParseMariadbGTIDSet(gtidSetStr)
c.Assert(err, check.IsNil)
c.Assert(gtidSet.String(), check.Equals, sorted)
}