-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
*: move config file option tidb_enable_auto_analyze to sysvar #34643
*: move config file option tidb_enable_auto_analyze to sysvar #34643
Conversation
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
cc @morgo |
Code Coverage Details: https://codecov.io/github/pingcap/tidb/commit/45f814d37f3de59c941f1c67104447eff5c4a98f |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just one minor nit about skip-init.
domain/domain.go
Outdated
@@ -1328,7 +1325,7 @@ func (do *Domain) UpdateTableStatsLoop(ctx sessionctx.Context) error { | |||
} | |||
do.SetStatsUpdating(true) | |||
do.wg.Run(func() { do.updateStatsWorker(ctx, owner) }) | |||
if RunAutoAnalyze { | |||
if variable.RunAutoAnalyze.Load() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing the code here does not take effect actually, because UpdateTableStatsLoop
is only called on the bootstrap stage of TiDB if you check the code in BootstrapSession()
.
This is fine before because when it is changed in the configuration file, TiDB always needs to restart and the BootstrapSession()
is called, but making it a sysvar means it the value can be changed dynamically, so:
- When it was
FALSE
and set toTRUE
, the auto-analyze worker will not be invoked. - When it was
TRUE
and set toFALSE
, the auto-analyze worker will still be there.
You can easily verify it by, for example, adding a log in HandleAutoAnalyze()
.
So my suggestion is removing the if
here:
// always runs the loop
do.wg.Run(func() { do.autoAnalyzeWorker(owner) })
And moving if
to here like:
select {
case <-analyzeTicker.C:
if owner.IsOwner() && variable.RunAutoAnalyze.Load() {
statsHandle.HandleAutoAnalyze(do.InfoSchema())
}
case <-do.exit:
return
}
So that the sysvar takes effect really.
@chrysan Please let me know if you have any comment on it, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -499,7 +498,6 @@ func TestAnalyzeLongString(t *testing.T) { | |||
} | |||
|
|||
func TestOutdatedStatsCheck(t *testing.T) { | |||
domain.RunAutoAnalyze = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the default value of RunAutoAnalyze
is true
, I think simply removing it may cause some trouble. @chrysan PTAL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's false in the test suite. See the change in session/bootstrap.go:2012.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer to keep the variable set in ut or at least an assertion to make the ut safe no matter what has been changed in variable module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, an explicit update for UT is more solid. @Alkaagr81 could you update this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with setting it in the test is:
- If you update the atomic directly, it can get overwritten when the sysvar cache is updated. This is because the sysvar cache calls the SetGlobal func with the value from the mysql.global_variables.
- To safely change it, tk.MustExec("set global sysvar=x") must be used. But tk is not available in all of the tests. We could add it, but it's quite a bit more code to set up each time.
This is why it uses the bootstrap to disable auto-analyze instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can however add an assertion that runautoanalyze is false. Reading the atomic value is no problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, an alternative way is to create it as another 'enhancement' issue as a backlog, then we could make this PR delivered with the next version(v6.1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forked to #34792
@Alkaagr81 Please resolve the conflict. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/merge |
This pull request has been accepted and is ready to merge. Commit hash: 70d5032
|
As discussed, we will handle the upgrade step for this in #34711 |
TiDB MergeCI notify🔴 Bad News! New failing [1] after this pr merged.
|
What problem does this PR solve?
Issue Number: ref #33769
Problem Summary:
The option
tidb_enable_auto_analyze
has historically been a config option. But based on requirements from cloud & PM it should instead be a sysvar scope Global.What is changed and how it works?
Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.