Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the bug that PD might panic if there is down store with 10 minutes #3069

Merged
merged 4 commits into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pkg/mock/mockcluster/mockcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,3 +632,12 @@ func (mc *Cluster) SetStoreLabel(storeID uint64, labels map[string]string) {
newStore := store.Clone(core.SetStoreLabels(newLabels))
mc.PutStore(newStore)
}

// SetStoreLastHeartbeatInterval set the last heartbeat to the target store
func (mc *Cluster) SetStoreLastHeartbeatInterval(storeID uint64, interval time.Duration) {
store := mc.GetStore(storeID)
newStore := store.Clone(
core.SetStoreState(metapb.StoreState_Up),
core.SetLastHeartbeatTS(time.Now().Add(-interval)))
mc.PutStore(newStore)
}
27 changes: 27 additions & 0 deletions server/schedule/filter/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,33 @@ func (f *healthFilter) Target(opt opt.Options, store *core.StoreInfo) bool {
return f.filter(opt, store)
}

type connectedFilter struct{ scope string }

// NewConnectedFilter creates a Filter that filters all stores that are disconnected.
func NewConnectedFilter(scope string) Filter {
return &connectedFilter{scope: scope}
}

func (f *connectedFilter) Scope() string {
return f.scope
}

func (f *connectedFilter) Type() string {
return "connected-filter"
}

func (f *connectedFilter) filter(opt opt.Options, store *core.StoreInfo) bool {
return !store.IsDisconnected()
}

func (f *connectedFilter) Source(opt opt.Options, store *core.StoreInfo) bool {
return f.filter(opt, store)
}

func (f *connectedFilter) Target(opt opt.Options, store *core.StoreInfo) bool {
return f.filter(opt, store)
}

type pendingPeerCountFilter struct{ scope string }

// NewPendingPeerCountFilter creates a Filter that filters all stores that are
Expand Down
4 changes: 2 additions & 2 deletions server/schedulers/hot_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ func (bs *balanceSolver) filterDstStores() map[uint64]*storeLoadDetail {
filters = []filter.Filter{
filter.StoreStateFilter{ActionScope: bs.sche.GetName(), MoveRegion: true},
filter.NewExcludedFilter(bs.sche.GetName(), bs.cur.region.GetStoreIds(), bs.cur.region.GetStoreIds()),
filter.NewHealthFilter(bs.sche.GetName()),
filter.NewConnectedFilter(bs.sche.GetName()),
filter.NewSpecialUseFilter(bs.sche.GetName(), filter.SpecialUseHotRegion),
scoreGuard,
}
Expand All @@ -789,7 +789,7 @@ func (bs *balanceSolver) filterDstStores() map[uint64]*storeLoadDetail {
case transferLeader:
filters = []filter.Filter{
filter.StoreStateFilter{ActionScope: bs.sche.GetName(), TransferLeader: true},
filter.NewHealthFilter(bs.sche.GetName()),
filter.NewConnectedFilter(bs.sche.GetName()),
filter.NewSpecialUseFilter(bs.sche.GetName(), filter.SpecialUseHotRegion),
}

Expand Down
46 changes: 46 additions & 0 deletions server/schedulers/hot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,52 @@ func (s *testHotWriteRegionSchedulerSuite) TestWithKeyRate(c *C) {
}
}

func (s *testHotWriteRegionSchedulerSuite) TestUnhealthyStore(c *C) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
statistics.Denoising = false
opt := mockoption.NewScheduleOptions()
hb, err := schedule.CreateScheduler(HotWriteRegionType, schedule.NewOperatorController(ctx, nil, nil), core.NewStorage(kv.NewMemoryKV()), nil)
c.Assert(err, IsNil)
hb.(*hotScheduler).conf.SetDstToleranceRatio(1)
hb.(*hotScheduler).conf.SetSrcToleranceRatio(1)
opt.HotRegionCacheHitsThreshold = 0

tc := mockcluster.NewCluster(opt)
tc.AddRegionStore(1, 20)
tc.AddRegionStore(2, 20)
tc.AddRegionStore(3, 20)
tc.AddRegionStore(4, 20)

tc.UpdateStorageWrittenStats(1, 10.5*MB*statistics.StoreHeartBeatReportInterval, 10.5*MB*statistics.StoreHeartBeatReportInterval)
tc.UpdateStorageWrittenStats(2, 10*MB*statistics.StoreHeartBeatReportInterval, 10*MB*statistics.StoreHeartBeatReportInterval)
tc.UpdateStorageWrittenStats(3, 9.5*MB*statistics.StoreHeartBeatReportInterval, 9.5*MB*statistics.StoreHeartBeatReportInterval)
tc.UpdateStorageWrittenStats(4, 0*MB*statistics.StoreHeartBeatReportInterval, 0*MB*statistics.StoreHeartBeatReportInterval)
addRegionInfo(tc, write, []testRegionInfo{
{1, []uint64{1, 2, 3}, 0.5 * MB, 0.5 * MB},
{2, []uint64{2, 1, 3}, 0.5 * MB, 0.5 * MB},
{3, []uint64{3, 2, 1}, 0.5 * MB, 0.5 * MB},
})

intervals := []time.Duration{
9 * time.Second,
10 * time.Second,
19 * time.Second,
20 * time.Second,
9 * time.Minute,
10 * time.Minute,
29 * time.Minute,
30 * time.Minute,
}
// test dst
for _, interval := range intervals {
tc.SetStoreLastHeartbeatInterval(4, interval)
hb.(*hotScheduler).clearPendingInfluence()
hb.Schedule(tc)
// no panic
}
}

func (s *testHotWriteRegionSchedulerSuite) TestLeader(c *C) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down