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

scheduler: filter unhealthy store in summaryStoresLoad (#2737) #2805

Merged
merged 3 commits into from
Aug 21, 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
2 changes: 2 additions & 0 deletions server/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ func (c *RaftCluster) HandleStoreHeartbeat(stats *pdpb.StoreStats) error {
c.storesStats.Observe(newStore.GetID(), newStore.GetStoreStats())
c.storesStats.UpdateTotalBytesRate(c.core.GetStores)
c.storesStats.UpdateTotalKeysRate(c.core.GetStores)
c.storesStats.FilterUnhealthyStore(c)

// c.limiter is nil before "start" is called
if c.limiter != nil && c.opt.GetStoreLimitMode() == "auto" {
Expand Down Expand Up @@ -821,6 +822,7 @@ func (c *RaftCluster) GetRegionStats(startKey, endKey []byte) *statistics.Region
}

// GetStoresStats returns stores' statistics from cluster.
// And it will be unnecessary to filter unhealthy store, because it has been solved in process heartbeat
func (c *RaftCluster) GetStoresStats() *statistics.StoresStats {
c.RLock()
defer c.RUnlock()
Expand Down
32 changes: 32 additions & 0 deletions server/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,38 @@ func (s *testClusterInfoSuite) TestStoreHeartbeat(c *C) {
}
}

func (s *testClusterInfoSuite) TestFilterUnhealthyStore(c *C) {
_, opt, err := newTestScheduleConfig()
c.Assert(err, IsNil)
cluster := newTestRaftCluster(mockid.NewIDAllocator(), opt, core.NewStorage(kv.NewMemoryKV()), core.NewBasicCluster())

stores := newTestStores(3)
for _, store := range stores {
storeStats := &pdpb.StoreStats{
StoreId: store.GetID(),
Capacity: 100,
Available: 50,
RegionCount: 1,
}
c.Assert(cluster.putStoreLocked(store), IsNil)
c.Assert(cluster.HandleStoreHeartbeat(storeStats), IsNil)
c.Assert(cluster.storesStats.GetRollingStoreStats(store.GetID()), NotNil)
}

for _, store := range stores {
storeStats := &pdpb.StoreStats{
StoreId: store.GetID(),
Capacity: 100,
Available: 50,
RegionCount: 1,
}
newStore := store.Clone(core.SetStoreState(metapb.StoreState_Tombstone))
c.Assert(cluster.putStoreLocked(newStore), IsNil)
c.Assert(cluster.HandleStoreHeartbeat(storeStats), IsNil)
c.Assert(cluster.storesStats.GetRollingStoreStats(store.GetID()), IsNil)
}
}

func (s *testClusterInfoSuite) TestRegionHeartbeat(c *C) {
_, opt, err := newTestScheduleConfig()
c.Assert(err, IsNil)
Expand Down
16 changes: 1 addition & 15 deletions server/schedulers/hot_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,7 @@ func (bs *balanceSolver) init() {
case readLeader:
bs.stLoadDetail = bs.sche.stLoadInfos[readLeader]
}
for _, id := range getUnhealthyStores(bs.cluster) {
delete(bs.stLoadDetail, id)
}
// And it will be unnecessary to filter unhealthy store, because it has been solved in process heartbeat

bs.maxSrc = &storeLoad{}
bs.minDst = &storeLoad{
Expand All @@ -542,18 +540,6 @@ func (bs *balanceSolver) init() {
}
}

func getUnhealthyStores(cluster opt.Cluster) []uint64 {
ret := make([]uint64, 0)
stores := cluster.GetStores()
for _, store := range stores {
if store.IsTombstone() ||
store.DownTime() > cluster.GetMaxStoreDownTime() {
ret = append(ret, store.GetID())
}
}
return ret
}

func newBalanceSolver(sche *hotScheduler, cluster opt.Cluster, rwTy rwType, opTy opType) *balanceSolver {
solver := &balanceSolver{
sche: sche,
Expand Down
16 changes: 16 additions & 0 deletions server/statistics/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,22 @@ func (s *StoresStats) GetStoresKeysReadStat() map[uint64]float64 {
return res
}

func (s *StoresStats) storeIsUnhealthy(cluster core.StoreSetInformer, storeID uint64) bool {
store := cluster.GetStore(storeID)
return store.IsTombstone() || store.IsUnhealth()
}

// FilterUnhealthyStore filter unhealthy store
func (s *StoresStats) FilterUnhealthyStore(cluster core.StoreSetInformer) {
s.Lock()
defer s.Unlock()
for storeID := range s.rollingStoresStats {
if s.storeIsUnhealthy(cluster, storeID) {
delete(s.rollingStoresStats, storeID)
}
}
}

// RollingStoreStats are multiple sets of recent historical records with specified windows size.
type RollingStoreStats struct {
sync.RWMutex
Expand Down
4 changes: 4 additions & 0 deletions server/statistics/store_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ func (s *storeStatistics) Observe(store *core.StoreInfo, stats *StoresStats) {

// Store flows.
storeFlowStats := stats.GetRollingStoreStats(store.GetID())
if storeFlowStats == nil {
return
}

storeWriteRateByte, storeReadRateByte := storeFlowStats.GetBytesRate()
storeStatusGauge.WithLabelValues(storeAddress, id, "store_write_rate_bytes").Set(storeWriteRateByte)
storeStatusGauge.WithLabelValues(storeAddress, id, "store_read_rate_bytes").Set(storeReadRateByte)
Expand Down