Skip to content

Commit

Permalink
do not balance the empty regions
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <rleungx@gmail.com>
  • Loading branch information
rleungx committed Jan 7, 2021
1 parent 1f6f41d commit 2438346
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
7 changes: 7 additions & 0 deletions server/schedulers/balance_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ func (s *balanceRegionScheduler) Schedule(cluster opt.Cluster) []*operator.Opera
}
log.Debug("select region", zap.String("scheduler", s.GetName()), zap.Uint64("region-id", region.GetID()))

// Skip the empty region
if region.GetApproximateSize() <= core.EmptyRegionApproximateSize {
log.Debug("region is empty", zap.String("scheduler", s.GetName()), zap.Uint64("region-id", region.GetID()))
schedulerCounter.WithLabelValues(s.GetName(), "empty-region").Inc()
continue
}

// Skip hot regions.
if cluster.IsRegionHot(region) {
log.Debug("region is hot", zap.String("scheduler", s.GetName()), zap.Uint64("region-id", region.GetID()))
Expand Down
31 changes: 31 additions & 0 deletions server/schedulers/balance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,37 @@ func (s *testBalanceRegionSchedulerSuite) TestShouldNotBalance(c *C) {
}
}

func (s *testBalanceRegionSchedulerSuite) TestEmptyRegion(c *C) {
opt := config.NewTestOptions()
tc := mockcluster.NewCluster(opt)
tc.DisableFeature(versioninfo.JointConsensus)
oc := schedule.NewOperatorController(s.ctx, nil, nil)
sb, err := schedule.CreateScheduler(BalanceRegionType, oc, core.NewStorage(kv.NewMemoryKV()), schedule.ConfigSliceDecoder(BalanceRegionType, []string{"", ""}))
c.Assert(err, IsNil)
tc.AddRegionStore(1, 10)
tc.AddRegionStore(2, 9)
tc.AddRegionStore(3, 10)
tc.AddRegionStore(4, 10)
region := core.NewRegionInfo(
&metapb.Region{
Id: 5,
StartKey: []byte("a"),
EndKey: []byte("b"),
Peers: []*metapb.Peer{
{Id: 6, StoreId: 1},
{Id: 7, StoreId: 3},
{Id: 8, StoreId: 4},
},
},
&metapb.Peer{Id: 7, StoreId: 3},
core.SetApproximateSize(1),
core.SetApproximateKeys(1),
)
tc.PutRegion(region)
operators := sb.Schedule(tc)
c.Assert(operators, IsNil)
}

var _ = Suite(&testRandomMergeSchedulerSuite{})

type testRandomMergeSchedulerSuite struct{}
Expand Down

0 comments on commit 2438346

Please sign in to comment.