Skip to content

Commit

Permalink
add region cache state test & fix some issues of replica selector (ti…
Browse files Browse the repository at this point in the history
…kv#910)

Signed-off-by: you06 <[email protected]>
  • Loading branch information
you06 committed Aug 14, 2023
1 parent 44f5025 commit d89c4b3
Show file tree
Hide file tree
Showing 5 changed files with 875 additions and 3 deletions.
4 changes: 3 additions & 1 deletion internal/locate/region_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,12 @@ func (c *RegionCache) Close() {
c.cancelFunc()
}

var reloadRegionInterval = int64(10 * time.Second)

// asyncCheckAndResolveLoop with
func (c *RegionCache) asyncCheckAndResolveLoop(interval time.Duration) {
ticker := time.NewTicker(interval)
reloadRegionTicker := time.NewTicker(10 * time.Second)
reloadRegionTicker := time.NewTicker(time.Duration(atomic.LoadInt64(&reloadRegionInterval)))
defer func() {
ticker.Stop()
reloadRegionTicker.Stop()
Expand Down
5 changes: 5 additions & 0 deletions internal/locate/region_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -2012,6 +2012,7 @@ func (s *RegionRequestSender) onRegionError(
}

// This peer is removed from the region. Invalidate the region since it's too stale.
// if the region error is from follower, can we mark the peer unavailable and reload region asynchronously?
if regionErr.GetRegionNotFound() != nil {
s.regionCache.InvalidateCachedRegion(ctx.Region)
return false, nil
Expand Down Expand Up @@ -2041,6 +2042,10 @@ func (s *RegionRequestSender) onRegionError(
s.replicaSelector.onDeadlineExceeded()
return true, nil
}
if s.replicaSelector.canFallback2Follower() {
// immediately retry on followers.
return true, nil
}
if s.replicaSelector != nil {
return s.replicaSelector.onServerIsBusy(bo, ctx, req, serverIsBusy)
}
Expand Down
Loading

0 comments on commit d89c4b3

Please sign in to comment.