Skip to content

Commit

Permalink
operator: remove unnecessary check in op_controller (#1882)
Browse files Browse the repository at this point in the history
Signed-off-by: lhy1024 <admin@liudos.us>
  • Loading branch information
lhy1024 authored and sre-bot committed Nov 6, 2019
1 parent cb56454 commit a256162
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 25 deletions.
2 changes: 1 addition & 1 deletion server/schedule/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ func (o *Operator) UnfinishedInfluence(opInfluence OpInfluence, region *core.Reg
// TotalInfluence calculates the store difference which whole operator steps make.
func (o *Operator) TotalInfluence(opInfluence OpInfluence, region *core.RegionInfo) {
for step := 0; step < len(o.steps); step++ {
o.steps[int(step)].Influence(opInfluence, region)
o.steps[step].Influence(opInfluence, region)
}
}

Expand Down
27 changes: 5 additions & 22 deletions server/schedule/operator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,19 +600,20 @@ func (oc *OperatorController) OperatorCount(mask operator.OpKind) uint64 {

// GetOpInfluence gets OpInfluence.
func (oc *OperatorController) GetOpInfluence(cluster opt.Cluster) operator.OpInfluence {
influence := operator.OpInfluence{
StoresInfluence: make(map[uint64]*operator.StoreInfluence),
}
oc.RLock()
defer oc.RUnlock()

var res []*operator.Operator
for _, op := range oc.operators {
if !op.IsTimeout() && !op.IsFinish() {
region := cluster.GetRegion(op.RegionID())
if region != nil {
res = append(res, op)
op.UnfinishedInfluence(influence, region)
}
}
}
return NewUnfinishedOpInfluence(res, cluster)
return influence
}

// NewTotalOpInfluence creates a OpInfluence.
Expand All @@ -631,24 +632,6 @@ func NewTotalOpInfluence(operators []*operator.Operator, cluster opt.Cluster) op
return influence
}

// NewUnfinishedOpInfluence creates a OpInfluence.
func NewUnfinishedOpInfluence(operators []*operator.Operator, cluster opt.Cluster) operator.OpInfluence {
influence := operator.OpInfluence{
StoresInfluence: make(map[uint64]*operator.StoreInfluence),
}

for _, op := range operators {
if !op.IsTimeout() && !op.IsFinish() {
region := cluster.GetRegion(op.RegionID())
if region != nil {
op.UnfinishedInfluence(influence, region)
}
}
}

return influence
}

// SetOperator is only used for test.
func (oc *OperatorController) SetOperator(op *operator.Operator) {
oc.Lock()
Expand Down
7 changes: 5 additions & 2 deletions server/schedulers/balance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ func (s *testBalanceSpeedSuite) TestShouldBalance(c *C) {

opt := mockoption.NewScheduleOptions()
tc := mockcluster.NewCluster(opt)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
oc := schedule.NewOperatorController(ctx, nil, nil)
// create a region to control average region size.
tc.AddLeaderRegion(1, 1, 2)

Expand All @@ -118,7 +121,7 @@ func (s *testBalanceSpeedSuite) TestShouldBalance(c *C) {
tc.PutRegion(region)
tc.LeaderScheduleStrategy = t.kind.String()
kind := core.NewScheduleKind(core.LeaderKind, t.kind)
c.Assert(shouldBalance(tc, source, target, region, kind, schedule.NewUnfinishedOpInfluence(nil, tc), ""), Equals, t.expectedResult)
c.Assert(shouldBalance(tc, source, target, region, kind, oc.GetOpInfluence(tc), ""), Equals, t.expectedResult)
}

for _, t := range tests {
Expand All @@ -130,7 +133,7 @@ func (s *testBalanceSpeedSuite) TestShouldBalance(c *C) {
region := tc.GetRegion(1).Clone(core.SetApproximateSize(t.regionSize))
tc.PutRegion(region)
kind := core.NewScheduleKind(core.RegionKind, t.kind)
c.Assert(shouldBalance(tc, source, target, region, kind, schedule.NewUnfinishedOpInfluence(nil, tc), ""), Equals, t.expectedResult)
c.Assert(shouldBalance(tc, source, target, region, kind, oc.GetOpInfluence(tc), ""), Equals, t.expectedResult)
}
}
}
Expand Down

0 comments on commit a256162

Please sign in to comment.