Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

Commit

Permalink
cherry pick #1385 to release-2.0 (#1395)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot authored Jan 21, 2021
1 parent decdcd4 commit fd608ec
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 12 deletions.
2 changes: 1 addition & 1 deletion dm/config/source_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (c *SourceConfig) ParseYaml(content string) error {
return terror.ErrConfigYamlTransform.Delegate(err, "decode source config")
}
c.adjust()
return c.Verify()
return nil
}

// EncodeToml encodes config.
Expand Down
4 changes: 4 additions & 0 deletions dm/master/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,10 @@ func parseAndAdjustSourceConfig(ctx context.Context, contents []string) ([]*conf
return cfgs, err
}

if err = cfg.Verify(); err != nil {
return cfgs, err
}

fromDB.Close()
cfgs[i] = cfg
}
Expand Down
5 changes: 3 additions & 2 deletions dm/worker/source.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ server-id: 101
source-id: mysql-replica-01

#flavor: mysql/mariadb
flavor: mysql

#directory that used to store relay log
relay-dir: ./relay_log

#enable gtid in relay log unit
enable-gtid: false
enable-gtid: true

relay-binlog-gtid: "e68f6068-53ec-11eb-9c5f-0242ac110003:1-50"

#charset of DSN of source mysql/mariadb instance
# charset: ''
Expand Down
30 changes: 25 additions & 5 deletions pkg/gtid/gtid.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package gtid

import (
"github.com/pingcap/errors"
"github.com/siddontang/go-mysql/mysql"

"github.com/pingcap/dm/pkg/terror"
Expand Down Expand Up @@ -47,16 +48,35 @@ type Set interface {
// ParserGTID parses GTID from string
func ParserGTID(flavor, gtidStr string) (Set, error) {
var (
m Set
err error
m Set
err error
gtid mysql.GTIDSet
)

gtid, err := mysql.ParseGTIDSet(flavor, gtidStr)
if len(flavor) == 0 && len(gtidStr) == 0 {
return nil, errors.Errorf("empty flavor with empty gtid is invalid")
}

fla := flavor
switch fla {
case mysql.MySQLFlavor, mysql.MariaDBFlavor:
gtid, err = mysql.ParseGTIDSet(fla, gtidStr)
case "":
fla = mysql.MySQLFlavor
gtid, err = mysql.ParseGTIDSet(fla, gtidStr)
if err != nil {
fla = mysql.MariaDBFlavor
gtid, err = mysql.ParseGTIDSet(fla, gtidStr)
}
default:
err = terror.ErrNotSupportedFlavor.Generate(flavor)
}

if err != nil {
return nil, terror.ErrParseGTID.Delegate(err, gtidStr)
return nil, err
}

switch flavor {
switch fla {
case mysql.MariaDBFlavor:
m = &MariadbGTIDSet{}
case mysql.MySQLFlavor:
Expand Down
8 changes: 8 additions & 0 deletions pkg/gtid/gtid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ func (s *testGTIDSuite) TestGTID(c *C) {
{"mysql", []interface{}{matserUUIDs[0]}, fmt.Sprintf("%s:1-2", matserUUIDs[1]), "", ""},
{"mysql", []interface{}{matserUUIDs[0], matserUUIDs[1]}, fmt.Sprintf("%s:1-2,%s:1-2", matserUUIDs[0], matserUUIDs[1]), fmt.Sprintf("%s:1-12,%s:1-4,%s:1-4", matserUUIDs[0], matserUUIDs[1], matserUUIDs[2]), fmt.Sprintf("%s:1-2,%s:1-2,%s:1-4", matserUUIDs[0], matserUUIDs[1], matserUUIDs[2])},
{"mysql", []interface{}{matserUUIDs[0], matserUUIDs[2]}, fmt.Sprintf("%s:1-2", matserUUIDs[1]), fmt.Sprintf("%s:1-12,%s:1-3,%s:1-4", matserUUIDs[0], matserUUIDs[1], matserUUIDs[2]), fmt.Sprintf("%s:1-2", matserUUIDs[1])},
{"", []interface{}{uint32(1)}, "1-1-1,2-2-2", "1-1-12,4-4-4", "1-1-1,4-4-4"},
{"", []interface{}{uint32(1)}, "2-2-2", "1-2-12,2-2-3,4-4-4", "2-2-2,4-4-4"},
{"", []interface{}{uint32(1), uint32(3)}, "1-1-1,3-3-4,2-2-2", "1-1-12,3-3-8,4-4-4", "1-1-1,3-3-4,4-4-4"},
{"", []interface{}{uint32(1), uint32(3)}, "2-2-2", "1-2-12,2-2-3,3-3-8,4-4-4", "2-2-2,4-4-4"},
{"", []interface{}{matserUUIDs[0]}, fmt.Sprintf("%s:1-2,%s:1-2", matserUUIDs[0], matserUUIDs[1]), fmt.Sprintf("%s:1-12,%s:1-4", matserUUIDs[0], matserUUIDs[2]), fmt.Sprintf("%s:1-2,%s:1-4", matserUUIDs[0], matserUUIDs[2])},
{"", []interface{}{matserUUIDs[0]}, fmt.Sprintf("%s:1-2", matserUUIDs[1]), fmt.Sprintf("%s:1-12,%s:1-3,%s:1-4", matserUUIDs[0], matserUUIDs[1], matserUUIDs[2]), fmt.Sprintf("%s:1-2,%s:1-4", matserUUIDs[1], matserUUIDs[2])},
{"", []interface{}{matserUUIDs[0], matserUUIDs[1]}, fmt.Sprintf("%s:1-2,%s:1-2", matserUUIDs[0], matserUUIDs[1]), fmt.Sprintf("%s:1-12,%s:1-4,%s:1-4", matserUUIDs[0], matserUUIDs[1], matserUUIDs[2]), fmt.Sprintf("%s:1-2,%s:1-2,%s:1-4", matserUUIDs[0], matserUUIDs[1], matserUUIDs[2])},
{"", []interface{}{matserUUIDs[0], matserUUIDs[2]}, fmt.Sprintf("%s:1-2", matserUUIDs[1]), fmt.Sprintf("%s:1-12,%s:1-3,%s:1-4", matserUUIDs[0], matserUUIDs[1], matserUUIDs[2]), fmt.Sprintf("%s:1-2", matserUUIDs[1])},
}

for _, cs := range cases {
Expand Down
10 changes: 6 additions & 4 deletions relay/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,11 +473,13 @@ func (lm *LocalMeta) loadMetaData() error {
return terror.ErrRelayLoadMetaData.Delegate(err)
}

gset, err := gtid.ParserGTID(lm.flavor, lm.BinlogGTID)
if err != nil {
return terror.ErrRelayLoadMetaData.Delegate(err)
if len(lm.BinlogGTID) != 0 {
gset, err := gtid.ParserGTID("", lm.BinlogGTID)
if err != nil {
return terror.ErrRelayLoadMetaData.Delegate(err)
}
lm.gset = gset
}
lm.gset = gset

return nil
}

0 comments on commit fd608ec

Please sign in to comment.