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, variable: move gc special sysvars to getters/setters #24896

Merged
merged 13 commits into from
Aug 18, 2021

Conversation

morgo
Copy link
Contributor

@morgo morgo commented May 25, 2021

What problem does this PR solve?

Problem Summary:

Currently setting GC sysvars is kind of invasive in the session package. This is because they required to be available as sysvars so that the mysql.tidb table could be hidden for SEM, but there was not yet a standard way in the sysvar system to write code on get/set special values.

This moves the special code directly into getters and setters. The functionality is the same, and covered by existing tests.

What is changed and how it works?

What's Changed:

Internal refactoring of code.

Related changes

  • None

Check List

Tests

  • Unit test (covered by existing tests)

Side effects

  • None

Release note

  • No release note

@ti-chi-bot ti-chi-bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label May 25, 2021
@github-actions github-actions bot added the sig/sql-infra SIG: SQL Infra label May 25, 2021
Comment on lines -521 to +522
c.Assert(val, Equals, strconv.FormatUint(uint64(atomic.LoadUint32(&config.GetGlobalConfig().Log.RecordPlanInSlowLog)), 10))
enabled := atomic.LoadUint32(&config.GetGlobalConfig().Log.RecordPlanInSlowLog) == 1
c.Assert(val, Equals, BoolToOnOff(enabled))
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 is a boolean typed value, but it was previously returning "1" instead of "ON/OFF". Because this code cahnge now calls validation on getters, it needed to be fixed.

Comment on lines +1956 to +1973
// SQLModeVar is the name of the 'sql_mode' system variable.
SQLModeVar = "sql_mode"
// CharacterSetResults is the name of the 'character_set_results' system variable.
CharacterSetResults = "character_set_results"
// MaxAllowedPacket is the name of the 'max_allowed_packet' system variable.
MaxAllowedPacket = "max_allowed_packet"
// TimeZone is the name of the 'time_zone' system variable.
TimeZone = "time_zone"
// TxnIsolation is the name of the 'tx_isolation' system variable.
TxnIsolation = "tx_isolation"
// TransactionIsolation is the name of the 'transaction_isolation' system variable.
TransactionIsolation = "transaction_isolation"
// TxnIsolationOneShot is the name of the 'tx_isolation_one_shot' system variable.
TxnIsolationOneShot = "tx_isolation_one_shot"
// MaxExecutionTime is the name of the 'max_execution_time' system variable.
MaxExecutionTime = "max_execution_time"
// ReadOnly is the name of the 'read_only' system variable.
ReadOnly = "read_only"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are moved from sessionctx/variable/session.go. They are technically not related to this PR, but its a small change.

Comment on lines -1013 to -1119
if name == variable.TiDBSlowLogMasking {
name = variable.TiDBRedactLog
}
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 is now handled by a getter on TiDBSlowLogMasking.

Comment on lines +138 to +144
val, err := sv.GetGlobal(s)
if err != nil {
return val, err
}
// Ensure that the results from the getter are validated
// Since some are read directly from tables.
return sv.ValidateWithRelaxedValidation(s, val, ScopeGlobal), nil
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 is required because in many case getters are reading from table values and accept user input directly without normalization. ValidateWithRelaxedValidation is the same function that is called when init'ing a new session and assigning values to the session variables.

Comment on lines +1490 to +1491
enabled := atomic.LoadUint32(&config.GetGlobalConfig().Log.RecordPlanInSlowLog) == 1
return BoolToOnOff(enabled), nil
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 is technically a bug: a bool type should return the string value "ON/OFF". It is fixed here because the validation added converts it to ON/OFF anyway, which broke a test for this value.

@morgo morgo requested a review from a team May 31, 2021 16:22
@morgo morgo requested a review from a team June 9, 2021 00:34
Copy link
Contributor

@xhebox xhebox left a comment

Choose a reason for hiding this comment

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

Rest LGTM

sessionctx/variable/sysvar.go Outdated Show resolved Hide resolved
@ti-chi-bot
Copy link
Member

ti-chi-bot commented Jun 11, 2021

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • bb7133
  • 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 the status/LGT1 Indicates that a PR has LGTM 1. label Jun 11, 2021
@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 5, 2021
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 5, 2021
@morgo morgo requested a review from bb7133 August 10, 2021 05:34
@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 Aug 18, 2021
@bb7133
Copy link
Member

bb7133 commented Aug 18, 2021

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: dd5c8a6

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Aug 18, 2021
@ti-chi-bot
Copy link
Member

@morgo: Your PR was out of date, I have automatically updated it for you.

At the same time I will also trigger all tests for you:

/run-all-tests

If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot ti-chi-bot merged commit 79f0b49 into pingcap:master Aug 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/sql-infra SIG: SQL Infra size/XL Denotes a PR that changes 500-999 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.

4 participants