Skip to content

Commit 0a1eda9

Browse files
rleungxti-chi-bot
authored andcommitted
This is an automated cherry-pick of tikv#8824
close tikv#8823 Signed-off-by: ti-chi-bot <[email protected]>
1 parent 57d5bdc commit 0a1eda9

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

Diff for: pkg/syncer/client.go

+23-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const (
4141
keepaliveTime = 10 * time.Second
4242
keepaliveTimeout = 3 * time.Second
4343
msgSize = 8 * units.MiB
44+
retryInterval = time.Second
4445
)
4546

4647
// StopSyncWithLeader stop to sync the region with leader.
@@ -150,7 +151,12 @@ func (s *RegionSyncer) StartSyncWithLeader(addr string) {
150151
}
151152
}
152153
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))
153-
time.Sleep(time.Second)
154+
select {
155+
case <-ctx.Done():
156+
log.Info("stop synchronizing with leader due to context canceled")
157+
return
158+
case <-time.After(retryInterval):
159+
}
154160
continue
155161
}
156162
log.Info("server starts to synchronize with leader", zap.String("server", s.server.Name()), zap.String("leader", s.server.GetLeader().GetName()), zap.Uint64("request-index", s.history.GetNextIndex()))
@@ -162,7 +168,12 @@ func (s *RegionSyncer) StartSyncWithLeader(addr string) {
162168
if err = stream.CloseSend(); err != nil {
163169
log.Error("failed to terminate client stream", errs.ZapError(errs.ErrGRPCCloseSend, err))
164170
}
165-
time.Sleep(time.Second)
171+
select {
172+
case <-ctx.Done():
173+
log.Info("stop synchronizing with leader due to context canceled")
174+
return
175+
case <-time.After(retryInterval):
176+
}
166177
break
167178
}
168179
if s.history.GetNextIndex() != resp.GetStartIndex() {
@@ -206,7 +217,17 @@ func (s *RegionSyncer) StartSyncWithLeader(addr string) {
206217
log.Debug("region is stale", zap.Stringer("origin", origin.GetMeta()), errs.ZapError(err))
207218
continue
208219
}
220+
<<<<<<< HEAD
209221
saveKV, _, _ := regionGuide(region, origin)
222+
=======
223+
cctx := &core.MetaProcessContext{
224+
Context: ctx,
225+
TaskRunner: ratelimit.NewSyncRunner(),
226+
Tracer: core.NewNoopHeartbeatProcessTracer(),
227+
// no limit for followers.
228+
}
229+
saveKV, _, _, _ := regionGuide(cctx, region, origin)
230+
>>>>>>> 41ec8dced (syncer: exit watch leader immediately (#8824))
210231
overlaps := bc.PutRegion(region)
211232

212233
if hasBuckets {

0 commit comments

Comments
 (0)