Skip to content

Commit

Permalink
Merge branch 'master' into remove_failover
Browse files Browse the repository at this point in the history
  • Loading branch information
lance6716 authored Nov 11, 2024
2 parents af687be + 37a3291 commit 2e66675
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 21 deletions.
15 changes: 8 additions & 7 deletions cmd/go-mysqlbinlog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ func main() {
ServerID: 101,
Flavor: *flavor,

Host: *host,
Port: uint16(*port),
User: *user,
Password: *password,
RawModeEnabled: *rawMode,
SemiSyncEnabled: *semiSync,
UseDecimal: true,
Host: *host,
Port: uint16(*port),
User: *user,
Password: *password,
RawModeEnabled: *rawMode,
SemiSyncEnabled: *semiSync,
UseDecimal: true,
MaxReconnectAttempts: 10,
}

b := replication.NewBinlogSyncer(cfg)
Expand Down
15 changes: 9 additions & 6 deletions cmd/go-mysqldump/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,27 @@ var (
addr = flag.String("addr", "127.0.0.1:3306", "MySQL addr")
user = flag.String("user", "root", "MySQL user")
password = flag.String("password", "", "MySQL password")
execution = flag.String("exec", "mysqldump", "mysqldump execution path")
execution = flag.String("exec", "", "mysqldump/mariadb-dump execution path")
output = flag.String("o", "", "dump output, empty for stdout")

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

func main() {
flag.Parse()

d, err := dump.NewDumper(*execution, *addr, *user, *password)
if err != nil {
fmt.Printf("Create Dumper error %v\n", errors.ErrorStack(err))
fmt.Printf("Create Dumper error: %v\n", errors.ErrorStack(err))
os.Exit(1)
}

d.SkipMasterData(*skipBinlogPos)

if len(*ignoreTables) > 0 {
subs := strings.Split(*ignoreTables, ",")
for _, sub := range subs {
Expand Down
22 changes: 16 additions & 6 deletions dump/dumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,23 @@ type Dumper struct {
}

func NewDumper(executionPath string, addr string, user string, password string) (*Dumper, error) {
if len(executionPath) == 0 {
return nil, nil
}
var path string
var err error

path, err := exec.LookPath(executionPath)
if err != nil {
return nil, errors.Trace(err)
if len(executionPath) == 0 { // No explicit path set
path, err = exec.LookPath("mysqldump")
if err != nil {
path, err = exec.LookPath("mariadb-dump")
if err != nil {
// Using a new error as `err` will only mention mariadb-dump and not mysqldump
return nil, errors.New("not able to find mysqldump or mariadb-dump in path")
}
}
} else {
path, err = exec.LookPath(executionPath)
if err != nil {
return nil, err
}
}

d := new(Dumper)
Expand Down
10 changes: 8 additions & 2 deletions replication/binlogsyncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -749,12 +749,18 @@ func (b *BinlogSyncer) onStream(s *BinlogStreamer) {
b.retryCount++
if err = b.retrySync(); err != nil {
if b.cfg.MaxReconnectAttempts > 0 && b.retryCount >= b.cfg.MaxReconnectAttempts {
b.cfg.Logger.Errorf("retry sync err: %v, exceeded max retries (%d)", err, b.cfg.MaxReconnectAttempts)
b.cfg.Logger.Errorf(
"retry sync err: %v, exceeded max retries (%d)",
err, b.cfg.MaxReconnectAttempts,
)
s.closeWithError(err)
return
}

b.cfg.Logger.Errorf("retry sync err: %v, wait 1s and retry again", err)
b.cfg.Logger.Errorf(
"retry sync err: %v, wait 1s and retry again (retries: %d/%d)",
err, b.retryCount, b.cfg.MaxReconnectAttempts,
)
continue
}
}
Expand Down

0 comments on commit 2e66675

Please sign in to comment.