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

session, sessionctx: Make sysvar tidb_read_staleness TypeInt #32794

Merged
merged 17 commits into from
Apr 6, 2022

Conversation

TszKitLo40
Copy link
Contributor

@TszKitLo40 TszKitLo40 commented Mar 3, 2022

What problem does this PR solve?

Issue Number: close #32763

Problem Summary:

What is changed and how it works?

Make sysvar tidb_read_staleness TypeInt

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

None

@TszKitLo40 TszKitLo40 requested a review from a team as a code owner March 3, 2022 07:21
@ti-chi-bot
Copy link
Member

ti-chi-bot commented Mar 3, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • morgo
  • xhebox

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added release-note-none Denotes a PR that doesn't merit a release note. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Mar 3, 2022
@TszKitLo40
Copy link
Contributor Author

/cc @morgo

@ti-chi-bot ti-chi-bot requested a review from morgo March 3, 2022 07:21
@ti-chi-bot ti-chi-bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Mar 3, 2022
@@ -5828,7 +5828,8 @@ func (s *testSessionSuite) TestTiDBReadStaleness(c *C) {
c.Assert(err, NotNil)
err = tk.ExecToErr("set @@tidb_read_staleness='foo'")
c.Assert(err, NotNil)
tk.MustExec("set @@tidb_read_staleness=''")
err = tk.ExecToErr("set @@tidb_read_staleness='100'")
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 case will fail in CI, I think it should be checked in sysvar.go.

Copy link
Contributor

Choose a reason for hiding this comment

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

If this only supports negative values, we should test one of those too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@morgo But why set @@tidb_read_staleness='100' can succeed now? Because the MaxValue is 0, shouldn't the validation will automatically be performed?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes it should. We don't have any other examples where the range is been -val and 0 though, maybe there is a bug?

My point was that we should test that -100 is tested, as an example of an expected valid value.

Copy link
Contributor Author

@TszKitLo40 TszKitLo40 Mar 4, 2022

Choose a reason for hiding this comment

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

The minValue and maxValue is checked in checkInt64SystemVar, but it won't throw an error, only the warning is appended and the value will be set to minValue or maxValue if needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh yes! The MySQL behavior is to autoconvert to the closest permitted value + raise a warning. This is the case since #25686 It is only wrong typed values that will error.

If you modify the test to read back the value, it should be zero?

Copy link
Contributor Author

@TszKitLo40 TszKitLo40 Mar 5, 2022

Choose a reason for hiding this comment

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

I think yes. Do yo think we need to check it in the test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any modification is needed for this PR? @morgo

Copy link
Contributor

@djshow832 djshow832 left a comment

Choose a reason for hiding this comment

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

Is it backward compatible? When a user sets the value in an older version, and then upgrades to this version, what will happen?

@TszKitLo40
Copy link
Contributor Author

set @@tidb_read_staleness=''

I think the affected statement is set @@tidb_read_staleness='', because the type of tidb_read_staleness should be int.

sessionctx/variable/sysvar.go Outdated Show resolved Hide resolved
@@ -5828,7 +5828,8 @@ func (s *testSessionSuite) TestTiDBReadStaleness(c *C) {
c.Assert(err, NotNil)
err = tk.ExecToErr("set @@tidb_read_staleness='foo'")
c.Assert(err, NotNil)
tk.MustExec("set @@tidb_read_staleness=''")
err = tk.ExecToErr("set @@tidb_read_staleness='100'")
Copy link
Contributor

Choose a reason for hiding this comment

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

If this only supports negative values, we should test one of those too.

@morgo
Copy link
Contributor

morgo commented Mar 3, 2022

Is it backward compatible? When a user sets the value in an older version, and then upgrades to this version, what will happen?

The variable is only session scoped, so we never persist the meta data. But I provided a comment on how to still accept empty if applications do this.

You are right though, that this is still a concern for variables that include global scope. I have a PR @ #31583 - looking for your review :-)

@ti-chi-bot ti-chi-bot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Mar 4, 2022
@morgo
Copy link
Contributor

morgo commented Mar 4, 2022

/run-unit-test

@sre-bot
Copy link
Contributor

sre-bot commented Mar 4, 2022

@morgo morgo self-requested a review March 9, 2022 03:48
@ti-chi-bot ti-chi-bot added status/LGT1 Indicates that a PR has LGTM 1. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Mar 9, 2022
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 14, 2022
@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 16, 2022
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 17, 2022
@TszKitLo40
Copy link
Contributor Author

@morgo Can anyone help me review and merge this PR?

@morgo morgo requested a review from djshow832 March 21, 2022 02:25
@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 3, 2022
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 6, 2022
@TszKitLo40
Copy link
Contributor Author

/cc @xhebox

@ti-chi-bot ti-chi-bot requested a review from xhebox April 6, 2022 02:44
@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Apr 6, 2022
@xhebox
Copy link
Contributor

xhebox commented Apr 6, 2022

/hold
@TszKitLo40 It seems check_dev fails?

@ti-chi-bot ti-chi-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 6, 2022
@xhebox
Copy link
Contributor

xhebox commented Apr 6, 2022

/unhold
/merge

@ti-chi-bot ti-chi-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 6, 2022
@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: abaa9a2

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Apr 6, 2022
@TszKitLo40
Copy link
Contributor Author

I think it has been fixed. @xhebox

@ti-chi-bot ti-chi-bot merged commit b37b3b1 into pingcap:master Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none Denotes a PR that doesn't merit a release note. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sysvar tidb_read_staleness does not have a type
6 participants