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

VReplication: Auto renew lease on Keyspace Lock #16240

Closed
wants to merge 8 commits into from

Conversation

mattlord
Copy link
Contributor

@mattlord mattlord commented Jun 20, 2024

Description

VReplication uses Keyspace topo server locks in order to prevent concurrent changes that could cause breakages. It does that in these primary locations:

  1. When performing a traffic switch (SwitchTraffic and ReverseTraffic) in various workflows like MoveTables and Reshard
  2. When cleaning up resources related to a workflow when canceling/deleting/completing it
  3. When initializing a VDiff

This is done in order to prevent concurrent changes to shared resources such as the _vt.vreplication record on target shards.

At some point, I think we should add a distributed workflow lock in the topo to coordinate on related issues. We may want those both at a keyspace level and at a shard level — depending on the level of concurrency control we require for the given operation. This lock can then also be held for as long as needed as it would not impact other Vitess operations (the Keyspace Lock is used for things e.g. like updating the throttler config, durability policy, or schema for a keyspace). This will be a major project, however, and for the time being we can instead make a relatively minor change to how the Keyspace locks are managed in the noted cases within VReplication. In this PR the change is that we automatically renew the Keyspace Lock while holding it, up to a maximum time (hard coded at 10 mins now but will probably add a flag for this ~ --max-keyspace-lock-ttl=<duration> which defaults to 10m).

Related Issue(s)

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

@mattlord mattlord added Type: Bug Type: Enhancement Logical improvement (somewhere between a bug and feature) Component: VReplication labels Jun 20, 2024
Copy link
Contributor

vitess-bot bot commented Jun 20, 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 Jun 20, 2024
@github-actions github-actions bot added this to the v21.0.0 milestone Jun 20, 2024
@mattlord mattlord changed the title Auto renew KS lock on traffic switch and vdiff init VReplication: Auto renew Keyspace Lock on traffic switch and VDiff init Jun 20, 2024
@mattlord mattlord removed 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 Jun 20, 2024
@mattlord mattlord force-pushed the vrepl_ks_lock_auto_renew branch from 09e8f62 to 0962e47 Compare June 20, 2024 15:33
Comment on lines +102 to +104
if si.PrimaryAlias == nil {
return nil, fmt.Errorf("target shard %v has no primary tablet", shard)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is unrelated, but addresses a panic raised in the Vitess Slack where the target shard had no primary tablet.

@mattlord mattlord changed the title VReplication: Auto renew Keyspace Lock on traffic switch and VDiff init VReplication: Auto renew Keyspace Lock Jun 20, 2024
@mattlord mattlord changed the title VReplication: Auto renew Keyspace Lock VReplication: Auto renew lease on Keyspace Lock Jun 20, 2024
mattlord added 2 commits June 20, 2024 16:02
Signed-off-by: Matt Lord <[email protected]>
Can't range over a buffered channel to drain it w/o first
closing it. Just close it.

Signed-off-by: Matt Lord <[email protected]>
@mattlord mattlord force-pushed the vrepl_ks_lock_auto_renew branch from 13bfb01 to b1fa06d Compare June 20, 2024 22:04
Signed-off-by: Matt Lord <[email protected]>
@mattlord mattlord force-pushed the vrepl_ks_lock_auto_renew branch from 2172180 to 5dfe973 Compare June 21, 2024 14:58
Signed-off-by: Matt Lord <[email protected]>
@mattlord mattlord force-pushed the vrepl_ks_lock_auto_renew branch from 5dfe973 to 7c5c0db Compare June 21, 2024 15:00
Copy link

codecov bot commented Jun 21, 2024

Codecov Report

Attention: Patch coverage is 31.71806% with 155 lines in your changes missing coverage. Please review.

Project coverage is 68.56%. Comparing base (7a737f4) to head (9f9f13f).
Report is 2 commits behind head on main.

Files Patch % Lines
go/vt/vtctl/workflow/server.go 31.44% 109 Missing ⚠️
go/vt/vttablet/tabletmanager/vdiff/table_differ.go 0.00% 31 Missing ⚠️
go/vt/topo/keyspace_lock.go 58.06% 13 Missing ⚠️
go/vt/vtctl/workflow/resharder.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16240      +/-   ##
==========================================
- Coverage   68.61%   68.56%   -0.06%     
==========================================
  Files        1544     1544              
  Lines      197993   198176     +183     
==========================================
+ Hits       135848   135874      +26     
- Misses      62145    62302     +157     

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

@mattlord mattlord force-pushed the vrepl_ks_lock_auto_renew branch from 73f2808 to feca7a1 Compare June 21, 2024 17:21
Signed-off-by: Matt Lord <[email protected]>
@mattlord mattlord force-pushed the vrepl_ks_lock_auto_renew branch from feca7a1 to 9f9f13f Compare June 21, 2024 17:26
@mattlord
Copy link
Contributor Author

Replaced by: #16260

@mattlord mattlord closed this Jun 25, 2024
@mattlord mattlord deleted the vrepl_ks_lock_auto_renew branch October 1, 2024 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: VReplication NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work Type: Bug Type: Enhancement Logical improvement (somewhere between a bug and feature)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug Report: VDiff2 topo keyspace locks can be released too early
1 participant