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

Topology Server Locking Refactor #16005

Merged
merged 11 commits into from
Jun 12, 2024

Conversation

GuptaManan100
Copy link
Member

@GuptaManan100 GuptaManan100 commented May 24, 2024

Description

This PR refactors the resource locking in the topology server.

Vitess has had the ability to lock shards and keyspaces for a long time. We recently added the code to also lock routing rules in #15807 and noticed that the code for locking the three resources was essentially the same with minor differences.

It is a good idea to refactor all of this code such that the locking and unlocking code is common for all three resources. This PR accomplishes this goal. Since locking of shards and keyspace is very crucial to the correct functionality of Vitess, we have added tests for all the three supported topo servers in addition to the unit tests to ensure that the functionality of locking is unchanged by the refactor.

This refactor also allows addition of new resources to be locked quite easily, since only an interface implementation of iTopoLock is required.

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

Deployment Notes

Copy link
Contributor

vitess-bot bot commented May 24, 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 May 24, 2024
@github-actions github-actions bot added this to the v20.0.0 milestone May 24, 2024
Copy link

codecov bot commented May 24, 2024

Codecov Report

Attention: Patch coverage is 96.05263% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 68.23%. Comparing base (a1edaee) to head (febce16).
Report is 14 commits behind head on main.

Files Patch % Lines
go/vt/topo/locks.go 89.28% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16005      +/-   ##
==========================================
- Coverage   68.24%   68.23%   -0.01%     
==========================================
  Files        1562     1542      -20     
  Lines      197171   196969     -202     
==========================================
- Hits       134550   134394     -156     
+ Misses      62621    62575      -46     

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

@GuptaManan100 GuptaManan100 added Type: Internal Cleanup Component: Cluster management Component: Topology 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 May 24, 2024
@GuptaManan100 GuptaManan100 marked this pull request as ready for review May 24, 2024 09:27
Copy link
Contributor

@mattlord mattlord left a comment

Choose a reason for hiding this comment

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

This looks great! Thank you @GuptaManan100 ! ❤️ I only had one comment that I think is worth discussing before approval. What you have now is equivalent to what we already have, so we could leave it as-is and change later, but it's a relatively easy change and I think it's worth doing now if we can. Let me know what you think.

One other general question.. I thought that we were going to effectively make CheckKeyspaceLockedAndRenew be CheckKeyspaceLocked. I think we did that here, but it wasn't clear from the diff so wanted to double check.

Thanks again!

go/test/endtoend/topotest/utils/utils.go Outdated Show resolved Hide resolved
go/vt/topo/locks.go Outdated Show resolved Hide resolved
go/vt/topo/locks.go Outdated Show resolved Hide resolved
go/vt/topo/routing_rules_lock.go Outdated Show resolved Hide resolved
go/vt/topo/routing_rules_lock.go Show resolved Hide resolved
@GuptaManan100
Copy link
Member Author

GuptaManan100 commented May 30, 2024

I should have called out the changes in CheckKeyspaceLockedAndRenew and CheckKeyspaceLocked in the description.

The problem with the earlier implementation was that it was wrong. After looking at the code, I realised that whether the lock is renewed or not when we call Check in the lock descriptor depends on the implementation. In etcd, we are renewing the lease, but not so in Consul and ZooKeeper. That is why I merged the two functions together, because CheckKeyspaceLocked wasn't calling Check in the lock descriptor, but it is required to check whether the lock is still held, but when we do call it, it will sometimes renew the lease like in etcd.

@deepthi deepthi removed this from the v20.0.0 milestone May 30, 2024
@GuptaManan100 GuptaManan100 added this to the v21.0.0 milestone Jun 4, 2024
Copy link
Contributor

@mattlord mattlord left a comment

Choose a reason for hiding this comment

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

The only open issue is the lock path issue but I will defer to @rohit-nayak-ps on that (he has the larger refactor in mind better than I do). I'm fine keeping it as-is. I don't think there would be major upgrade issues there if we did later change it, since keyspace routing rules are experimental and we haven't added locking for the other types yet. Thanks again! Nice work on this @GuptaManan100

@GuptaManan100
Copy link
Member Author

Thank you @mattlord! Now that release-20 has been cut, are we good to be able to merge this?

@mattlord
Copy link
Contributor

mattlord commented Jun 6, 2024

Thank you @mattlord! Now that release-20 has been cut, are we good to be able to merge this?

IMO at least, yes. 🙂

Copy link
Contributor

@rohit-nayak-ps rohit-nayak-ps left a comment

Choose a reason for hiding this comment

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

❤️

@GuptaManan100 GuptaManan100 merged commit 3f2d096 into vitessio:main Jun 12, 2024
93 checks passed
@GuptaManan100 GuptaManan100 deleted the topo-lock-refactor branch June 12, 2024 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants