*: move config file option tidb_enable_auto_analyze to sysvar#34643
*: move config file option tidb_enable_auto_analyze to sysvar#34643ti-chi-bot merged 14 commits intopingcap:masterfrom
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. DetailsReviewer can indicate their review by submitting an approval review. |
|
cc @morgo |
|
Code Coverage Details: https://codecov.io/github/pingcap/tidb/commit/45f814d37f3de59c941f1c67104447eff5c4a98f |
morgo
left a comment
There was a problem hiding this comment.
LGTM, just one minor nit about skip-init.
domain/domain.go
Outdated
| do.SetStatsUpdating(true) | ||
| do.wg.Run(func() { do.updateStatsWorker(ctx, owner) }) | ||
| if RunAutoAnalyze { | ||
| if variable.RunAutoAnalyze.Load() { |
There was a problem hiding this comment.
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
FALSEand set toTRUE, the auto-analyze worker will not be invoked. - When it was
TRUEand 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!
| } | ||
|
|
||
| func TestOutdatedStatsCheck(t *testing.T) { | ||
| domain.RunAutoAnalyze = false |
There was a problem hiding this comment.
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.
It's false in the test suite. See the change in session/bootstrap.go:2012.
There was a problem hiding this comment.
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.
Agreed, an explicit update for UT is more solid. @Alkaagr81 could you update this?
There was a problem hiding this comment.
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.
We can however add an assertion that runautoanalyze is false. Reading the atomic value is no problem.
There was a problem hiding this comment.
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)
|
@Alkaagr81 Please resolve the conflict. |
|
/merge |
|
This pull request has been accepted and is ready to merge. DetailsCommit 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_analyzehas 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.