mcs/scheduling: prevent scheduler update notifier from blocking#10869
Conversation
Signed-off-by: Ryan Leung <rleungx@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughUpdated scheduler-updating notifier mechanism to prevent blocking during primary switches. Changed channel type to bidirectional, implemented non-blocking notification coalescing, added atomic clearing with compare-and-swap, ensured cleanup on exit, and validated with lifecycle tests. ChangesScheduler Notifier Lifecycle Management
Sequence Diagram(s)sequenceDiagram
participant UpdateScheduler as updateScheduler<br/>(cluster.go)
participant PersistConfig as PersistConfig<br/>(config.go)
participant Notifier as Notifier Channel
UpdateScheduler->>PersistConfig: SetSchedulersUpdatingNotifier(ch)
activate PersistConfig
PersistConfig->>PersistConfig: Store ch in atomic.Value
deactivate PersistConfig
loop Background Loop
UpdateScheduler->>PersistConfig: SetScheduleConfig(...)
activate PersistConfig
PersistConfig->>PersistConfig: tryNotifySchedulersUpdating()
PersistConfig->>Notifier: select { case ch <- struct{}{} | default: }
Note over Notifier: Non-blocking send<br/>Coalesces multiple signals
deactivate PersistConfig
end
Note over UpdateScheduler: Function exit or shutdown
UpdateScheduler->>PersistConfig: defer ClearSchedulersUpdatingNotifier(ch)
activate PersistConfig
PersistConfig->>PersistConfig: CompareAndSwap in atomic.Value<br/>Clear only if ch matches
deactivate PersistConfig
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #10869 +/- ##
==========================================
- Coverage 79.17% 79.09% -0.08%
==========================================
Files 536 536
Lines 73882 74044 +162
==========================================
+ Hits 58494 58568 +74
- Misses 11271 11336 +65
- Partials 4117 4140 +23
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
Signed-off-by: Ryan Leung <rleungx@gmail.com>
|
/test pull-integration-realcluster-test |
| if notifier == nil { | ||
| return | ||
| } | ||
| current := o.getSchedulersUpdatingNotifier() |
There was a problem hiding this comment.
Do we need to close the current channel? And if the equal condition is not true, Dose it cause the channel leak(I don't find any where close it )?
There was a problem hiding this comment.
I do not think we should close the notifier here. updateScheduler exits through c.ctx.Done(), and closing the channel could race with tryNotifySchedulersUpdating after it has loaded the channel and cause a send-on-closed-channel panic. If current != notifier, it means a newer notifier has already been registered, so the old one should not clear or close it. The old channel will be released after the old updateScheduler exits.
|
/label needs-cherry-pick-release-8.5 |
[LGTM Timeline notifier]Timeline:
|
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: bufferflies, lhy1024, niubell The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
In response to a cherrypick label: new pull request created to branch |
What problem does this PR solve?
Issue Number: Close #9776
What is changed and how does it work?
Check List
Tests
Related changes
Release note
Summary by CodeRabbit
Bug Fixes
Tests