vitess icon indicating copy to clipboard operation
vitess copied to clipboard

Fix PromoteReplica call in ERS

Open GuptaManan100 opened this issue 1 year ago • 3 comments

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 -

  1. We now run PromoteReplica in parallel with SetReplicationSource. This also allows us to not run the PrimaryPosition RPC separately, since PromoteReplica also returns the position of the primary.
  2. We should be using a context that has a timeout when running any RPC calls. Previously PromoteReplica and InitPrimary both 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

GuptaManan100 avatar May 14 '24 07:05 GuptaManan100

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 Jobs should be named in order to mark it as required.
  • [ ] 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 _vt tables 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.
  • [ ] vtctl command output order should be stable and awk-able.

vitess-bot[bot] avatar May 14 '24 07:05 vitess-bot[bot]

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.

codecov[bot] avatar May 14 '24 07:05 codecov[bot]

@deepthi Added the test as well, which I ensured failed before the changes.

GuptaManan100 avatar May 16 '24 09:05 GuptaManan100

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.

GuptaManan100 avatar May 21 '24 14:05 GuptaManan100

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.

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!

mattlord avatar May 21 '24 15:05 mattlord

Thank you @mattlord! I've addressed all the review comments, and just waiting for the tests now! 🚀

GuptaManan100 avatar May 21 '24 15:05 GuptaManan100