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: fix datarace in operator.check (#8264) #8580

Closed
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
5 changes: 5 additions & 0 deletions pkg/schedule/operator/operator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,13 @@ func (oc *Controller) checkAddOperator(isPromoting bool, ops ...*Operator) (bool
operatorCounter.WithLabelValues(op.Desc(), "unexpected-status").Inc()
return false, NotInCreateStatus
}
<<<<<<< HEAD
if !isPromoting && oc.wopStatus.ops[op.Desc()] >= oc.config.GetSchedulerMaxWaitingOperator() {
log.Debug("exceed max return false", zap.Uint64("waiting", oc.wopStatus.ops[op.Desc()]), zap.String("desc", op.Desc()), zap.Uint64("max", oc.config.GetSchedulerMaxWaitingOperator()))
=======
if !isPromoting && oc.wopStatus.getCount(op.Desc()) >= oc.config.GetSchedulerMaxWaitingOperator() {
log.Debug("exceed max return false", zap.Uint64("waiting", oc.wopStatus.getCount(op.Desc())), zap.String("desc", op.Desc()), zap.Uint64("max", oc.config.GetSchedulerMaxWaitingOperator()))
>>>>>>> e767c012f (schedule: fix datarace in `operator.check` (#8264))
operatorCounter.WithLabelValues(op.Desc(), "exceed-max-waiting").Inc()
return false, ExceedWaitLimit
}
Expand Down
27 changes: 27 additions & 0 deletions pkg/schedule/operator/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
import (
"context"
"encoding/json"
<<<<<<< HEAD

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / tso-function-test

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / statics

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (12)

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (13)

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (10)

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (10)

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (10)

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (2)

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (2)

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (2)

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (4)

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (4)

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (4)

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (6)

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (6)

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (6)

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (1)

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (1)

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (1)

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (5)

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (5)

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (5)

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (11)

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (3)

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (3)

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (3)

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (7)

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (7)

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (7)

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (9)

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (9)

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (9)

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (8)

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (8)

missing import path

Check failure on line 20 in pkg/schedule/operator/operator_test.go

View workflow job for this annotation

GitHub Actions / chunks (8)

missing import path
"fmt"
=======
>>>>>>> e767c012f (schedule: fix datarace in `operator.check` (#8264))
"sync"
"sync/atomic"
"testing"
Expand Down Expand Up @@ -553,3 +556,27 @@
}
wg.Wait()
}

func TestOperatorCheckConcurrently(t *testing.T) {
re := require.New(t)
region := newTestRegion(1, 1, [2]uint64{1, 1}, [2]uint64{2, 2})
// addPeer1, transferLeader1, removePeer3
steps := []OpStep{
AddPeer{ToStore: 1, PeerID: 1},
TransferLeader{FromStore: 3, ToStore: 1},
RemovePeer{FromStore: 3},
}
op := NewTestOperator(1, &metapb.RegionEpoch{}, OpAdmin|OpLeader|OpRegion, steps...)
re.Equal(constant.Urgent, op.GetPriorityLevel())
checkSteps(re, op, steps)
op.Start()
var wg sync.WaitGroup
for i := 0; i < 10; i++ {
wg.Add(1)
go func() {
defer wg.Done()
re.Nil(op.Check(region))
}()
}
wg.Wait()
}
Loading