From 49fa8fd504bef24f9b2114663c96500f1cd4bf64 Mon Sep 17 00:00:00 2001 From: Song Gao Date: Wed, 16 Sep 2020 15:42:28 +0800 Subject: [PATCH 1/7] add verify Signed-off-by: Song Gao --- server/schedule/filter/filters.go | 11 +++++++---- server/schedulers/balance_region.go | 5 +++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/server/schedule/filter/filters.go b/server/schedule/filter/filters.go index 06fa404e10e..01975633525 100644 --- a/server/schedule/filter/filters.go +++ b/server/schedule/filter/filters.go @@ -683,10 +683,13 @@ func (f *isolationFilter) Target(opt *config.PersistOptions, store *core.StoreIn // FitRegion in filter func createRegionForRuleFit(startKey, endKey []byte, peers []*metapb.Peer, leader *metapb.Peer, opts ...core.RegionCreateOption) *core.RegionInfo { - copyLeader := &metapb.Peer{ - Id: leader.Id, - StoreId: leader.StoreId, - Role: leader.Role, + copyLeader := &metapb.Peer{} + if leader != nil { + copyLeader = &metapb.Peer{ + Id: leader.Id, + StoreId: leader.StoreId, + Role: leader.Role, + } } copyPeers := make([]*metapb.Peer, 0, len(peers)) for _, p := range peers { diff --git a/server/schedulers/balance_region.go b/server/schedulers/balance_region.go index ace2c99f1cd..b6efa5bda33 100644 --- a/server/schedulers/balance_region.go +++ b/server/schedulers/balance_region.go @@ -173,6 +173,11 @@ func (s *balanceRegionScheduler) Schedule(cluster opt.Cluster) []*operator.Opera schedulerCounter.WithLabelValues(s.GetName(), "region-hot").Inc() continue } + // Check region whether have leader + if region.GetLeader() == nil { + log.Debug("region have no leader", zap.String("scheduler", s.GetName()), zap.Uint64("region-id", region.GetID())) + continue + } oldPeer := region.GetStorePeer(sourceID) if op := s.transferPeer(cluster, region, oldPeer); op != nil { From 01eef634e5c55712858f194b6d619d4816d76141 Mon Sep 17 00:00:00 2001 From: Song Gao Date: Wed, 16 Sep 2020 16:37:27 +0800 Subject: [PATCH 2/7] add test cases Signed-off-by: Song Gao --- pkg/mock/mockcluster/mockcluster.go | 20 +++++++++++++++----- pkg/pointer/point.go | 18 ++++++++++++++++++ server/schedule/operator_controller_test.go | 9 +++++---- server/schedulers/balance_test.go | 17 +++++++++++++++++ 4 files changed, 55 insertions(+), 9 deletions(-) create mode 100644 pkg/pointer/point.go diff --git a/pkg/mock/mockcluster/mockcluster.go b/pkg/mock/mockcluster/mockcluster.go index deb019fdca1..840daf26c6e 100644 --- a/pkg/mock/mockcluster/mockcluster.go +++ b/pkg/mock/mockcluster/mockcluster.go @@ -245,6 +245,11 @@ func (mc *Cluster) AddRegionStore(storeID uint64, regionCount int) { mc.PutStore(store) } +// AddRegionInfo supports add regionInfo directly +func (mc *Cluster) AddRegionInfo(regionInfo *core.RegionInfo) { + mc.PutRegion(regionInfo) +} + // AddRegionStoreWithLeader adds store with specified count of region and leader. func (mc *Cluster) AddRegionStoreWithLeader(storeID uint64, regionCount int, leaderCounts ...int) { leaderCount := regionCount @@ -292,7 +297,7 @@ func (mc *Cluster) AddLeaderRegion(regionID uint64, leaderStoreID uint64, follow // AddRegionWithLearner adds region with specified leader, followers and learners. func (mc *Cluster) AddRegionWithLearner(regionID uint64, leaderStoreID uint64, followerStoreIDs, learnerStoreIDs []uint64) *core.RegionInfo { - origin := mc.MockRegionInfo(regionID, leaderStoreID, followerStoreIDs, learnerStoreIDs, nil) + origin := mc.MockRegionInfo(regionID, &leaderStoreID, followerStoreIDs, learnerStoreIDs, nil) region := origin.Clone(core.SetApproximateSize(10), core.SetApproximateKeys(10)) mc.PutRegion(region) return region @@ -535,7 +540,7 @@ func (mc *Cluster) UpdateStoreStatus(id uint64) { } func (mc *Cluster) newMockRegionInfo(regionID uint64, leaderStoreID uint64, followerStoreIDs ...uint64) *core.RegionInfo { - return mc.MockRegionInfo(regionID, leaderStoreID, followerStoreIDs, []uint64{}, nil) + return mc.MockRegionInfo(regionID, &leaderStoreID, followerStoreIDs, []uint64{}, nil) } // CheckLabelProperty checks label property. @@ -574,7 +579,8 @@ func (mc *Cluster) RemoveScheduler(name string) error { } // MockRegionInfo returns a mock region -func (mc *Cluster) MockRegionInfo(regionID uint64, leaderStoreID uint64, +// If leaderStoreID is undefined, the regions would have no leader +func (mc *Cluster) MockRegionInfo(regionID uint64, leaderStoreID *uint64, followerStoreIDs, learnerStoreIDs []uint64, epoch *metapb.RegionEpoch) *core.RegionInfo { region := &metapb.Region{ @@ -583,8 +589,12 @@ func (mc *Cluster) MockRegionInfo(regionID uint64, leaderStoreID uint64, EndKey: []byte(fmt.Sprintf("%20d", regionID+1)), RegionEpoch: epoch, } - leader, _ := mc.AllocPeer(leaderStoreID) - region.Peers = []*metapb.Peer{leader} + region.Peers = []*metapb.Peer{} + var leader *metapb.Peer + if leaderStoreID != nil { + leader, _ = mc.AllocPeer(*leaderStoreID) + region.Peers = append(region.Peers, leader) + } for _, storeID := range followerStoreIDs { peer, _ := mc.AllocPeer(storeID) region.Peers = append(region.Peers, peer) diff --git a/pkg/pointer/point.go b/pkg/pointer/point.go new file mode 100644 index 00000000000..3ea9be62faf --- /dev/null +++ b/pkg/pointer/point.go @@ -0,0 +1,18 @@ +// Copyright 2020 TiKV Project Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// See the License for the specific language governing permissions and +// limitations under the License. + +package pointer + +func UInt64Ptr(value uint64) *uint64 { + return &value +} diff --git a/server/schedule/operator_controller_test.go b/server/schedule/operator_controller_test.go index 85c5e8187e9..da3f5a36f92 100644 --- a/server/schedule/operator_controller_test.go +++ b/server/schedule/operator_controller_test.go @@ -26,6 +26,7 @@ import ( "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/tikv/pd/pkg/mock/mockcluster" + "github.com/tikv/pd/pkg/pointer" "github.com/tikv/pd/server/config" "github.com/tikv/pd/server/core" "github.com/tikv/pd/server/core/storelimit" @@ -428,7 +429,7 @@ func (t *testOperatorControllerSuite) TestDispatchOutdatedRegion(c *C) { c.Assert(stream.MsgLength(), Equals, 1) // report the result of transferring leader - region := cluster.MockRegionInfo(1, 2, []uint64{1, 2}, []uint64{}, + region := cluster.MockRegionInfo(1, pointer.UInt64Ptr(2), []uint64{1, 2}, []uint64{}, &metapb.RegionEpoch{ConfVer: 0, Version: 0}) controller.Dispatch(region, DispatchFromHeartBeat) @@ -436,7 +437,7 @@ func (t *testOperatorControllerSuite) TestDispatchOutdatedRegion(c *C) { c.Assert(stream.MsgLength(), Equals, 2) // report the result of removing peer - region = cluster.MockRegionInfo(1, 2, []uint64{2}, []uint64{}, + region = cluster.MockRegionInfo(1, pointer.UInt64Ptr(2), []uint64{2}, []uint64{}, &metapb.RegionEpoch{ConfVer: 0, Version: 0}) controller.Dispatch(region, DispatchFromHeartBeat) @@ -452,7 +453,7 @@ func (t *testOperatorControllerSuite) TestDispatchOutdatedRegion(c *C) { c.Assert(stream.MsgLength(), Equals, 3) // report region with an abnormal confver - region = cluster.MockRegionInfo(1, 1, []uint64{1, 2}, []uint64{}, + region = cluster.MockRegionInfo(1, pointer.UInt64Ptr(1), []uint64{1, 2}, []uint64{}, &metapb.RegionEpoch{ConfVer: 1, Version: 0}) controller.Dispatch(region, DispatchFromHeartBeat) c.Assert(op.ConfVerChanged(region), Equals, uint64(0)) @@ -470,7 +471,7 @@ func (t *testOperatorControllerSuite) TestDispatchUnfinishedStep(c *C) { // so the two peers are {peerid: 1, storeid: 1}, {peerid: 2, storeid: 2} // The peer on store 1 is the leader epoch := &metapb.RegionEpoch{ConfVer: 0, Version: 0} - region := cluster.MockRegionInfo(1, 1, []uint64{2}, []uint64{}, epoch) + region := cluster.MockRegionInfo(1, pointer.UInt64Ptr(1), []uint64{2}, []uint64{}, epoch) // Put region into cluster, otherwise, AddOperator will fail because of // missing region cluster.PutRegion(region) diff --git a/server/schedulers/balance_test.go b/server/schedulers/balance_test.go index caa61245e1b..dbded853ff3 100644 --- a/server/schedulers/balance_test.go +++ b/server/schedulers/balance_test.go @@ -899,6 +899,23 @@ func (s *testBalanceRegionSchedulerSuite) checkReplacePendingRegion(c *C, tc *mo testutil.CheckTransferPeer(c, sb.Schedule(tc)[0], operator.OpKind(0), 1, 4) } +func (s *testBalanceRegionSchedulerSuite) TestShouldNotBalance(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) + region := tc.MockRegionInfo(1, nil, []uint64{2, 3, 4}, nil, nil) + tc.AddRegionInfo(region) + operators := sb.Schedule(tc) + if operators != nil { + c.Assert(len(operators), Equals, 0) + } else { + c.Assert(operators, IsNil) + } +} + var _ = Suite(&testRandomMergeSchedulerSuite{}) type testRandomMergeSchedulerSuite struct{} From 58cfabac5d25a9e0dd28407a3d7062f3a1570e3a Mon Sep 17 00:00:00 2001 From: Song Gao Date: Wed, 16 Sep 2020 17:00:27 +0800 Subject: [PATCH 3/7] address the comment Signed-off-by: Song Gao --- server/schedule/filter/filters.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/server/schedule/filter/filters.go b/server/schedule/filter/filters.go index 01975633525..7ae154b3ee9 100644 --- a/server/schedule/filter/filters.go +++ b/server/schedule/filter/filters.go @@ -16,6 +16,7 @@ package filter import ( "fmt" + "github.com/golang/protobuf/proto" "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/log" "github.com/tikv/pd/pkg/slice" @@ -683,14 +684,7 @@ func (f *isolationFilter) Target(opt *config.PersistOptions, store *core.StoreIn // FitRegion in filter func createRegionForRuleFit(startKey, endKey []byte, peers []*metapb.Peer, leader *metapb.Peer, opts ...core.RegionCreateOption) *core.RegionInfo { - copyLeader := &metapb.Peer{} - if leader != nil { - copyLeader = &metapb.Peer{ - Id: leader.Id, - StoreId: leader.StoreId, - Role: leader.Role, - } - } + copyLeader := proto.Clone(leader).(*metapb.Peer) copyPeers := make([]*metapb.Peer, 0, len(peers)) for _, p := range peers { peer := &metapb.Peer{ From 48225f53206d1a03103d3468becd932e0937885f Mon Sep 17 00:00:00 2001 From: Song Gao Date: Wed, 16 Sep 2020 17:11:23 +0800 Subject: [PATCH 4/7] address the comment Signed-off-by: Song Gao --- pkg/pointer/{point.go => pointer.go} | 1 + server/schedulers/balance_region.go | 1 + 2 files changed, 2 insertions(+) rename pkg/pointer/{point.go => pointer.go} (91%) diff --git a/pkg/pointer/point.go b/pkg/pointer/pointer.go similarity index 91% rename from pkg/pointer/point.go rename to pkg/pointer/pointer.go index 3ea9be62faf..6cb5611fcfe 100644 --- a/pkg/pointer/point.go +++ b/pkg/pointer/pointer.go @@ -13,6 +13,7 @@ package pointer +// UInt64Ptr return the pointer for the given value func UInt64Ptr(value uint64) *uint64 { return &value } diff --git a/server/schedulers/balance_region.go b/server/schedulers/balance_region.go index b6efa5bda33..e885b2c03f9 100644 --- a/server/schedulers/balance_region.go +++ b/server/schedulers/balance_region.go @@ -176,6 +176,7 @@ func (s *balanceRegionScheduler) Schedule(cluster opt.Cluster) []*operator.Opera // Check region whether have leader if region.GetLeader() == nil { log.Debug("region have no leader", zap.String("scheduler", s.GetName()), zap.Uint64("region-id", region.GetID())) + schedulerCounter.WithLabelValues(s.GetName(), "no-leader").Inc() continue } From 85c892d2a15ce840b06ca149c04879599d9652e3 Mon Sep 17 00:00:00 2001 From: Song Gao Date: Thu, 17 Sep 2020 12:57:26 +0800 Subject: [PATCH 5/7] address the comment Signed-off-by: Song Gao --- pkg/mock/mockcluster/mockcluster.go | 15 +++++---------- pkg/pointer/pointer.go | 19 ------------------- server/schedule/operator_controller_test.go | 9 ++++----- server/schedulers/balance_test.go | 4 ++-- 4 files changed, 11 insertions(+), 36 deletions(-) delete mode 100644 pkg/pointer/pointer.go diff --git a/pkg/mock/mockcluster/mockcluster.go b/pkg/mock/mockcluster/mockcluster.go index 840daf26c6e..d1793df794d 100644 --- a/pkg/mock/mockcluster/mockcluster.go +++ b/pkg/mock/mockcluster/mockcluster.go @@ -245,11 +245,6 @@ func (mc *Cluster) AddRegionStore(storeID uint64, regionCount int) { mc.PutStore(store) } -// AddRegionInfo supports add regionInfo directly -func (mc *Cluster) AddRegionInfo(regionInfo *core.RegionInfo) { - mc.PutRegion(regionInfo) -} - // AddRegionStoreWithLeader adds store with specified count of region and leader. func (mc *Cluster) AddRegionStoreWithLeader(storeID uint64, regionCount int, leaderCounts ...int) { leaderCount := regionCount @@ -297,7 +292,7 @@ func (mc *Cluster) AddLeaderRegion(regionID uint64, leaderStoreID uint64, follow // AddRegionWithLearner adds region with specified leader, followers and learners. func (mc *Cluster) AddRegionWithLearner(regionID uint64, leaderStoreID uint64, followerStoreIDs, learnerStoreIDs []uint64) *core.RegionInfo { - origin := mc.MockRegionInfo(regionID, &leaderStoreID, followerStoreIDs, learnerStoreIDs, nil) + origin := mc.MockRegionInfo(regionID, leaderStoreID, followerStoreIDs, learnerStoreIDs, nil) region := origin.Clone(core.SetApproximateSize(10), core.SetApproximateKeys(10)) mc.PutRegion(region) return region @@ -540,7 +535,7 @@ func (mc *Cluster) UpdateStoreStatus(id uint64) { } func (mc *Cluster) newMockRegionInfo(regionID uint64, leaderStoreID uint64, followerStoreIDs ...uint64) *core.RegionInfo { - return mc.MockRegionInfo(regionID, &leaderStoreID, followerStoreIDs, []uint64{}, nil) + return mc.MockRegionInfo(regionID, leaderStoreID, followerStoreIDs, []uint64{}, nil) } // CheckLabelProperty checks label property. @@ -580,7 +575,7 @@ func (mc *Cluster) RemoveScheduler(name string) error { // MockRegionInfo returns a mock region // If leaderStoreID is undefined, the regions would have no leader -func (mc *Cluster) MockRegionInfo(regionID uint64, leaderStoreID *uint64, +func (mc *Cluster) MockRegionInfo(regionID uint64, leaderStoreID uint64, followerStoreIDs, learnerStoreIDs []uint64, epoch *metapb.RegionEpoch) *core.RegionInfo { region := &metapb.Region{ @@ -591,8 +586,8 @@ func (mc *Cluster) MockRegionInfo(regionID uint64, leaderStoreID *uint64, } region.Peers = []*metapb.Peer{} var leader *metapb.Peer - if leaderStoreID != nil { - leader, _ = mc.AllocPeer(*leaderStoreID) + if leaderStoreID != 0 { + leader, _ = mc.AllocPeer(leaderStoreID) region.Peers = append(region.Peers, leader) } for _, storeID := range followerStoreIDs { diff --git a/pkg/pointer/pointer.go b/pkg/pointer/pointer.go deleted file mode 100644 index 6cb5611fcfe..00000000000 --- a/pkg/pointer/pointer.go +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2020 TiKV Project Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// See the License for the specific language governing permissions and -// limitations under the License. - -package pointer - -// UInt64Ptr return the pointer for the given value -func UInt64Ptr(value uint64) *uint64 { - return &value -} diff --git a/server/schedule/operator_controller_test.go b/server/schedule/operator_controller_test.go index da3f5a36f92..85c5e8187e9 100644 --- a/server/schedule/operator_controller_test.go +++ b/server/schedule/operator_controller_test.go @@ -26,7 +26,6 @@ import ( "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/tikv/pd/pkg/mock/mockcluster" - "github.com/tikv/pd/pkg/pointer" "github.com/tikv/pd/server/config" "github.com/tikv/pd/server/core" "github.com/tikv/pd/server/core/storelimit" @@ -429,7 +428,7 @@ func (t *testOperatorControllerSuite) TestDispatchOutdatedRegion(c *C) { c.Assert(stream.MsgLength(), Equals, 1) // report the result of transferring leader - region := cluster.MockRegionInfo(1, pointer.UInt64Ptr(2), []uint64{1, 2}, []uint64{}, + region := cluster.MockRegionInfo(1, 2, []uint64{1, 2}, []uint64{}, &metapb.RegionEpoch{ConfVer: 0, Version: 0}) controller.Dispatch(region, DispatchFromHeartBeat) @@ -437,7 +436,7 @@ func (t *testOperatorControllerSuite) TestDispatchOutdatedRegion(c *C) { c.Assert(stream.MsgLength(), Equals, 2) // report the result of removing peer - region = cluster.MockRegionInfo(1, pointer.UInt64Ptr(2), []uint64{2}, []uint64{}, + region = cluster.MockRegionInfo(1, 2, []uint64{2}, []uint64{}, &metapb.RegionEpoch{ConfVer: 0, Version: 0}) controller.Dispatch(region, DispatchFromHeartBeat) @@ -453,7 +452,7 @@ func (t *testOperatorControllerSuite) TestDispatchOutdatedRegion(c *C) { c.Assert(stream.MsgLength(), Equals, 3) // report region with an abnormal confver - region = cluster.MockRegionInfo(1, pointer.UInt64Ptr(1), []uint64{1, 2}, []uint64{}, + region = cluster.MockRegionInfo(1, 1, []uint64{1, 2}, []uint64{}, &metapb.RegionEpoch{ConfVer: 1, Version: 0}) controller.Dispatch(region, DispatchFromHeartBeat) c.Assert(op.ConfVerChanged(region), Equals, uint64(0)) @@ -471,7 +470,7 @@ func (t *testOperatorControllerSuite) TestDispatchUnfinishedStep(c *C) { // so the two peers are {peerid: 1, storeid: 1}, {peerid: 2, storeid: 2} // The peer on store 1 is the leader epoch := &metapb.RegionEpoch{ConfVer: 0, Version: 0} - region := cluster.MockRegionInfo(1, pointer.UInt64Ptr(1), []uint64{2}, []uint64{}, epoch) + region := cluster.MockRegionInfo(1, 1, []uint64{2}, []uint64{}, epoch) // Put region into cluster, otherwise, AddOperator will fail because of // missing region cluster.PutRegion(region) diff --git a/server/schedulers/balance_test.go b/server/schedulers/balance_test.go index dbded853ff3..2179caf3ac7 100644 --- a/server/schedulers/balance_test.go +++ b/server/schedulers/balance_test.go @@ -906,8 +906,8 @@ func (s *testBalanceRegionSchedulerSuite) TestShouldNotBalance(c *C) { 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) - region := tc.MockRegionInfo(1, nil, []uint64{2, 3, 4}, nil, nil) - tc.AddRegionInfo(region) + region := tc.MockRegionInfo(1, 0, []uint64{2, 3, 4}, nil, nil) + tc.PutRegion(region) operators := sb.Schedule(tc) if operators != nil { c.Assert(len(operators), Equals, 0) From accdec8efc1a092f52f6a03825c0a2c898fdd262 Mon Sep 17 00:00:00 2001 From: Song Gao Date: Thu, 17 Sep 2020 12:58:38 +0800 Subject: [PATCH 6/7] fix comment Signed-off-by: Song Gao --- pkg/mock/mockcluster/mockcluster.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/mock/mockcluster/mockcluster.go b/pkg/mock/mockcluster/mockcluster.go index d1793df794d..8812cff484a 100644 --- a/pkg/mock/mockcluster/mockcluster.go +++ b/pkg/mock/mockcluster/mockcluster.go @@ -574,7 +574,7 @@ func (mc *Cluster) RemoveScheduler(name string) error { } // MockRegionInfo returns a mock region -// If leaderStoreID is undefined, the regions would have no leader +// If leaderStoreID is zero, the regions would have no leader func (mc *Cluster) MockRegionInfo(regionID uint64, leaderStoreID uint64, followerStoreIDs, learnerStoreIDs []uint64, epoch *metapb.RegionEpoch) *core.RegionInfo { From 373b6dc088ad9ed80cd1bf16091c0e2d8c97f074 Mon Sep 17 00:00:00 2001 From: Song Gao Date: Fri, 18 Sep 2020 15:57:20 +0800 Subject: [PATCH 7/7] address the comment Signed-off-by: Song Gao --- pkg/mock/mockcluster/mockcluster.go | 1 - server/schedulers/balance_region.go | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/mock/mockcluster/mockcluster.go b/pkg/mock/mockcluster/mockcluster.go index 8812cff484a..937eeb3b333 100644 --- a/pkg/mock/mockcluster/mockcluster.go +++ b/pkg/mock/mockcluster/mockcluster.go @@ -584,7 +584,6 @@ func (mc *Cluster) MockRegionInfo(regionID uint64, leaderStoreID uint64, EndKey: []byte(fmt.Sprintf("%20d", regionID+1)), RegionEpoch: epoch, } - region.Peers = []*metapb.Peer{} var leader *metapb.Peer if leaderStoreID != 0 { leader, _ = mc.AllocPeer(leaderStoreID) diff --git a/server/schedulers/balance_region.go b/server/schedulers/balance_region.go index e885b2c03f9..fffb932facb 100644 --- a/server/schedulers/balance_region.go +++ b/server/schedulers/balance_region.go @@ -175,7 +175,7 @@ func (s *balanceRegionScheduler) Schedule(cluster opt.Cluster) []*operator.Opera } // Check region whether have leader if region.GetLeader() == nil { - log.Debug("region have no leader", zap.String("scheduler", s.GetName()), zap.Uint64("region-id", region.GetID())) + log.Warn("region have no leader", zap.String("scheduler", s.GetName()), zap.Uint64("region-id", region.GetID())) schedulerCounter.WithLabelValues(s.GetName(), "no-leader").Inc() continue }