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

sysvar tidb_read_staleness does not have a type #32763

Closed
morgo opened this issue Mar 2, 2022 · 1 comment · Fixed by #32794
Closed

sysvar tidb_read_staleness does not have a type #32763

morgo opened this issue Mar 2, 2022 · 1 comment · Fixed by #32794
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. type/enhancement The issue or PR belongs to an enhancement.

Comments

@morgo
Copy link
Contributor

morgo commented Mar 2, 2022

Enhancement

From code inspection:

{Scope: ScopeSession, Name: TiDBReadStaleness, Value: "", Hidden: false, SetSession: func(s *SessionVars, val string) error {
return setReadStaleness(s, val)
}},

It looks like the intention is that the value specified should be an integer, but the default for a system variable is TypeStr. If we change it to TypeInt, then we can set a minimum/maximum value and validation will automatically be performed to make sure it actually is an int (with MySQL-compatible error codes automatically returned)

This will improve this code:

if sVal == "" || sVal == "0" {
s.ReadStaleness = 0
return nil
}
if s.SnapshotTS != 0 {
return fmt.Errorf("tidb_snapshot should be clear before setting tidb_read_staleness")
}
sValue, err := strconv.ParseInt(sVal, 10, 32)
if err != nil {
return err
}

Since the error returned by ParseInt will not be reached.

@morgo morgo added type/enhancement The issue or PR belongs to an enhancement. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. labels Mar 2, 2022
@morgo
Copy link
Contributor Author

morgo commented Mar 2, 2022

cc @Yisaer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant