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: use new topo named locks and TTL override for workflow coordination #16260

Merged
merged 15 commits into from
Jul 10, 2024

Conversation

mattlord
Copy link
Contributor

@mattlord mattlord commented Jun 25, 2024

Description

The VReplication and VDiff engines need to coordinate on workflows as the TableDiffer manipulates the associated workflow record (in the _vt.vreplication table) on its shard in order to initialize the diff (stopping the workflow, syncing up streams and snapshot positions, before restarting the workflow). In order to do so properly — meaning w/o impacting unrelated operations and thus able to use a lock that will not expire/be lost while work is in progress — they need a distributed lock in the topo server. Workflow information is, however, not stored in the topo server so there's no related record to lock. To address this gap, this PR adds support for named locks in the topo server. These are locks on an opaque name rather than a topo record/key. We then leverage this to lock the workflow using the unique name of targetkeyspace/workflowname.

Here's an example of their usage when running a vdiff with the local examples where the target keyspace is customer (which has 2 shards) and the workflow is commerce2customer:

❯ etcdctl watch --prefix=true /vitess/global/internal

PUT
/vitess/global/internal/named_locks/customer/commerce2customer/locks/7587879623616723911
{
  "Action": "vdiff",
  "HostName": "pslord.local",
  "UserName": "matt",
  "Time": "2024-06-25T14:51:21-04:00",
  "Status": "Running"
}
DELETE
/vitess/global/internal/named_locks/customer/commerce2customer/locks/7587879623616723911

PUT
/vitess/global/internal/named_locks/customer/commerce2customer/locks/7587879623616723958
{
  "Action": "vdiff",
  "HostName": "pslord.local",
  "UserName": "matt",
  "Time": "2024-06-25T14:51:21-04:00",
  "Status": "Running"
}
DELETE
/vitess/global/internal/named_locks/customer/commerce2customer/locks/7587879623616723958

There remains a general issue that the Keyspace locks taken during traffic switches — where we update various records in the topo related to routing rules, shard records, etc — can be lost after 30 seconds (by default, for etcd2topo). This PR also addresses this by adding a mechanism in the topo service, LockWithTTL, to override the default lock TTL for the topo implementation:

  • For etcd it's 30 seconds configured via the --topo_etcd_lease_ttl flag
  • For consul it's 15 seconds configured via the --topo_consul_lock_session_ttl flag
  • For ZooKeeper there is no default as it does not support TTLs

We also now check to confirm that we are holding the locks between major operations.

Please see the RFC for additional details: #16269

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

Copy link
Contributor

vitess-bot bot commented Jun 25, 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 25, 2024
@mattlord mattlord removed the NeedsIssue A linked issue is missing for this Pull Request label Jun 25, 2024
@github-actions github-actions bot added this to the v21.0.0 milestone Jun 25, 2024
@mattlord mattlord force-pushed the topo_named_locks branch 2 times, most recently from 25e6572 to f0cd253 Compare June 25, 2024 20:41
@mattlord mattlord removed the NeedsBackportReason If backport labels have been applied to a PR, a justification is required label Jun 25, 2024
And use that for VReplication workflows when coordination is
necessary, such as between the VReplicaiton engine and the VDiff
engine.

Signed-off-by: Matt Lord <mattalord@gmail.com>
Copy link

codecov bot commented Jun 25, 2024

Codecov Report

Attention: Patch coverage is 64.52991% with 83 lines in your changes missing coverage. Please review.

Project coverage is 68.69%. Comparing base (0db3577) to head (8de719a).

Files Patch % Lines
go/vt/vtctl/workflow/server.go 52.22% 43 Missing ⚠️
go/vt/topo/faketopo/faketopo.go 0.00% 8 Missing ⚠️
go/vt/topo/locks.go 77.14% 8 Missing ⚠️
go/vt/topo/consultopo/lock.go 53.84% 6 Missing ⚠️
go/vt/topo/etcd2topo/lock.go 40.00% 6 Missing ⚠️
go/vt/vttablet/tabletmanager/vdiff/table_differ.go 0.00% 5 Missing ⚠️
go/vt/topo/zk2topo/lock.go 0.00% 4 Missing ⚠️
...lient/command/vreplication/common/switchtraffic.go 0.00% 2 Missing ⚠️
go/vt/topo/memorytopo/lock.go 94.44% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16260      +/-   ##
==========================================
- Coverage   68.71%   68.69%   -0.02%     
==========================================
  Files        1547     1548       +1     
  Lines      198287   198444     +157     
==========================================
+ Hits       136243   136330      +87     
- Misses      62044    62114      +70     

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

@mattlord mattlord changed the title VReplication: use new topo named locks for workflow coordination VReplication: use new topo named locks and TTL override for workflow coordination Jun 26, 2024
@mattlord mattlord added Type: Bug Type: Enhancement Logical improvement (somewhere between a bug and feature) Component: VReplication and removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says labels Jun 26, 2024
@mattlord mattlord force-pushed the topo_named_locks branch 3 times, most recently from 49747a4 to ee7ff15 Compare June 26, 2024 14:43
Signed-off-by: Matt Lord <mattalord@gmail.com>
@mattlord mattlord force-pushed the topo_named_locks branch 2 times, most recently from b3ffc7e to 0809dad Compare June 27, 2024 15:37
mattlord added 2 commits June 28, 2024 10:35
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
go/vt/topo/shard_lock.go Show resolved Hide resolved
go/vt/topo/locks.go Outdated Show resolved Hide resolved
go/vt/vtctl/workflow/server.go Outdated Show resolved Hide resolved
go/vt/vtctl/workflow/server.go Outdated Show resolved Hide resolved
go/vt/vtctl/workflow/server.go Show resolved Hide resolved
go/vt/vtctl/workflow/server.go Outdated Show resolved Hide resolved
go/vt/vtctl/workflow/server.go Show resolved Hide resolved
go/vt/vtctl/workflow/server.go Show resolved Hide resolved
Signed-off-by: Matt Lord <mattalord@gmail.com>
@mattlord mattlord force-pushed the topo_named_locks branch 2 times, most recently from 8a63b31 to 321c4f0 Compare June 29, 2024 17:00
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
mattlord added 3 commits June 30, 2024 11:59
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
mattlord added 3 commits July 8, 2024 10:00
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
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!

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.

Nice work!

Signed-off-by: Matt Lord <mattalord@gmail.com>
@mattlord mattlord merged commit 16b05c1 into vitessio:main Jul 10, 2024
94 checks passed
@mattlord mattlord deleted the topo_named_locks branch July 10, 2024 02:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: VReplication Type: Bug Type: Enhancement Logical improvement (somewhere between a bug and feature)
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Bug Report: VDiff2 topo keyspace locks can be released too early
3 participants