Skip to content

Commit

Permalink
syncer: exit watch leader immediately (#8824) (#8827)
Browse files Browse the repository at this point in the history
close #8823

Signed-off-by: ti-chi-bot <[email protected]>
Signed-off-by: Ryan Leung <[email protected]>

Co-authored-by: Ryan Leung <[email protected]>
  • Loading branch information
ti-chi-bot and rleungx authored Dec 20, 2024
1 parent 445fbd4 commit 3e55a4f
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions server/region_syncer/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
const (
keepaliveTime = 10 * time.Second
keepaliveTimeout = 3 * time.Second
retryInterval = time.Second
)

// StopSyncWithLeader stop to sync the region with leader.
Expand Down Expand Up @@ -163,7 +164,15 @@ func (s *RegionSyncer) StartSyncWithLeader(addr string) {
}
}
log.Error("server failed to establish sync stream with leader", zap.String("server", s.server.Name()), zap.String("leader", s.server.GetLeader().GetName()), errs.ZapError(err))
time.Sleep(time.Second)
timer := time.NewTimer(retryInterval)
select {
case <-ctx.Done():
log.Info("stop synchronizing with leader due to context canceled")
timer.Stop()
return
case <-timer.C:
timer.Stop()
}
continue
}

Expand All @@ -175,7 +184,15 @@ func (s *RegionSyncer) StartSyncWithLeader(addr string) {
if err = stream.CloseSend(); err != nil {
log.Error("failed to terminate client stream", errs.ZapError(errs.ErrGRPCCloseSend, err))
}
time.Sleep(time.Second)
timer := time.NewTimer(retryInterval)
select {
case <-ctx.Done():
log.Info("stop synchronizing with leader due to context canceled")
timer.Stop()
return
case <-timer.C:
timer.Stop()
}
break
}
if s.history.GetNextIndex() != resp.GetStartIndex() {
Expand Down

0 comments on commit 3e55a4f

Please sign in to comment.