-
Notifications
You must be signed in to change notification settings - Fork 24
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
[to #48] try to fix scheduler problem #90
Merged
Merged
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
7713452
try fix scheduler problem
5a9e84c
optimization
ea8d92a
fix ut
8365ece
fix ut
ed5ea96
remove commented codes
910807a
Merge branch 'main' into scheduler
pingyu 7446ada
fix ut for owner
edbfecd
add ut for processor
418f32a
merge
cdca014
Merge branch 'main' into scheduler
zeminzhou 401e190
fix ut
a91c864
Merge branch 'new-sched' into new-sched2
064fa9f
Merge branch 'tikv:main' into scheduler
zeminzhou fbadbdd
Merge branch 'main' into scheduler
zeminzhou 981497b
fix ut
zeminzhou fb38d21
remove spaceline
zeminzhou 272db76
int64 -> uint64
zeminzhou 176b48e
.
zeminzhou ea39b9d
.
zeminzhou acd37f3
Merge branch 'main' into scheduler
pingyu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,8 @@ type schedulerJob struct { | |
// if the operation is an add operation, boundaryTs is start ts | ||
BoundaryTs uint64 | ||
TargetCapture model.CaptureID | ||
|
||
RelatedKeySpans []model.KeySpanLocation | ||
} | ||
|
||
type moveKeySpanJob struct { | ||
|
@@ -55,7 +57,7 @@ type moveKeySpanJob struct { | |
|
||
type oldScheduler struct { | ||
state *orchestrator.ChangefeedReactorState | ||
currentKeySpansID []model.KeySpanID | ||
currentKeySpanIDs []model.KeySpanID | ||
currentKeySpans map[model.KeySpanID]regionspan.Span | ||
captures map[model.CaptureID]*model.CaptureInfo | ||
|
||
|
@@ -80,20 +82,21 @@ func newSchedulerV1(f updateCurrentKeySpansFunc) scheduler { | |
func (s *oldScheduler) Tick( | ||
ctx cdcContext.Context, | ||
state *orchestrator.ChangefeedReactorState, | ||
// currentKeySpans []model.KeySpanID, | ||
captures map[model.CaptureID]*model.CaptureInfo, | ||
) (shouldUpdateState bool, err error) { | ||
|
||
s.state = state | ||
s.captures = captures | ||
|
||
s.currentKeySpansID, s.currentKeySpans, err = s.updateCurrentKeySpans(ctx) | ||
currentKeySpanIDs, currentKeySpans, err := s.updateCurrentKeySpans(ctx) | ||
if err != nil { | ||
return false, errors.Trace(err) | ||
} | ||
|
||
newKeySpans, needRemoveKeySpans := s.diffCurrentKeySpans(currentKeySpans) | ||
s.currentKeySpanIDs, s.currentKeySpans = currentKeySpanIDs, currentKeySpans | ||
|
||
s.cleanUpFinishedOperations() | ||
pendingJob, err := s.syncKeySpansWithCurrentKeySpans() | ||
pendingJob, err := s.syncKeySpansWithCurrentKeySpans(newKeySpans, needRemoveKeySpans) | ||
if err != nil { | ||
return false, errors.Trace(err) | ||
} | ||
|
@@ -116,6 +119,27 @@ func (s *oldScheduler) Tick( | |
return shouldUpdateState, nil | ||
} | ||
|
||
func (s *oldScheduler) diffCurrentKeySpans(currentKeySpans map[model.KeySpanID]regionspan.Span) (map[model.KeySpanID]struct{}, []model.KeySpanID) { | ||
oldKeySpans := s.currentKeySpans | ||
|
||
newKeySpans := map[model.KeySpanID]struct{}{} | ||
needRemoveKeySpans := []model.KeySpanID{} | ||
|
||
for keyspanID := range oldKeySpans { | ||
if _, ok := currentKeySpans[keyspanID]; !ok { | ||
needRemoveKeySpans = append(needRemoveKeySpans, keyspanID) | ||
} | ||
} | ||
|
||
for keyspanID := range currentKeySpans { | ||
if _, ok := oldKeySpans[keyspanID]; !ok { | ||
newKeySpans[keyspanID] = struct{}{} | ||
} | ||
} | ||
|
||
return newKeySpans, needRemoveKeySpans | ||
} | ||
|
||
func (s *oldScheduler) MoveKeySpan(keyspanID model.KeySpanID, target model.CaptureID) { | ||
s.moveKeySpanJobQueue = append(s.moveKeySpanJobQueue, &moveKeySpanJob{ | ||
keyspanID: keyspanID, | ||
|
@@ -221,7 +245,9 @@ func (s *oldScheduler) dispatchToTargetCaptures(pendingJobs []*schedulerJob) { | |
} | ||
} | ||
|
||
count := 0 | ||
getMinWorkloadCapture := func() model.CaptureID { | ||
count++ | ||
minCapture := "" | ||
minWorkLoad := uint64(math.MaxUint64) | ||
for captureID, workload := range workloads { | ||
|
@@ -249,26 +275,41 @@ func (s *oldScheduler) dispatchToTargetCaptures(pendingJobs []*schedulerJob) { | |
|
||
// syncKeySpansWithCurrentKeySpans iterates all current keyspans to check whether it should be listened or not. | ||
// this function will return schedulerJob to make sure all keyspans will be listened. | ||
func (s *oldScheduler) syncKeySpansWithCurrentKeySpans() ([]*schedulerJob, error) { | ||
func (s *oldScheduler) syncKeySpansWithCurrentKeySpans(newKeySpans map[model.KeySpanID]struct{}, needRemoveKeySpans []model.KeySpanID) ([]*schedulerJob, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest to add unit test for this method. |
||
var pendingJob []*schedulerJob | ||
allKeySpanListeningNow, err := s.keyspan2CaptureIndex() | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
relatedKeySpans := make([]model.KeySpanLocation, 0, len(needRemoveKeySpans)) | ||
for _, keyspanID := range needRemoveKeySpans { | ||
if captureID, ok := allKeySpanListeningNow[keyspanID]; ok { | ||
location := model.KeySpanLocation{ | ||
CaptureID: captureID, | ||
KeySpanID: keyspanID, | ||
} | ||
relatedKeySpans = append(relatedKeySpans, location) | ||
} | ||
} | ||
|
||
globalCheckpointTs := s.state.Status.CheckpointTs | ||
for _, keyspanID := range s.currentKeySpansID { | ||
for _, keyspanID := range s.currentKeySpanIDs { | ||
if _, exist := allKeySpanListeningNow[keyspanID]; exist { | ||
delete(allKeySpanListeningNow, keyspanID) | ||
continue | ||
} | ||
// For each keyspan which should be listened but is not, add an adding-keyspan job to the pending job list | ||
pendingJob = append(pendingJob, &schedulerJob{ | ||
job := &schedulerJob{ | ||
Tp: schedulerJobTypeAddKeySpan, | ||
KeySpanID: keyspanID, | ||
Start: s.currentKeySpans[keyspanID].Start, | ||
End: s.currentKeySpans[keyspanID].End, | ||
BoundaryTs: globalCheckpointTs, | ||
}) | ||
} | ||
if _, ok := newKeySpans[keyspanID]; ok { | ||
job.RelatedKeySpans = relatedKeySpans | ||
} | ||
// For each keyspan which should be listened but is not, add an adding-keyspan job to the pending job list | ||
pendingJob = append(pendingJob, job) | ||
} | ||
// The remaining keyspans are the keyspans which should be not listened | ||
keyspansThatShouldNotBeListened := allKeySpanListeningNow | ||
|
@@ -303,7 +344,7 @@ func (s *oldScheduler) handleJobs(jobs []*schedulerJob) { | |
StartTs: job.BoundaryTs, | ||
Start: job.Start, | ||
End: job.End, | ||
}, job.BoundaryTs) | ||
}, job.BoundaryTs, job.RelatedKeySpans) | ||
case schedulerJobTypeRemoveKeySpan: | ||
failpoint.Inject("OwnerRemoveKeySpanError", func() { | ||
// just skip removing this keyspan | ||
|
@@ -517,6 +558,7 @@ func (w *schedulerV1CompatWrapper) calculateWatermarks( | |
if resolvedTs == model.Ts(math.MaxUint64) { | ||
return schedulerv2.CheckpointCannotProceed, 0 | ||
} | ||
|
||
checkpointTs := resolvedTs | ||
for _, position := range state.TaskPositions { | ||
if checkpointTs > position.CheckPointTs { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add unit test for this method.