diff --git a/server/schedulers/balance_test.go b/server/schedulers/balance_test.go index 893a75734a5..6447643d28c 100644 --- a/server/schedulers/balance_test.go +++ b/server/schedulers/balance_test.go @@ -909,6 +909,9 @@ func (s *testBalanceHotWriteRegionSchedulerSuite) TestBalance(c *C) { opt.HotRegionScheduleLimit = mockoption.NewScheduleOptions().HotRegionScheduleLimit opt.RegionScheduleLimit = 0 c.Assert(hb.Schedule(tc), HasLen, 1) + // Always produce operator + c.Assert(hb.Schedule(tc), HasLen, 1) + c.Assert(hb.Schedule(tc), HasLen, 1) //| region_id | leader_store | follower_store | follower_store | written_bytes | //|-----------|--------------|----------------|----------------|---------------| diff --git a/server/schedulers/hot_region.go b/server/schedulers/hot_region.go index 44b57c4eb0b..2ad7002f8ff 100644 --- a/server/schedulers/hot_region.go +++ b/server/schedulers/hot_region.go @@ -128,20 +128,13 @@ func (h *balanceHotRegionsScheduler) IsScheduleAllowed(cluster schedule.Cluster) return h.allowBalanceLeader(cluster) || h.allowBalanceRegion(cluster) } -func min(a, b uint64) uint64 { - if a < b { - return a - } - return b -} - func (h *balanceHotRegionsScheduler) allowBalanceLeader(cluster schedule.Cluster) bool { - return h.opController.OperatorCount(schedule.OpHotRegion) < min(h.leaderLimit, cluster.GetHotRegionScheduleLimit()) && + return h.opController.OperatorCount(schedule.OpHotRegion) < minUint64(h.leaderLimit, cluster.GetHotRegionScheduleLimit()) && h.opController.OperatorCount(schedule.OpLeader) < cluster.GetLeaderScheduleLimit() } func (h *balanceHotRegionsScheduler) allowBalanceRegion(cluster schedule.Cluster) bool { - return h.opController.OperatorCount(schedule.OpHotRegion) < min(h.peerLimit, cluster.GetHotRegionScheduleLimit()) + return h.opController.OperatorCount(schedule.OpHotRegion) < minUint64(h.peerLimit, cluster.GetHotRegionScheduleLimit()) } func (h *balanceHotRegionsScheduler) Schedule(cluster schedule.Cluster) []*schedule.Operator { @@ -443,7 +436,8 @@ func (h *balanceHotRegionsScheduler) adjustBalanceLimit(storeID uint64, storesSt avgRegionCount := hotRegionTotalCount / float64(len(storesStat)) // Multiplied by hotRegionLimitFactor to avoid transfer back and forth - return uint64((float64(srcStoreStatistics.RegionsStat.Len()) - avgRegionCount) * hotRegionLimitFactor) + limit := uint64((float64(srcStoreStatistics.RegionsStat.Len()) - avgRegionCount) * hotRegionLimitFactor) + return maxUint64(limit, 1) } func (h *balanceHotRegionsScheduler) GetHotReadStatus() *statistics.StoreHotRegionInfos {