Skip to content

Commit

Permalink
go-mysqlbinlog: set to retry only 10 times
Browse files Browse the repository at this point in the history
  • Loading branch information
dveeden committed Nov 8, 2024
1 parent 867d4cc commit 5d8d5a6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 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
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 5d8d5a6

Please sign in to comment.