diff --git a/server/schedulers/hot_region.go b/server/schedulers/hot_region.go index f4073548d08..2dd80b31693 100644 --- a/server/schedulers/hot_region.go +++ b/server/schedulers/hot_region.go @@ -811,18 +811,21 @@ func (bs *balanceSolver) filterDstStores() map[uint64]*storeLoadDetail { default: return nil } + return bs.pickDstStores(filters, candidates) +} +func (bs *balanceSolver) pickDstStores(filters []filter.Filter, candidates []*core.StoreInfo) map[uint64]*storeLoadDetail { ret := make(map[uint64]*storeLoadDetail, len(candidates)) + dstToleranceRatio := bs.sche.conf.GetDstToleranceRatio() for _, store := range candidates { if filter.Target(bs.cluster, store, filters) { detail := bs.stLoadDetail[store.GetID()] - if detail.LoadPred.max().ByteRate*bs.sche.conf.GetDstToleranceRatio() < detail.LoadPred.Future.ExpByteRate && - detail.LoadPred.max().KeyRate*bs.sche.conf.GetDstToleranceRatio() < detail.LoadPred.Future.ExpKeyRate { + if detail.LoadPred.max().ByteRate*dstToleranceRatio < detail.LoadPred.Future.ExpByteRate && + detail.LoadPred.max().KeyRate*dstToleranceRatio < detail.LoadPred.Future.ExpKeyRate { ret[store.GetID()] = bs.stLoadDetail[store.GetID()] balanceHotRegionCounter.WithLabelValues("dst-store-succ", strconv.FormatUint(store.GetID(), 10)).Inc() } balanceHotRegionCounter.WithLabelValues("dst-store-fail", strconv.FormatUint(store.GetID(), 10)).Inc() - ret[store.GetID()] = bs.stLoadDetail[store.GetID()] } } return ret diff --git a/server/schedulers/hot_test.go b/server/schedulers/hot_test.go index 366cf09bed6..d230802e052 100644 --- a/server/schedulers/hot_test.go +++ b/server/schedulers/hot_test.go @@ -496,12 +496,12 @@ func (s *testHotReadRegionSchedulerSuite) TestByteRateOnly(c *C) { //|----------|-----------------| //| 1 | 7.5MB | //| 2 | 4.9MB | - //| 3 | 4.5MB | + //| 3 | 3.7MB | //| 4 | 6MB | //| 5 | 0MB | tc.UpdateStorageReadBytes(1, 7.5*MB*statistics.StoreHeartBeatReportInterval) tc.UpdateStorageReadBytes(2, 4.9*MB*statistics.StoreHeartBeatReportInterval) - tc.UpdateStorageReadBytes(3, 4.5*MB*statistics.StoreHeartBeatReportInterval) + tc.UpdateStorageReadBytes(3, 3.7*MB*statistics.StoreHeartBeatReportInterval) tc.UpdateStorageReadBytes(4, 6*MB*statistics.StoreHeartBeatReportInterval) tc.UpdateStorageReadBytes(5, 0) @@ -642,6 +642,7 @@ func (s *testHotReadRegionSchedulerSuite) TestWithPendingInfluence(c *C) { // For test hb.(*hotScheduler).conf.GreatDecRatio = 0.99 hb.(*hotScheduler).conf.MinorDecRatio = 1 + hb.(*hotScheduler).conf.DstToleranceRatio = 1 for i := 0; i < 2; i++ { // 0: byte rate