Skip to content

Commit

Permalink
start using the retry limiter
Browse files Browse the repository at this point in the history
  • Loading branch information
artem_danilov committed Oct 25, 2024
1 parent a1b5339 commit da98bdc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config/retry/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ var (
BoTiFlashRPC = NewConfig("tiflashRPC", &metrics.BackoffHistogramRPC, NewBackoffFnCfg(100, 2000, EqualJitter), tikverr.ErrTiFlashServerTimeout)
BoTxnLock = NewConfig("txnLock", &metrics.BackoffHistogramLock, NewBackoffFnCfg(100, 3000, EqualJitter), tikverr.ErrResolveLockTimeout)
BoPDRPC = NewConfig("pdRPC", &metrics.BackoffHistogramPD, NewBackoffFnCfg(500, 3000, EqualJitter), tikverr.NewErrPDServerTimeout(""))
BoPDRegionMetadata = NewConfigWithRetryLimit("pdRegionMetadata", &metrics.BackoffHistogramPD, NewBackoffFnCfg(500, 3000, EqualJitter), NewRetryRateLimiter(10, 10), tikverr.NewErrPDServerTimeout(""))
BoPDRegionMetadata = NewConfigWithRetryLimit("pdRegionMetadata", &metrics.BackoffHistogramPD, NewBackoffFnCfg(500, 3000, EqualJitter), NewRetryRateLimiter(100, 1), tikverr.NewErrPDServerTimeout(""))
// change base time to 2ms, because it may recover soon.
BoRegionMiss = NewConfig("regionMiss", &metrics.BackoffHistogramRegionMiss, NewBackoffFnCfg(2, 500, NoJitter), tikverr.ErrRegionUnavailable)
BoRegionScheduling = NewConfig("regionScheduling", &metrics.BackoffHistogramRegionScheduling, NewBackoffFnCfg(2, 500, NoJitter), tikverr.ErrRegionUnavailable)
Expand Down
12 changes: 10 additions & 2 deletions internal/locate/region_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -2059,7 +2059,7 @@ func (c *RegionCache) loadRegion(bo *retry.Backoffer, key []byte, isEndKey bool,
opts = append(opts, pd.WithBuckets())
for {
if backoffErr != nil {
err := bo.Backoff(retry.BoPDRPC, backoffErr)
err := bo.Backoff(retry.BoPDRegionMetadata, backoffErr)
if err != nil {
return nil, errors.WithStack(err)
}
Expand All @@ -2077,6 +2077,10 @@ func (c *RegionCache) loadRegion(bo *retry.Backoffer, key []byte, isEndKey bool,
metrics.RegionCacheCounterWithGetCacheMissError.Inc()
} else {
metrics.RegionCacheCounterWithGetCacheMissOK.Inc()
if backoffErr == nil {
// refill retry allowance only for the original call
bo.OnSuccess(retry.BoPDRegionMetadata)
}
}
if err != nil {
if apicodec.IsDecodeError(err) {
Expand Down Expand Up @@ -2112,7 +2116,7 @@ func (c *RegionCache) loadRegionByID(bo *retry.Backoffer, regionID uint64) (*Reg
var backoffErr error
for {
if backoffErr != nil {
err := bo.Backoff(retry.BoPDRPC, backoffErr)
err := bo.Backoff(retry.BoPDRegionMetadata, backoffErr)
if err != nil {
return nil, errors.WithStack(err)
}
Expand All @@ -2124,6 +2128,10 @@ func (c *RegionCache) loadRegionByID(bo *retry.Backoffer, regionID uint64) (*Reg
metrics.RegionCacheCounterWithGetRegionByIDError.Inc()
} else {
metrics.RegionCacheCounterWithGetRegionByIDOK.Inc()
if backoffErr == nil {
// refill retry allowance only for the original call
bo.OnSuccess(retry.BoPDRegionMetadata)
}
}
if err != nil {
if apicodec.IsDecodeError(err) {
Expand Down

0 comments on commit da98bdc

Please sign in to comment.