Skip to content

Commit 2e66675

Browse files
authored
Merge branch 'master' into remove_failover
2 parents af687be + 37a3291 commit 2e66675

File tree

4 files changed

+41
-21
lines changed

4 files changed

+41
-21
lines changed

cmd/go-mysqlbinlog/main.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ func main() {
4040
ServerID: 101,
4141
Flavor: *flavor,
4242

43-
Host: *host,
44-
Port: uint16(*port),
45-
User: *user,
46-
Password: *password,
47-
RawModeEnabled: *rawMode,
48-
SemiSyncEnabled: *semiSync,
49-
UseDecimal: true,
43+
Host: *host,
44+
Port: uint16(*port),
45+
User: *user,
46+
Password: *password,
47+
RawModeEnabled: *rawMode,
48+
SemiSyncEnabled: *semiSync,
49+
UseDecimal: true,
50+
MaxReconnectAttempts: 10,
5051
}
5152

5253
b := replication.NewBinlogSyncer(cfg)

cmd/go-mysqldump/main.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,27 @@ var (
1515
addr = flag.String("addr", "127.0.0.1:3306", "MySQL addr")
1616
user = flag.String("user", "root", "MySQL user")
1717
password = flag.String("password", "", "MySQL password")
18-
execution = flag.String("exec", "mysqldump", "mysqldump execution path")
18+
execution = flag.String("exec", "", "mysqldump/mariadb-dump execution path")
1919
output = flag.String("o", "", "dump output, empty for stdout")
2020

21-
dbs = flag.String("dbs", "", "dump databases, separated by comma")
22-
tables = flag.String("tables", "", "dump tables, separated by comma, will overwrite dbs")
23-
tableDB = flag.String("table_db", "", "database for dump tables")
24-
ignoreTables = flag.String("ignore_tables", "", "ignore tables, must be database.table format, separated by comma")
21+
dbs = flag.String("dbs", "", "dump databases, separated by comma")
22+
tables = flag.String("tables", "", "dump tables, separated by comma, will overwrite dbs")
23+
tableDB = flag.String("table_db", "", "database for dump tables")
24+
ignoreTables = flag.String("ignore_tables", "", "ignore tables, must be database.table format, separated by comma")
25+
skipBinlogPos = flag.Bool("skip-binlog-pos", false, "skip fetching binlog position via --master-data/--source-data")
2526
)
2627

2728
func main() {
2829
flag.Parse()
2930

3031
d, err := dump.NewDumper(*execution, *addr, *user, *password)
3132
if err != nil {
32-
fmt.Printf("Create Dumper error %v\n", errors.ErrorStack(err))
33+
fmt.Printf("Create Dumper error: %v\n", errors.ErrorStack(err))
3334
os.Exit(1)
3435
}
3536

37+
d.SkipMasterData(*skipBinlogPos)
38+
3639
if len(*ignoreTables) > 0 {
3740
subs := strings.Split(*ignoreTables, ",")
3841
for _, sub := range subs {

dump/dumper.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,23 @@ type Dumper struct {
5151
}
5252

5353
func NewDumper(executionPath string, addr string, user string, password string) (*Dumper, error) {
54-
if len(executionPath) == 0 {
55-
return nil, nil
56-
}
54+
var path string
55+
var err error
5756

58-
path, err := exec.LookPath(executionPath)
59-
if err != nil {
60-
return nil, errors.Trace(err)
57+
if len(executionPath) == 0 { // No explicit path set
58+
path, err = exec.LookPath("mysqldump")
59+
if err != nil {
60+
path, err = exec.LookPath("mariadb-dump")
61+
if err != nil {
62+
// Using a new error as `err` will only mention mariadb-dump and not mysqldump
63+
return nil, errors.New("not able to find mysqldump or mariadb-dump in path")
64+
}
65+
}
66+
} else {
67+
path, err = exec.LookPath(executionPath)
68+
if err != nil {
69+
return nil, err
70+
}
6171
}
6272

6373
d := new(Dumper)

replication/binlogsyncer.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,12 +749,18 @@ func (b *BinlogSyncer) onStream(s *BinlogStreamer) {
749749
b.retryCount++
750750
if err = b.retrySync(); err != nil {
751751
if b.cfg.MaxReconnectAttempts > 0 && b.retryCount >= b.cfg.MaxReconnectAttempts {
752-
b.cfg.Logger.Errorf("retry sync err: %v, exceeded max retries (%d)", err, b.cfg.MaxReconnectAttempts)
752+
b.cfg.Logger.Errorf(
753+
"retry sync err: %v, exceeded max retries (%d)",
754+
err, b.cfg.MaxReconnectAttempts,
755+
)
753756
s.closeWithError(err)
754757
return
755758
}
756759

757-
b.cfg.Logger.Errorf("retry sync err: %v, wait 1s and retry again", err)
760+
b.cfg.Logger.Errorf(
761+
"retry sync err: %v, wait 1s and retry again (retries: %d/%d)",
762+
err, b.retryCount, b.cfg.MaxReconnectAttempts,
763+
)
758764
continue
759765
}
760766
}

0 commit comments

Comments
 (0)