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

Improve efficiency of vtorc topo calls #17071

Merged
merged 12 commits into from
Nov 6, 2024

Conversation

timvaillancourt
Copy link
Contributor

@timvaillancourt timvaillancourt commented Oct 25, 2024

Description

This PR adds a similar optimization to this PR to vtorc by moving to using ts.GetTabletsByCell(...) and the new ts.GetTabletsByShard(...) methods to fetch tablets. These methods respect the concurrency limit flag for the topo and seem to be more efficient overall

Support for filtering by keyspace/shard was added to ts.GetTabletsByCell(...) which is called by ts.GetTabletsByShard(...)

Related to this discussion, we're unfortunately forced to fetch "all" records from the cell just to filter them out by keyspace/shard using x != y. In our production when fetching topo records for a single shard, < 0.5% of the topo records fetched are actually used - but that's nothing new

Related Issue(s)

Resolves #17073

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

@timvaillancourt timvaillancourt added Type: Enhancement Logical improvement (somewhere between a bug and feature) Component: VTorc Vitess Orchestrator integration labels Oct 25, 2024
Copy link
Contributor

vitess-bot bot commented Oct 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 Oct 25, 2024
@github-actions github-actions bot added this to the v22.0.0 milestone Oct 25, 2024
@timvaillancourt timvaillancourt removed 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 Oct 25, 2024
Copy link

codecov bot commented Oct 31, 2024

Codecov Report

Attention: Patch coverage is 15.94203% with 58 lines in your changes missing coverage. Please review.

Project coverage is 67.41%. Comparing base (fa5a2c5) to head (707ad06).
Report is 19 commits behind head on main.

Files with missing lines Patch % Lines
go/vt/topo/shard.go 0.00% 54 Missing ⚠️
go/vt/vtorc/logic/tablet_discovery.go 0.00% 3 Missing ⚠️
go/vt/topo/tablet.go 90.90% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #17071      +/-   ##
==========================================
+ Coverage   67.17%   67.41%   +0.23%     
==========================================
  Files        1571     1569       -2     
  Lines      252246   252171      -75     
==========================================
+ Hits       169458   170002     +544     
+ Misses      82788    82169     -619     

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

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
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 is looking good! ❤️ I only had some minor nits and suggestions. Let me know what you think.

go/vt/topo/shard.go Outdated Show resolved Hide resolved
go/vt/topo/shard.go Show resolved Hide resolved
go/vt/topo/shard.go Outdated Show resolved Hide resolved
go/vt/topo/shard.go Outdated Show resolved Hide resolved
go/vt/topo/shard.go Outdated Show resolved Hide resolved
go/vt/topo/shard.go Outdated Show resolved Hide resolved
go/vt/topo/tablet.go Outdated Show resolved Hide resolved
go/vt/topo/tablet.go Outdated Show resolved Hide resolved
go/vt/topo/tablet.go Outdated Show resolved Hide resolved
@mattlord mattlord removed the NeedsBackportReason If backport labels have been applied to a PR, a justification is required label Oct 31, 2024
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.

Apart from Matt's comments, everything else LGTM. It can be merged once they have been addressed.

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
@timvaillancourt
Copy link
Contributor Author

Thanks for the review! Updated with @mattlord's suggestions 👍

@timvaillancourt timvaillancourt added the Backport to: release-19.0 Needs to be back ported to release-19.0 label Nov 4, 2024
@timvaillancourt
Copy link
Contributor Author

Whoops, meant to add ^^^ backport labels to a different PR. Removed

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
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.

We're super close! I really only had the one open question about shard filtering when there's no Keyspace provided.

go/vt/topo/shard.go Show resolved Hide resolved
go/vt/topo/tablet.go Outdated Show resolved Hide resolved
go/vt/topo/tablet_test.go Show resolved Hide resolved
go/vt/topo/tablet.go Outdated Show resolved Hide resolved
go/vt/topo/tablet_test.go Outdated Show resolved Hide resolved
timvaillancourt and others added 2 commits November 4, 2024 23:21
Co-authored-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
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.

Looking good! The only remaining issue is whether or not we want to support filtering by shard w/o a keyspace. I'm OK either way, but if we do want to support that then we should add a test case for it. That make sense?

go/vt/topo/shard.go Outdated Show resolved Hide resolved
go/vt/topo/tablet.go Outdated Show resolved Hide resolved
go/vt/topo/tablet_test.go Outdated Show resolved Hide resolved
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
@timvaillancourt
Copy link
Contributor Author

The only remaining issue is whether or not we want to support filtering by shard w/o a keyspace

@mattlord I don't plan to support this because I can't think of a use case. I've updated to make keyspace required 👍

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
go/vt/topo/tablet.go Outdated Show resolved Hide resolved
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
go/vt/topo/tablet.go Show resolved Hide resolved
go/vt/topo/tablet.go Outdated Show resolved Hide resolved
@mattlord
Copy link
Contributor

mattlord commented Nov 5, 2024

Looks like the new unit test is flaky:

That's the only thing left! Thank you for sticking this out, @timvaillancourt ! This will be a nice improvement.

@timvaillancourt
Copy link
Contributor Author

Hmm, this flakiness is weird. Perhaps I need to sort the tt.expectedTablets but I thought that wasn't necessary 🤔

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
@timvaillancourt
Copy link
Contributor Author

@mattlord I believe moving tt.keyspaceShards to keyspaceShards []*topo.KeyspaceShard (from a map) will fix this flakiness 👍

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.

Great work on this, @timvaillancourt ! You can merge any time, just please don't forget to squash and merge.

One last note, up to you if you want to add it:


			slices.SortFunc(out, func(i, j *topo.TabletInfo) int {
				return cmp.Compare(i.Alias.Uid, j.Alias.Uid)
			})
			for i, tablet := range out {
				expected := tt.expectedTablets[i]
				require.Equal(t, expected.Alias.String(), tablet.Alias.String())
				require.Equal(t, expected.Keyspace, tablet.Keyspace)
				require.Equal(t, expected.Shard, tablet.Shard)
			}

Right now you're ordering all of the entries in expectedTablets by Uid in the test cases. IMO it's worth sorting that slice as well so that things do not become flaky in the future if someone modifies the existing test cases or adds new ones where that slice is not ordered:


			slices.SortFunc(out, func(i, j *topo.TabletInfo) int {
				return cmp.Compare(i.Alias.Uid, j.Alias.Uid)
			})
			slices.SortFunc(tt.expectedTablets, func(i, j *topo.TabletInfo) int {
				return cmp.Compare(i.Alias.Uid, j.Alias.Uid)
			})
			for i, tablet := range out {
				expected := tt.expectedTablets[i]
				require.Equal(t, expected.Alias.String(), tablet.Alias.String())
				require.Equal(t, expected.Keyspace, tablet.Keyspace)
				require.Equal(t, expected.Shard, tablet.Shard)
			}

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
@timvaillancourt
Copy link
Contributor Author

@mattlord thanks for the reviews, added that!

@timvaillancourt timvaillancourt merged commit a575982 into vitessio:main Nov 6, 2024
98 checks passed
@timvaillancourt timvaillancourt deleted the vtorc-GetTabletsByCell branch November 6, 2024 17:34
timvaillancourt added a commit to slackhq/vitess that referenced this pull request Nov 8, 2024
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
Co-authored-by: Matt Lord <mattalord@gmail.com>
timvaillancourt added a commit to slackhq/vitess that referenced this pull request Nov 12, 2024
* Move to native sqlite3 queries (vitessio#17124)

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
Co-authored-by: Tim Vaillancourt <tim@timvaillancourt.com>

* missing updates

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>

* fix %

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>

* missing comma

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>

* Improve efficiency of `vtorc` topo calls  (vitessio#17071)

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
Co-authored-by: Matt Lord <mattalord@gmail.com>

---------

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
Co-authored-by: Dirkjan Bussink <d.bussink@gmail.com>
Co-authored-by: Matt Lord <mattalord@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: VTorc Vitess Orchestrator integration 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: vtorc to support --topo_read_concurrency limit
3 participants