Skip to content
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

Support specifying expected primary in ERS/PRS #16852

Merged
merged 15 commits into from
Oct 4, 2024

Conversation

timvaillancourt
Copy link
Contributor

@timvaillancourt timvaillancourt commented Sep 26, 2024

Description

This PR allows a EmergencyReparentShard/PlannedReparentShard request to contain the alias of the primary we expect to be the current primary for the action to succeed. If this alias is incorrect or stale, the reparent fails with an error indicating there is a failed precondition/mismatch.

This is useful to prevent races between external automation that runs reparents and Vitess (vtorc and vtctld), which may reparent a shard in the time external automation is creating/processing it's own reparent request. With this support added, automation with a stale view of the world will encounter an error instead of triggering an potentially unnecessary reparent

In the future, Vitess could use this field internally to be more explicit but because everything uses shard locks, it should never encounter a mismatch

Related Issue(s)

Resolves #16430

Checklist

  • "Backport to:" labels have been added if this change should be back-ported to release branches
  • If this change is to be back-ported to previous releases, a justification is included in the PR description
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on CI?
  • Documentation was added or is not required

Deployment Notes

Signed-off-by: Tim Vaillancourt <[email protected]>
Signed-off-by: Tim Vaillancourt <[email protected]>
Signed-off-by: Tim Vaillancourt <[email protected]>
Signed-off-by: Tim Vaillancourt <[email protected]>
Signed-off-by: Tim Vaillancourt <[email protected]>
Signed-off-by: Tim Vaillancourt <[email protected]>
Copy link
Contributor

vitess-bot bot commented Sep 26, 2024

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • 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.
  • There should be some code comments as to why things are implemented the way they are.
  • 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 vitess-bot bot added NeedsBackportReason If backport labels have been applied to a PR, a justification is required NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsWebsiteDocsUpdate What it says labels Sep 26, 2024
@timvaillancourt timvaillancourt added Type: Enhancement Logical improvement (somewhere between a bug and feature) Component: vtctl and removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says NeedsIssue A linked issue is missing for this Pull Request NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Sep 26, 2024
@timvaillancourt timvaillancourt added this to the v21.0.0 milestone Sep 26, 2024
Copy link

codecov bot commented Sep 26, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 15 lines in your changes missing coverage. Please review.

Project coverage is 69.43%. Comparing base (2e2b223) to head (40c78a2).
Report is 15 commits behind head on main.

Files with missing lines Patch % Lines
go/cmd/vtctldclient/command/reparents.go 12.50% 14 Missing ⚠️
go/vt/vtctl/grpcvtctldserver/server.go 75.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main   #16852    +/-   ##
========================================
  Coverage   69.43%   69.43%            
========================================
  Files        1571     1571            
  Lines      203021   203223   +202     
========================================
+ Hits       140970   141117   +147     
- Misses      62051    62106    +55     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mattlord
Copy link
Contributor

mattlord commented Sep 26, 2024

You'll want to add support for this in the client command, no? Here: go/cmd/vtctldclient/command/reparents.go

@timvaillancourt
Copy link
Contributor Author

You'll want to add support for this in the client command, no? Here: go/cmd/vtctldclient/command/reparents.go

@mattlord oh thanks, yes I'll add support for the CLI binary 👍👀

@timvaillancourt
Copy link
Contributor Author

Added:

tvaillancourt@tvailla-ltmxctu vitess % ./bin/vtctldclient EmergencyReparentShard --help 2>&1 | grep expected-primary
      --expected-primary string          Alias of a tablet that must be the current primary in order for the reparent to be processed.

👍

Signed-off-by: Tim Vaillancourt <[email protected]>
@arthurschreiber
Copy link
Contributor

@timvaillancourt Can we have that same cli flag for PlannedReparentShard as well? 😬

@timvaillancourt
Copy link
Contributor Author

@arthurschreiber in the original issue we discussed adding this to PRS too but the recommendation was to use the new primary flag to fence things. Of course that only works if all systems agree on a candidate, which isn't guaranteed

I'd be on board with adding this to PRS too if no objections

@arthurschreiber
Copy link
Contributor

Adding this to PRS would make our operations a lot more robust. Obviously, PRS takes a lock before modifying a shard, so no two PRS operations can run at the same time, but we'd also like to guarantee that we don't fail over a shard during the buffer cooldown period we have set.

We can check the time when the current primary started serving, but we can't guarantee that a PRS from some other automation or manual call jumps in between the check of the timestamp and the call to PRS. Allowing us to specify the expected current primary for PRS as well would allow us to abort if the primary got changed unexpectedly.

@mattlord
Copy link
Contributor

mattlord commented Oct 2, 2024

I think the idea of being able to enforce a specific sequence or state machine for the shard leadership/primaryship makes a lot of sense for both ERS and PRS, FWIW. 🙂

@timvaillancourt
Copy link
Contributor Author

timvaillancourt commented Oct 2, 2024

@arthurschreiber / @mattlord yeah, I think it's a good idea for both so I'll update this PR to add that

As mentioned, Vitess could use this internally too (probably in +1 release). It would never hit a conflict (unless we broke something) but it wouldn't hurt either

EDIT: I also realized RequiredPrimary might be more clear. Any thoughts?

Signed-off-by: Tim Vaillancourt <[email protected]>
@timvaillancourt timvaillancourt changed the title Support specifying expected primary in ERS Support specifying expected primary in ERS/PRS Oct 2, 2024
Signed-off-by: Tim Vaillancourt <[email protected]>
Signed-off-by: Tim Vaillancourt <[email protected]>
@timvaillancourt
Copy link
Contributor Author

timvaillancourt commented Oct 2, 2024

I think I prefer the field-name RequiredPrimary now but let's vote on it

🎉 for ExpectedPrimary
🚀 for RequiredPrimary
👀 for ExpectedCurrentPrimary
😄 for RequiredCurrentPrimary

Or other suggestions appreciated

Signed-off-by: Tim Vaillancourt <[email protected]>
Copy link
Member

@GuptaManan100 GuptaManan100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@deepthi
Copy link
Member

deepthi commented Oct 3, 2024

I think I prefer the field-name RequiredPrimary now but let's vote on it

🎉 for ExpectedPrimary 🚀 for RequiredPrimary

Or other suggestions appreciated

RequiredCurrentPrimary OR ExpectedCurrentPrimary :)

Copy link
Member

@deepthi deepthi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Once the flag name is final, you should edit the PR description to document command usage. I've added a label that prevents merge, and you can remove the label and merge it at that point.

@deepthi deepthi added the NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work label Oct 3, 2024
@timvaillancourt
Copy link
Contributor Author

LGTM. Once the flag name is final, you should edit the PR description to document command usage. I've added a label that prevents merge, and you can remove the label and merge it at that point.

Sounds good! It looks like there weren't many strong opinions on naming

I think I've flip/flopped back to leaving this as-is. My reasoning is if I say what I'm asking to do out loud it is "do X reparent and I expect Y to be still be the primary". And I feel adding Current is redundant because there can only be a single primary

@timvaillancourt timvaillancourt removed the NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work label Oct 4, 2024
@timvaillancourt timvaillancourt merged commit 945124a into vitessio:main Oct 4, 2024
102 of 103 checks passed
@timvaillancourt timvaillancourt deleted the ers-current-primary branch October 4, 2024 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: CLI Component: vtctl Type: Enhancement Logical improvement (somewhere between a bug and feature)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: allow current/before PRIMARY to be specified in ERS
5 participants