Skip to content

Commit

Permalink
async replication refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
suetin committed May 6, 2024
1 parent a155b32 commit 27b7834
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 26 deletions.
28 changes: 2 additions & 26 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2136,23 +2136,8 @@ func (app *App) waitForCatchUp(node *mysql.Node, gtidset gtids.GTIDSet, timeout
if app.dcs.Get(pathCurrentSwitch, switchover) == dcs.ErrNotFound {
return false, nil
}
if app.config.ASync && switchover.Cause == CauseAuto {
app.logger.Infof("async mode is active and this is auto switch so we checking new master delay")
ts, err := app.GetMdbReplMonTS()
if err != nil {
app.logger.Errorf("failed to get mdb repl mon ts: %v", err)
continue
}
delay, err := node.CalcMdbReplMonTSDelay(ts)
if err != nil {
app.logger.Errorf("failed to calc mdb repl mon ts: %v", err)
continue
}
if delay < app.config.AsyncAllowedLag {
app.logger.Infof("async allowed lag is %d and current lag on host %s is %d, so we don't wait for catch up any more",
app.config.AsyncAllowedLag, node.Host(), delay)
return true, nil
}
if app.CheckAsyncSwitchAllowed(node, switchover) {
return true, nil
}
time.Sleep(sleep)
if time.Now().After(deadline) {
Expand Down Expand Up @@ -2257,15 +2242,6 @@ func (app *App) getNodePositions(activeNodes []string) ([]nodePosition, error) {
return positions, util.CombineErrors(errs)
}

func (app *App) updateMdbReplMonTS(master string) error {
masterNode := app.cluster.Get(master)
ts, err := masterNode.GetMdbReplMonTS()
if err != nil {
return fmt.Errorf("failed to get master mdb_repl_mon timestamp: %v", err)
}
return app.SetMdbReplMonTS(ts)
}

/*
Run enters the main application loop
When Run exits mysync process is over
Expand Down
37 changes: 37 additions & 0 deletions internal/app/async.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package app

import (
"fmt"

Check failure on line 4 in internal/app/async.go

View workflow job for this annotation

GitHub Actions / lint

File is not `goimports`-ed (goimports)
"github.com/yandex/mysync/internal/mysql"
)

func (app *App) CheckAsyncSwitchAllowed(node *mysql.Node, switchover *Switchover) bool {
if app.config.ASync && switchover.Cause == CauseAuto {
app.logger.Infof("async mode is active and this is auto switch so we checking new master delay")
ts, err := app.GetMdbReplMonTS()
if err != nil {
app.logger.Errorf("failed to get mdb repl mon ts: %v", err)
return false
}
delay, err := node.CalcMdbReplMonTSDelay(ts)
if err != nil {
app.logger.Errorf("failed to calc mdb repl mon ts: %v", err)
return false
}
if delay < app.config.AsyncAllowedLag {
app.logger.Infof("async allowed lag is %d and current lag on host %s is %d, so we don't wait for catch up any more",
app.config.AsyncAllowedLag, node.Host(), delay)
return true
}
}
return false
}

func (app *App) updateMdbReplMonTS(master string) error {
masterNode := app.cluster.Get(master)
ts, err := masterNode.GetMdbReplMonTS()
if err != nil {
return fmt.Errorf("failed to get master mdb_repl_mon timestamp: %v", err)
}
return app.SetMdbReplMonTS(ts)
}

Check failure on line 37 in internal/app/async.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)

0 comments on commit 27b7834

Please sign in to comment.