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

schedule: adjust store balance rate meaning #1591

Merged
merged 1 commit into from
Jun 20, 2019
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
4 changes: 2 additions & 2 deletions conf/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ max-snapshot-count = 3
max-pending-peer-count = 16
max-store-down-time = "30m"
leader-schedule-limit = 4
region-schedule-limit = 1024
replica-schedule-limit = 1024
region-schedule-limit = 64
replica-schedule-limit = 64
merge-schedule-limit = 8
tolerant-size-ratio = 0
# Enable two-way merge, set it to true may help improving merge speed.
Expand Down
5 changes: 3 additions & 2 deletions server/api/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/pingcap/pd/pkg/typeutil"
"github.com/pingcap/pd/server"
"github.com/pingcap/pd/server/core"
"github.com/pingcap/pd/server/schedule"
"github.com/pkg/errors"
"github.com/unrolled/render"
)
Expand Down Expand Up @@ -328,7 +329,7 @@ func (h *storeHandler) SetLimit(w http.ResponseWriter, r *http.Request) {
return
}

if err := h.SetStoreLimit(storeID, rate); err != nil {
if err := h.SetStoreLimit(storeID, rate/schedule.StoreBalanceBaseTime); err != nil {
h.rd.JSON(w, http.StatusInternalServerError, err.Error())
return
}
Expand Down Expand Up @@ -381,7 +382,7 @@ func (h *storesHandler) SetAllLimit(w http.ResponseWriter, r *http.Request) {
return
}

if err := h.SetAllStoresLimit(rate); err != nil {
if err := h.SetAllStoresLimit(rate / schedule.StoreBalanceBaseTime); err != nil {
h.rd.JSON(w, http.StatusInternalServerError, err.Error())
return
}
Expand Down
4 changes: 2 additions & 2 deletions server/api/trend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var _ = Suite(&testTrendSuite{})
type testTrendSuite struct{}

func (s *testTrendSuite) TestTrend(c *C) {
svr, cleanup := mustNewServer(c)
svr, cleanup := mustNewServer(c, func(cfg *server.Config) { cfg.Schedule.StoreBalanceRate = 60 })
defer cleanup()
mustWaitLeader(c, []*server.Server{svr})

Expand All @@ -49,7 +49,7 @@ func (s *testTrendSuite) TestTrend(c *C) {
// Create 3 operators that transfers leader, moves follower, moves leader.
c.Assert(svr.GetHandler().AddTransferLeaderOperator(4, 2), IsNil)
c.Assert(svr.GetHandler().AddTransferPeerOperator(5, 2, 3), IsNil)
time.Sleep(2 * time.Second)
time.Sleep(1 * time.Second)
c.Assert(svr.GetHandler().AddTransferPeerOperator(6, 1, 3), IsNil)

// Complete the operators.
Expand Down
6 changes: 3 additions & 3 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,11 +568,11 @@ const (
defaultPatrolRegionInterval = 100 * time.Millisecond
defaultMaxStoreDownTime = 30 * time.Minute
defaultLeaderScheduleLimit = 8
defaultRegionScheduleLimit = 1024
defaultReplicaScheduleLimit = 1024
defaultRegionScheduleLimit = 64
defaultReplicaScheduleLimit = 64
defaultMergeScheduleLimit = 8
defaultHotRegionScheduleLimit = 2
defaultStoreBalanceRate = 1
defaultStoreBalanceRate = 15
defaultTolerantSizeRatio = 0
defaultLowSpaceRatio = 0.8
defaultHighSpaceRatio = 0.6
Expand Down
1 change: 1 addition & 0 deletions server/coordinator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func newTestOperator(regionID uint64, regionEpoch *metapb.RegionEpoch, kind sche
func newTestScheduleConfig() (*ScheduleConfig, *scheduleOption, error) {
cfg := NewConfig()
cfg.Schedule.TolerantSizeRatio = 5
cfg.Schedule.StoreBalanceRate = 60
if err := cfg.Adjust(nil); err != nil {
return nil, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion server/schedule/mockcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ const (
defaultReplicaScheduleLimit = 8
defaultMergeScheduleLimit = 8
defaultHotRegionScheduleLimit = 2
defaultStoreBalanceRate = 1
defaultStoreBalanceRate = 60
defaultTolerantSizeRatio = 2.5
defaultLowSpaceRatio = 0.8
defaultHighSpaceRatio = 0.6
Expand Down
4 changes: 3 additions & 1 deletion server/schedule/operator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ var (
fastNotifyInterval = 2 * time.Second
// PushOperatorTickInterval is the interval try to push the operator.
PushOperatorTickInterval = 500 * time.Millisecond
// StoreBalanceBaseTime represents the base time of balance rate.
StoreBalanceBaseTime float64 = 60
)

// HeartbeatStreams is an interface of async region heartbeat.
Expand Down Expand Up @@ -660,7 +662,7 @@ func (oc *OperatorController) newStoreLimit(storeID uint64, rate float64) {
// getOrCreateStoreLimit is used to get or create the limit of a store.
func (oc *OperatorController) getOrCreateStoreLimit(storeID uint64) *ratelimit.Bucket {
if oc.storesLimit[storeID] == nil {
rate := oc.cluster.GetStoreBalanceRate()
rate := oc.cluster.GetStoreBalanceRate() / StoreBalanceBaseTime
oc.newStoreLimit(storeID, rate)
oc.cluster.AttachOverloadStatus(storeID, func() bool {
oc.RLock()
Expand Down
2 changes: 1 addition & 1 deletion tests/cmd/pdctl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ func (s *cmdTestSuite) TestOperator(c *C) {
cluster, err := tests.NewTestCluster(3,
func(conf *server.Config) { conf.Replication.MaxReplicas = 2 },
func(conf *server.Config) { conf.Schedule.MaxStoreDownTime.Duration = time.Since(t) },
func(conf *server.Config) { conf.Schedule.StoreBalanceRate = 4 },
func(conf *server.Config) { conf.Schedule.StoreBalanceRate = 240 },
)
c.Assert(err, IsNil)
err = cluster.RunInitialServers()
Expand Down