Skip to content

Commit

Permalink
This is an automated cherry-pick of tikv#6832
Browse files Browse the repository at this point in the history
close tikv#6833

Signed-off-by: ti-chi-bot <[email protected]>
  • Loading branch information
bufferflies authored and ti-chi-bot committed Jul 26, 2023
1 parent bd94a98 commit a8dea1a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 52 deletions.
3 changes: 3 additions & 0 deletions server/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -753,11 +753,14 @@ func (c *RaftCluster) HandleStoreHeartbeat(heartbeat *pdpb.StoreHeartbeatRequest
reportInterval := stats.GetInterval()
interval := reportInterval.GetEndTimestamp() - reportInterval.GetStartTimestamp()

<<<<<<< HEAD
// c.limiter is nil before "start" is called
if c.limiter != nil && c.opt.GetStoreLimitMode() == "auto" {
c.limiter.Collect(newStore.GetStoreStats())
}

=======
>>>>>>> 2c030264a (cluster: remove store limit collect logic (#6832))
regions := make(map[uint64]*core.RegionInfo, len(stats.GetPeerStats()))
for _, peerStat := range stats.GetPeerStats() {
regionID := peerStat.GetRegionId()
Expand Down
57 changes: 6 additions & 51 deletions server/cluster/store_limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@
package cluster

import (
<<<<<<< HEAD

Check failure on line 18 in server/cluster/store_limiter.go

View workflow job for this annotation

GitHub Actions / statics

expected 'STRING', found '<<'

Check failure on line 18 in server/cluster/store_limiter.go

View workflow job for this annotation

GitHub Actions / statics

expected 'STRING', found '<<'
"github.com/pingcap/kvproto/pkg/pdpb"
"github.com/pingcap/log"
"github.com/tikv/pd/pkg/syncutil"
"github.com/tikv/pd/server/config"
"github.com/tikv/pd/server/core/storelimit"
"go.uber.org/zap"
=======
"github.com/tikv/pd/pkg/core/storelimit"
"github.com/tikv/pd/pkg/utils/syncutil"
"github.com/tikv/pd/server/config"
>>>>>>> 2c030264a (cluster: remove store limit collect logic (#6832))
)

// StoreLimiter adjust the store limit dynamically
Expand All @@ -47,57 +53,6 @@ func NewStoreLimiter(opt *config.PersistOptions) *StoreLimiter {
}
}

// Collect the store statistics and update the cluster state
func (s *StoreLimiter) Collect(stats *pdpb.StoreStats) {
s.m.Lock()
defer s.m.Unlock()

log.Debug("collected statistics", zap.Reflect("stats", stats))
s.state.Collect((*StatEntry)(stats))

state := s.state.State()
ratePeerAdd := s.calculateRate(storelimit.AddPeer, state)
ratePeerRemove := s.calculateRate(storelimit.RemovePeer, state)

if ratePeerAdd > 0 || ratePeerRemove > 0 {
if ratePeerAdd > 0 {
s.opt.SetAllStoresLimit(storelimit.AddPeer, ratePeerAdd)
log.Info("change store region add limit for cluster", zap.Stringer("state", state), zap.Float64("rate", ratePeerAdd))
}
if ratePeerRemove > 0 {
s.opt.SetAllStoresLimit(storelimit.RemovePeer, ratePeerRemove)
log.Info("change store region remove limit for cluster", zap.Stringer("state", state), zap.Float64("rate", ratePeerRemove))
}
s.current = state
collectClusterStateCurrent(state)
}
}

func collectClusterStateCurrent(state LoadState) {
for i := LoadStateNone; i <= LoadStateHigh; i++ {
if i == state {
clusterStateCurrent.WithLabelValues(state.String()).Set(1)
continue
}
clusterStateCurrent.WithLabelValues(i.String()).Set(0)
}
}

func (s *StoreLimiter) calculateRate(limitType storelimit.Type, state LoadState) float64 {
rate := float64(0)
switch state {
case LoadStateIdle:
rate = float64(s.scene[limitType].Idle)
case LoadStateLow:
rate = float64(s.scene[limitType].Low)
case LoadStateNormal:
rate = float64(s.scene[limitType].Normal)
case LoadStateHigh:
rate = float64(s.scene[limitType].High)
}
return rate
}

// ReplaceStoreLimitScene replaces the store limit values for different scenes
func (s *StoreLimiter) ReplaceStoreLimitScene(scene *storelimit.Scene, limitType storelimit.Type) {
s.m.Lock()
Expand Down
4 changes: 3 additions & 1 deletion server/cluster/store_limiter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ package cluster
import (
"testing"

"github.com/pingcap/kvproto/pkg/pdpb"
"github.com/stretchr/testify/require"
"github.com/tikv/pd/server/config"
"github.com/tikv/pd/server/core/storelimit"
)

<<<<<<< HEAD
func TestCollect(t *testing.T) {
re := require.New(t)

Expand All @@ -32,6 +32,8 @@ func TestCollect(t *testing.T) {
re.Equal(int64(1), limiter.state.cst.total)
}

=======
>>>>>>> 2c030264a (cluster: remove store limit collect logic (#6832))
func TestStoreLimitScene(t *testing.T) {
re := require.New(t)

Expand Down

0 comments on commit a8dea1a

Please sign in to comment.