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

Add GTID-based replication to example #615

Merged
merged 2 commits into from
Sep 2, 2021
Merged
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
26 changes: 22 additions & 4 deletions cmd/go-mysqlbinlog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var flavor = flag.String("flavor", "mysql", "Flavor: mysql or mariadb")

var file = flag.String("file", "", "Binlog filename")
var pos = flag.Int("pos", 4, "Binlog position")
var gtid = flag.String("gtid", "", "Binlog GTID set that this slave has executed")

var semiSync = flag.Bool("semisync", false, "Support semi sync")
var backupPath = flag.String("backup_path", "", "backup path to store binlog files")
Expand Down Expand Up @@ -57,10 +58,27 @@ func main() {
return
}
} else {
s, err := b.StartSync(pos)
if err != nil {
fmt.Printf("Start sync error: %v\n", errors.ErrorStack(err))
return
var (
s *replication.BinlogStreamer
err error
)
if len(*gtid) > 0 {
gset, err := mysql.ParseGTIDSet(*flavor, *gtid)
if err != nil {
fmt.Printf("Failed to parse gtid %s with flavor %s, error: %v\n",
*gtid, *flavor, errors.ErrorStack(err))
}
s, err = b.StartSyncGTID(gset)
if err != nil {
fmt.Printf("Start sync by GTID error: %v\n", errors.ErrorStack(err))
return
}
} else {
s, err = b.StartSync(pos)
if err != nil {
fmt.Printf("Start sync error: %v\n", errors.ErrorStack(err))
return
}
}

for {
Expand Down