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

fix: resolve Shake client hang in HandShaking state due to source Redis blocking during BGSAVE #879

Merged
merged 1 commit into from
Nov 11, 2024
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: 25 additions & 1 deletion internal/reader/sync_standalone_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (r *syncStandaloneReader) supportPSYNC() bool {
return false
}
}

}
}

Expand Down Expand Up @@ -178,6 +178,28 @@ func (r *syncStandaloneReader) sendReplconfListenPort() {
}
}

// When BGSAVE is triggered by the source Redis itself, synchronization is blocked, so need to check it
func (r *syncStandaloneReader) checkBgsaveInProgress() {
for {
select {
case <-r.ctx.Done():
close(r.ch)
runtime.Goexit() // stop goroutine
default:
argv := []interface{}{"INFO", "persistence"}
r.client.Send(argv...)
receiveString := r.client.ReceiveString()
if strings.Contains(receiveString, "rdb_bgsave_in_progress:1") {
log.Warnf("[%s] source db is doing bgsave, waiting for a while.", r.stat.Name)
} else {
log.Infof("[%s] source db is not doing bgsave! continue.", r.stat.Name)
return
}
time.Sleep(1 * time.Second)
}
}
}

func (r *syncStandaloneReader) sendPSync() {
if r.opts.TryDiskless {
argv := []interface{}{"REPLCONF", "CAPA", "EOF"}
Expand All @@ -186,6 +208,7 @@ func (r *syncStandaloneReader) sendPSync() {
log.Warnf("[%s] send replconf capa eof to redis server failed. reply=[%v]", r.stat.Name, reply)
}
}
r.checkBgsaveInProgress()
// send PSync
argv := []interface{}{"PSYNC", "?", "-1"}
if config.Opt.Advanced.AwsPSync != "" {
Expand Down Expand Up @@ -226,6 +249,7 @@ func (r *syncStandaloneReader) sendSync() {
log.Warnf("[%s] send replconf capa eof to redis server failed. reply=[%v]", r.stat.Name, reply)
}
}
r.checkBgsaveInProgress()
// send SYNC
argv := []interface{}{"SYNC"}
if config.Opt.Advanced.AwsPSync != "" {
Expand Down
Loading