Skip to content

Commit

Permalink
Merge pull request #545 from zeminzhou/sort-mariadb-gtid
Browse files Browse the repository at this point in the history
sort mariadb gtid set before printing
  • Loading branch information
lance6716 authored Apr 9, 2021
2 parents 0bd942a + 8b5c143 commit e4bb47e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
10 changes: 8 additions & 2 deletions mysql/mariadb_gtid.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package mysql
import (
"bytes"
"fmt"
"sort"
"strconv"
"strings"

"github.com/pingcap/errors"
"github.com/siddontang/go-log/log"
"github.com/siddontang/go/hack"
)

// MariadbGTID represent mariadb gtid, [domain ID]-[server-id]-[sequence]
Expand Down Expand Up @@ -157,7 +157,13 @@ func (s *MariadbGTIDSet) Update(GTIDStr string) error {
}

func (s *MariadbGTIDSet) String() string {
return hack.String(s.Encode())
sets := make([]string, 0, len(s.Sets))
for _, set := range s.Sets {
sets = append(sets, set.String())
}
sort.Strings(sets)

return strings.Join(sets, ",")
}

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

func (t *mariaDBTestSuite) TestMariaDBGTIDSetSortedString(c *check.C) {
cases := [][]string{{"", ""}, {"1-1-1", "1-1-1"},
{"2-2-2,1-1-1,3-2-1", "1-1-1,2-2-2,3-2-1"}}

for _, strs := range cases {
gtidSet, err := ParseMariadbGTIDSet(strs[0])
c.Assert(err, check.IsNil)
c.Assert(gtidSet.String(), check.Equals, strs[1])
}
}

0 comments on commit e4bb47e

Please sign in to comment.