Skip to content

Commit

Permalink
set MaxScheduleCost to 0 by default
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <rleungx@gmail.com>
  • Loading branch information
rleungx committed Apr 2, 2019
1 parent 8624ddf commit 2df2083
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 23 deletions.
10 changes: 5 additions & 5 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,13 +560,13 @@ const (
defaultSplitMergeInterval = 1 * time.Hour
defaultPatrolRegionInterval = 100 * time.Millisecond
defaultMaxStoreDownTime = 30 * time.Minute
defaultLeaderScheduleLimit = 4
defaultRegionScheduleLimit = 4
defaultReplicaScheduleLimit = 8
defaultLeaderScheduleLimit = 1000
defaultRegionScheduleLimit = 1000
defaultReplicaScheduleLimit = 1000
defaultMergeScheduleLimit = 8
defaultHotRegionScheduleLimit = 2
defaultMaxScheduleCost = 200
defaultStoreMaxScheduleCost = 20
defaultMaxScheduleCost = 0
defaultStoreMaxScheduleCost = 50
defaultTolerantSizeRatio = 5
defaultLowSpaceRatio = 0.8
defaultHighSpaceRatio = 0.6
Expand Down
6 changes: 4 additions & 2 deletions server/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ func (c *coordinator) checkRegion(region *core.RegionInfo) bool {
// If PD has restarted, it need to check learners added before and promote them.
// Don't check isRaftLearnerEnabled cause it maybe disable learner feature but there are still some learners to promote.
opController := c.opController
if c.opController.GetScheduleCost() >= c.cluster.GetMaxScheduleCost() {
maxScheduleCost := c.cluster.GetMaxScheduleCost()
if maxScheduleCost != 0 && c.opController.GetScheduleCost() >= maxScheduleCost {
return false
}
for _, p := range region.GetLearners() {
Expand Down Expand Up @@ -472,7 +473,8 @@ func (s *scheduleController) GetInterval() time.Duration {

// AllowSchedule returns if a scheduler is allowed to schedule.
func (s *scheduleController) AllowSchedule() bool {
if s.opController.GetScheduleCost() >= s.cluster.GetMaxScheduleCost() {
maxScheduleCost := s.cluster.GetMaxScheduleCost()
if maxScheduleCost != 0 && s.opController.GetScheduleCost() >= maxScheduleCost {
return false
}
return s.Scheduler.IsScheduleAllowed(s.cluster)
Expand Down
4 changes: 2 additions & 2 deletions server/schedule/mockcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,8 @@ const (
defaultReplicaScheduleLimit = 8
defaultMergeScheduleLimit = 8
defaultHotRegionScheduleLimit = 2
defaultMaxScheduleCost = 200
defaultStoreMaxScheduleCost = 20
defaultMaxScheduleCost = 0
defaultStoreMaxScheduleCost = 50
defaultTolerantSizeRatio = 2.5
defaultLowSpaceRatio = 0.8
defaultHighSpaceRatio = 0.6
Expand Down
2 changes: 1 addition & 1 deletion server/schedule/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const (
// longer than it, the operator will be considered timeout.
RegionOperatorWaitTime = 10 * time.Minute
// RegionWeight reflects the influence which is caused by a region related step in an operator.
RegionWeight = 2
RegionWeight = 10
// LeaderWeight reflects the influence which is caused by a leader related step in an operator.
LeaderWeight = 1
)
Expand Down
16 changes: 8 additions & 8 deletions server/schedule/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (s *testOperatorSuite) TestInfluence(c *C) {
LeaderCount: 0,
RegionSize: 10,
RegionCount: 1,
StepCost: 2,
StepCost: 10,
})

TransferLeader{FromStore: 1, ToStore: 2}.Influence(opInfluence, region)
Expand All @@ -139,7 +139,7 @@ func (s *testOperatorSuite) TestInfluence(c *C) {
LeaderCount: 1,
RegionSize: 10,
RegionCount: 1,
StepCost: 3,
StepCost: 11,
})

RemovePeer{FromStore: 1}.Influence(opInfluence, region)
Expand All @@ -148,14 +148,14 @@ func (s *testOperatorSuite) TestInfluence(c *C) {
LeaderCount: -1,
RegionSize: -10,
RegionCount: -1,
StepCost: 3,
StepCost: 11,
})
c.Assert(*storeOpInfluence[2], DeepEquals, StoreInfluence{
LeaderSize: 10,
LeaderCount: 1,
RegionSize: 10,
RegionCount: 1,
StepCost: 3,
StepCost: 11,
})

MergeRegion{IsPassive: false}.Influence(opInfluence, region)
Expand All @@ -164,14 +164,14 @@ func (s *testOperatorSuite) TestInfluence(c *C) {
LeaderCount: -1,
RegionSize: -10,
RegionCount: -1,
StepCost: 3,
StepCost: 11,
})
c.Assert(*storeOpInfluence[2], DeepEquals, StoreInfluence{
LeaderSize: 10,
LeaderCount: 1,
RegionSize: 10,
RegionCount: 1,
StepCost: 3,
StepCost: 11,
})

MergeRegion{IsPassive: true}.Influence(opInfluence, region)
Expand All @@ -180,14 +180,14 @@ func (s *testOperatorSuite) TestInfluence(c *C) {
LeaderCount: -2,
RegionSize: -10,
RegionCount: -2,
StepCost: 6,
StepCost: 22,
})
c.Assert(*storeOpInfluence[2], DeepEquals, StoreInfluence{
LeaderSize: 10,
LeaderCount: 1,
RegionSize: 10,
RegionCount: 0,
StepCost: 5,
StepCost: 21,
})
}

Expand Down
2 changes: 2 additions & 0 deletions tools/pd-simulator/simulator/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ func (r *RaftEngine) NeedSplit(size, rows int64) bool {
}

func (r *RaftEngine) recordRegionChange(region *core.RegionInfo) {
r.Lock()
defer r.Unlock()
n := region.GetLeader().GetStoreId()
r.regionChange[n] = append(r.regionChange[n], region.GetID())
}
Expand Down
5 changes: 0 additions & 5 deletions tools/pd-simulator/simulator/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ import (
"bytes"
"fmt"

"go.uber.org/zap"

"github.com/pingcap/kvproto/pkg/eraftpb"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/kvproto/pkg/pdpb"
"github.com/pingcap/pd/server/core"
"github.com/pingcap/pd/tools/pd-simulator/simulator/simutil"
)

// Task running in node.
Expand Down Expand Up @@ -234,7 +231,6 @@ func (a *addPeer) Step(r *RaftEngine) {
snapshotSize := region.GetApproximateSize()
sendNode := r.conn.Nodes[region.GetLeader().GetStoreId()]
if sendNode == nil {
simutil.Logger.Error("failed to sent snapshot, node has been deleted", zap.Uint64("node-id", sendNode.Id))
a.finished = true
return
}
Expand All @@ -245,7 +241,6 @@ func (a *addPeer) Step(r *RaftEngine) {

recvNode := r.conn.Nodes[a.peer.GetStoreId()]
if recvNode == nil {
simutil.Logger.Error("failed to receive snapshot: node has been deleted", zap.Uint64("node-id", recvNode.Id))
a.finished = true
return
}
Expand Down

0 comments on commit 2df2083

Please sign in to comment.