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 and accuracy of mysqld.GetVersionString #15096

Merged
merged 13 commits into from
Feb 1, 2024

Conversation

mattlord
Copy link
Contributor

@mattlord mattlord commented Jan 31, 2024

Description

The following vitess binaries call the tabletmanager FullStatus RPC:

  • vtorc: It runs it via refreshAllTablets() every 15 seconds by default
  • vtadmin: It runs it on the tablet view pages (I believe with a regular auto refresh)
  • vtctldclient: Any time the GetFullStatus command is used

In the vtorc (for sure) and vtadmin (I think) cases, it's run automatically and periodically. So over time, this RPC can be called many thousands of times on a tablet. And this RPC is merely one thing that ends up calling the VtMySQLRoot() function. This function was blindly prepending /usr/sbin: to the PATH and updating the environment variable every time it was called when VT_MYSQL_ROOT was not set:

vitess/go/vt/env/env.go

Lines 69 to 79 in 3147240

func VtMysqlRoot() (string, error) {
// if the environment variable is set, use that
if root := os.Getenv("VT_MYSQL_ROOT"); root != "" {
return root, nil
}
// otherwise let's look for mysqld in the PATH.
// ensure that /usr/sbin is included, as it might not be by default
// This is the default location for mysqld from packages.
newPath := fmt.Sprintf("/usr/sbin:%s", os.Getenv("PATH"))
os.Setenv("PATH", newPath)

In the case of the FullStatus RPC, it ends up there via:

  1. // Version string "majorVersion.minorVersion.patchRelease"
    version, err := tm.MysqlDaemon.GetVersionString(ctx)
  2. func (mysqld *Mysqld) GetVersionString(ctx context.Context) (string, error) {
  3. // GetVersionString runs mysqld --version and returns its output as a string
    func GetVersionString() (string, error) {
    noSocketFile()
    mysqlRoot, err := vtenv.VtMysqlRoot()

This ends up making a sys exec call to execute mysqld --version:

_, version, err := execCmd(mysqldPath, []string{"--version"}, nil, mysqlRoot, nil)

And every time we do this the PATH env var grows by 11 bytes as /usr/sbin: is prepended to it and saved in the env every time. When we exec the mysqld command it inherits a copy-on-write copy of the vttablet's env (with the ever growing PATH value) — because we set cmd.Env to nil. Eventually this will cause the execve call to fail with E2BIG (Argument list too long) as the the arguments and env size count against the ARG_MAX OS limit.

If you want to try and repeat it yourself, you can do so using this manual test: #15095 (comment)

I think that we should at least backport this to v18 since we expect everyone to be using vtorc, vtadmin, and vtctldclient.

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 Jan 31, 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 Jan 31, 2024
@github-actions github-actions bot added this to the v19.0.0 milestone Jan 31, 2024
Copy link

codecov bot commented Jan 31, 2024

Codecov Report

Attention: 7 lines in your changes are missing coverage. Please review.

Comparison is base (ebf0106) 47.70% compared to head (4cd461a) 47.79%.
Report is 6 commits behind head on main.

Files Patch % Lines
go/vt/mysqlctl/mysqld.go 0.00% 6 Missing ⚠️
go/vt/env/env.go 93.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15096      +/-   ##
==========================================
+ Coverage   47.70%   47.79%   +0.09%     
==========================================
  Files        1155     1155              
  Lines      240222   240319      +97     
==========================================
+ Hits       114596   114865     +269     
+ Misses     117021   116882     -139     
+ Partials     8605     8572      -33     

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

Signed-off-by: Matt Lord <[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.

I know this is a draft right now, but the changes look good to me! Thank-you for fixing this.

@mattlord mattlord 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 Jan 31, 2024
go/vt/env/env.go Outdated Show resolved Hide resolved
go/vt/mysqlctl/mysqld.go Outdated Show resolved Hide resolved
@@ -87,15 +93,15 @@ var (

replicationConnectRetry = 10 * time.Second

versionRegex = regexp.MustCompile(`Ver ([0-9]+)\.([0-9]+)\.([0-9]+)`)
versionRegex = regexp.MustCompile(fmt.Sprintf(`%s([0-9]+)\.([0-9]+)\.([0-9]+)`, versionStringPrefix))
Copy link
Member

Choose a reason for hiding this comment

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

I'm sure there's a good reason you changed this, but it doesn't feel necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just so that we're using the same const in the regex and where we build the string to match it when querying mysqld.

@mattlord mattlord removed the NeedsBackportReason If backport labels have been applied to a PR, a justification is required label Jan 31, 2024
@mattlord mattlord marked this pull request as ready for review January 31, 2024 07:08
go/vt/env/env.go Outdated Show resolved Hide resolved
go/vt/env/env.go Show resolved Hide resolved
@deepthi deepthi merged commit 6f9c5c2 into vitessio:main Feb 1, 2024
102 checks passed
@deepthi deepthi deleted the mysql_version branch February 1, 2024 15:22
vitess-bot pushed a commit that referenced this pull request Feb 1, 2024
frouioui pushed a commit that referenced this pull request Feb 1, 2024
…ring (#15096) (#15111)

Signed-off-by: Matt Lord <[email protected]>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
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.

Bug Report: GetFullStatus results in E2BIG
4 participants