vitess
vitess copied to clipboard
Fix PromoteReplica call in ERS
Description
As described in https://github.com/vitessio/vitess/issues/15935, running PromoteReplica before calling SetReplicationSource on the replicas is an issue as it can cause PromoteReplica to indefinitely hang.
This PR fixes 2 issues -
- We now run
PromoteReplicain parallel withSetReplicationSource. This also allows us to not run thePrimaryPositionRPC separately, sincePromoteReplicaalso returns the position of the primary. - We should be using a context that has a timeout when running any RPC calls. Previously
PromoteReplicaandInitPrimaryboth were being called without adding a context timeout. This has also been fixed now.
Related Issue(s)
- Fixes https://github.com/vitessio/vitess/issues/15935
Checklist
- [x] "Backport to:" labels have been added if this change should be back-ported to release branches
- [x] If this change is to be back-ported to previous releases, a justification is included in the PR description
- [x] Tests were added or are not required
- [x] Did the new or modified tests pass consistently locally and on CI?
- [x] Documentation was added or is not required
Deployment Notes
Review Checklist
Hello reviewers! :wave: Please follow this checklist when reviewing this Pull Request.
General
- [x] Ensure that the Pull Request has a descriptive title.
- [x] Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.
Tests
- [ ] Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.
Documentation
- [ ] Apply the
release notes (needs details)label if users need to know about this change. - [ ] New features should be documented.
- [x] There should be some code comments as to why things are implemented the way they are.
- [x] There should be a comment at the top of each new or modified test to explain what the test does.
New flags
- [ ] Is this flag really necessary?
- [ ] Flag names must be clear and intuitive, use dashes (
-), and have a clear help text.
If a workflow is added or modified:
- [ ] Each item in
Jobsshould be named in order to mark it asrequired. - [ ] If the workflow needs to be marked as
required, the maintainer team must be notified.
Backward compatibility
- [ ] Protobuf changes should be wire-compatible.
- [ ] Changes to
_vttables and RPCs need to be backward compatible. - [ ] RPC changes should be compatible with vitess-operator
- [ ] If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
- [ ]
vtctlcommand output order should be stable andawk-able.
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 68.46%. Comparing base (
3b09eb2) to head (392845f). Report is 1 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #15934 +/- ##
==========================================
- Coverage 68.47% 68.46% -0.02%
==========================================
Files 1562 1562
Lines 197083 197080 -3
==========================================
- Hits 134962 134936 -26
- Misses 62121 62144 +23
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
@deepthi Added the test as well, which I ensured failed before the changes.
Thank you for the review @mattlord. I'll work on addressing them 👍.
As far as the changes for running PromoteReplica in parallel, earlier we would call PromoteReplica and then the reparentReplicas function. Now, we call PromoteReplica as part of handlePrimary in reparentReplicas. handlePrimary runs in parallel with handleReplica which runs SetReplicationSource.
Thank you for the review @mattlord. I'll work on addressing them 👍.
As far as the changes for running
PromoteReplicain parallel, earlier we would callPromoteReplicaand then thereparentReplicasfunction. Now, we callPromoteReplicaas part ofhandlePrimaryinreparentReplicas.handlePrimaryruns in parallel withhandleReplicawhich runsSetReplicationSource.
OK, I see. So here: https://github.com/vitessio/vitess/pull/15934/files#diff-aace4cbbbebad37f5072421e16ca464c0f0b4eb98ad287380c2c764d11e7b836R310-R311
We're calling the reparentReplicas function — which does the promotion of the new primary and the replica reparents — instead of doing those two things serially. Now that I've looked at that reparentReplicas function I can see what you meant (it uses goroutines for each higher level task of promotion and reparent). Thanks!
Thank you @mattlord! I've addressed all the review comments, and just waiting for the tests now! 🚀