-
Notifications
You must be signed in to change notification settings - Fork 48
fix(*): merge operator inconsistent after maintainer move #3769
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
Open
wlwilliamx
wants to merge
20
commits into
pingcap:master
Choose a base branch
from
wlwilliamx:fix/merge-operator-inconsistent-after-maintainer-move
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
2686e4a
fix(scheduler): ensure span consistency for operator add, remove, mov…
wlwilliamx 7288257
fix a typo
wlwilliamx b9637e2
fix a log typo
wlwilliamx ce070cc
handle err for restoreCurrentWorkingOperators
wlwilliamx b0929db
modify a comment
wlwilliamx d8732bc
Merge remote-tracking branch 'upstream/master' into fix/dispatcher-lo…
wlwilliamx 050e13f
resolve conflicts
wlwilliamx a7be949
fix newRemoveDispatcherOperator node id
wlwilliamx c9891d8
handle return value for AddOperator and add some logs for it
wlwilliamx 8c4e099
add some logs for dispatcher manager store current working operators
wlwilliamx 75638b2
fix remove operator nil span
wlwilliamx 82637b9
Merge remote-tracking branch 'upstream/master' into fix/dispatcher-lo…
wlwilliamx 26f5a83
remove enabled split
wlwilliamx d1d8752
fix(*): ensure merge operator consistency when maintainer restart
wlwilliamx 53fb47d
Merge remote-tracking branch 'upstream/master' into fix/merge-operato…
wlwilliamx b8473b1
fix maintainer uts
wlwilliamx ba7dd6d
Merge remote-tracking branch 'upstream/master' into fix/merge-operato…
wlwilliamx 8e3b14a
add test case
wlwilliamx 927581d
Merge remote-tracking branch 'upstream/master' into fix/merge-operato…
wlwilliamx e124c26
maintainer: tolerate bootstrap overlap during merge
wlwilliamx 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 hidden or 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
105 changes: 105 additions & 0 deletions
105
downstreamadapter/dispatchermanager/dispatcher_manager_merge.go
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| // Copyright 2025 PingCAP, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package dispatchermanager | ||
|
|
||
| import ( | ||
| "github.com/pingcap/log" | ||
| "github.com/pingcap/ticdc/heartbeatpb" | ||
| "github.com/pingcap/ticdc/pkg/common" | ||
| "go.uber.org/zap" | ||
| ) | ||
|
|
||
| // TrackMergeOperator records an in-flight merge request so bootstrap can restore it after maintainer failover. | ||
| func (e *DispatcherManager) TrackMergeOperator(req *heartbeatpb.MergeDispatcherRequest) { | ||
| if req == nil || req.MergedDispatcherID == nil { | ||
| return | ||
| } | ||
| mergedID := common.NewDispatcherIDFromPB(req.MergedDispatcherID) | ||
| e.mergeOperatorMap.Store(mergedID.String(), cloneMergeDispatcherRequest(req)) | ||
| } | ||
|
|
||
| // RemoveMergeOperator drops the persisted merge request once the merged dispatcher has converged. | ||
| func (e *DispatcherManager) RemoveMergeOperator(mergedDispatcherID common.DispatcherID) { | ||
| e.mergeOperatorMap.Delete(mergedDispatcherID.String()) | ||
| } | ||
|
|
||
| // MaybeCleanupMergeOperator removes a persisted merge request when the merged dispatcher is already complete or gone. | ||
| func (e *DispatcherManager) MaybeCleanupMergeOperator(req *heartbeatpb.MergeDispatcherRequest) { | ||
| if req == nil || req.MergedDispatcherID == nil { | ||
| return | ||
| } | ||
| mergedID := common.NewDispatcherIDFromPB(req.MergedDispatcherID) | ||
| if common.IsRedoMode(req.Mode) { | ||
| if dispatcherItem, ok := e.redoDispatcherMap.Get(mergedID); ok { | ||
| if dispatcherItem.GetComponentStatus() == heartbeatpb.ComponentState_Working { | ||
| e.RemoveMergeOperator(mergedID) | ||
| } | ||
| return | ||
| } | ||
| } else { | ||
| if dispatcherItem, ok := e.dispatcherMap.Get(mergedID); ok { | ||
| if dispatcherItem.GetComponentStatus() == heartbeatpb.ComponentState_Working { | ||
| e.RemoveMergeOperator(mergedID) | ||
| } | ||
| return | ||
| } | ||
| } | ||
| log.Info("cleanup merge operator because merged dispatcher not found", | ||
| zap.Stringer("changefeedID", e.changefeedID), | ||
| zap.String("dispatcherID", mergedID.String()), | ||
| zap.Int64("mode", req.Mode)) | ||
| e.RemoveMergeOperator(mergedID) | ||
| } | ||
|
|
||
| // GetMergeOperators returns cloned in-flight merge requests for maintainer bootstrap. | ||
| func (e *DispatcherManager) GetMergeOperators() []*heartbeatpb.MergeDispatcherRequest { | ||
| operators := make([]*heartbeatpb.MergeDispatcherRequest, 0) | ||
| e.mergeOperatorMap.Range(func(_, value any) bool { | ||
| req, ok := value.(*heartbeatpb.MergeDispatcherRequest) | ||
| if !ok || req == nil { | ||
| return true | ||
| } | ||
| operators = append(operators, cloneMergeDispatcherRequest(req)) | ||
| return true | ||
| }) | ||
| return operators | ||
| } | ||
|
|
||
| func cloneMergeDispatcherRequest(req *heartbeatpb.MergeDispatcherRequest) *heartbeatpb.MergeDispatcherRequest { | ||
| if req == nil { | ||
| return nil | ||
| } | ||
| clone := &heartbeatpb.MergeDispatcherRequest{ | ||
| Mode: req.Mode, | ||
| } | ||
| if req.ChangefeedID != nil { | ||
| id := *req.ChangefeedID | ||
| clone.ChangefeedID = &id | ||
| } | ||
| if req.MergedDispatcherID != nil { | ||
| mergedID := *req.MergedDispatcherID | ||
| clone.MergedDispatcherID = &mergedID | ||
| } | ||
| if len(req.DispatcherIDs) > 0 { | ||
| clone.DispatcherIDs = make([]*heartbeatpb.DispatcherID, 0, len(req.DispatcherIDs)) | ||
| for _, dispatcherID := range req.DispatcherIDs { | ||
| if dispatcherID == nil { | ||
| continue | ||
| } | ||
| id := *dispatcherID | ||
| clone.DispatcherIDs = append(clone.DispatcherIDs, &id) | ||
| } | ||
| } | ||
| return clone | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
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.
Reject zero-valued merged dispatcher IDs before touching
mergeOperatorMap.A non-nil protobuf ID can still decode to
DispatcherID{}. Right now those requests all collapse to the same key, and the bootstrap side later treats that zero ID as a real merged dispatcher, so one malformed request can poison recovery state.🔒 Suggested guard
func (e *DispatcherManager) TrackMergeOperator(req *heartbeatpb.MergeDispatcherRequest) { if req == nil || req.MergedDispatcherID == nil { return } mergedID := common.NewDispatcherIDFromPB(req.MergedDispatcherID) + if mergedID.IsZero() { + log.Warn("merge operator has invalid merged dispatcher ID", + zap.Stringer("changefeedID", e.changefeedID)) + return + } e.mergeOperatorMap.Store(mergedID.String(), cloneMergeDispatcherRequest(req)) }Apply the same
mergedID.IsZero()guard inMaybeCleanupMergeOperator.Also applies to: 38-43
🤖 Prompt for AI Agents