@@ -2423,6 +2423,7 @@ func (c *RaftCluster) SetStoreLimit(storeID uint64, typ storelimit.Type, ratePer
24232423 log .Error ("persist store limit meet error" , errs .ZapError (err ))
24242424 return err
24252425 }
2426+ c .refreshStoreRateLimit (storeID , typ )
24262427 log .Info ("store limit changed" , zap .Uint64 ("store-id" , storeID ), zap .String ("type" , typ .String ()), zap .Float64 ("rate-per-min" , ratePerMin ))
24272428 return nil
24282429}
@@ -2441,10 +2442,35 @@ func (c *RaftCluster) SetAllStoresLimit(typ storelimit.Type, ratePerMin float64)
24412442 log .Error ("persist store limit meet error" , errs .ZapError (err ))
24422443 return err
24432444 }
2445+ for storeID := range c .opt .GetAllStoresLimit () {
2446+ c .refreshStoreRateLimit (storeID , typ )
2447+ }
24442448 log .Info ("all store limit changed" , zap .String ("type" , typ .String ()), zap .Float64 ("rate-per-min" , ratePerMin ))
24452449 return nil
24462450}
24472451
2452+ // refreshStoreRateLimit applies the schedule config's store limit to the in-memory store limiter.
2453+ func (c * RaftCluster ) refreshStoreRateLimit (storeID uint64 , limitType storelimit.Type ) {
2454+ // Only v1 uses StoreRateLimit for AddPeer/RemovePeer.
2455+ if c .opt .GetStoreLimitVersion () != storelimit .VersionV1 {
2456+ return
2457+ }
2458+ store := c .GetStore (storeID )
2459+ if store == nil {
2460+ return
2461+ }
2462+ limit , ok := store .GetStoreLimit ().(* storelimit.StoreRateLimit )
2463+ if ! ok {
2464+ return
2465+ }
2466+ // Schedule config stores the unit in rate-per-minute, but limiter uses rate-per-second.
2467+ const storeBalanceBaseTime = float64 (60 )
2468+ ratePerSec := c .opt .GetStoreLimitByType (storeID , limitType ) / storeBalanceBaseTime
2469+ if limit .Rate (limitType ) != ratePerSec {
2470+ c .ResetStoreLimit (storeID , limitType , ratePerSec )
2471+ }
2472+ }
2473+
24482474// SetAllStoresLimitTTL sets all store limit for a given type and rate with ttl.
24492475func (c * RaftCluster ) SetAllStoresLimitTTL (typ storelimit.Type , ratePerMin float64 , ttl time.Duration ) error {
24502476 return c .opt .SetAllStoresLimitTTL (c .ctx , c .etcdClient , typ , ratePerMin , ttl )
0 commit comments