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

*: move config file option tidb_enable_auto_analyze to sysvar #34643

Merged
merged 14 commits into from May 18, 2022

Conversation

Alkaagr81
Copy link
Collaborator

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

  • 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

Please refer to Release Notes Language Style Guide to write a quality release note.

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.

@Alkaagr81 Alkaagr81 requested a review from a team as a code owner May 13, 2022 16:43
@ti-chi-bot
Copy link
Member

ti-chi-bot commented May 13, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • bb7133
  • morgo

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 size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 13, 2022
@Alkaagr81
Copy link
Collaborator Author

cc @morgo

@sre-bot
Copy link
Contributor

sre-bot commented May 13, 2022

session/bootstrap.go Outdated Show resolved Hide resolved
config/config.go Show resolved Hide resolved
session/bootstrap.go Outdated Show resolved Hide resolved
Copy link
Contributor

@morgo morgo left a 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.

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label May 16, 2022
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() {
Copy link
Member

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 to TRUE, the auto-analyze worker will not be invoked.
  • When it was TRUE and set to FALSE, 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!

Copy link
Contributor

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
Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Member

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?

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Member

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)

Copy link
Contributor

Choose a reason for hiding this comment

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

Forked to #34792

@morgo morgo mentioned this pull request May 17, 2022
12 tasks
@bb7133
Copy link
Member

bb7133 commented May 18, 2022

@Alkaagr81 Please resolve the conflict.

@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 18, 2022
Copy link
Member

@bb7133 bb7133 left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot removed the status/LGT1 Indicates that a PR has LGTM 1. label May 18, 2022
@ti-chi-bot ti-chi-bot added the status/LGT2 Indicates that a PR has LGTM 2. label May 18, 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 May 18, 2022
@morgo
Copy link
Contributor

morgo commented May 18, 2022

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: 70d5032

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label May 18, 2022
@morgo morgo added the compatibility-breaker Violation of forwards/backwards compatibility in a design-time piece. label May 18, 2022
@ti-chi-bot ti-chi-bot merged commit eae2ae8 into pingcap:master May 18, 2022
@morgo
Copy link
Contributor

morgo commented May 18, 2022

As discussed, we will handle the upgrade step for this in #34711

@sre-bot
Copy link
Contributor

sre-bot commented May 18, 2022

TiDB MergeCI notify

🔴 Bad News! New failing [1] after this pr merged.
These new failed integration tests seem to be caused by the current PR, please try to fix these new failed integration tests, thanks!

CI Name Result Duration Compare with Parent commit
idc-jenkins-ci-tidb/integration-common-test 🟥 failed 2, success 9, total 11 7 min 27 sec New failing
idc-jenkins-ci/integration-cdc-test 🟢 all 34 tests passed 24 min Existing passed
idc-jenkins-ci-tidb/mybatis-test 🟢 all 1 tests passed 6 min 51 sec Existing passed
idc-jenkins-ci-tidb/common-test 🟢 all 12 tests passed 6 min 11 sec Existing passed
idc-jenkins-ci-tidb/integration-ddl-test 🟢 all 6 tests passed 6 min 3 sec Existing passed
idc-jenkins-ci-tidb/sqllogic-test-2 🟢 all 28 tests passed 5 min 44 sec Existing passed
idc-jenkins-ci-tidb/sqllogic-test-1 🟢 all 26 tests passed 5 min 44 sec Existing passed
idc-jenkins-ci-tidb/tics-test 🟢 all 1 tests passed 5 min 32 sec Existing passed
idc-jenkins-ci-tidb/integration-compatibility-test 🟢 all 1 tests passed 5 min 17 sec Existing passed
idc-jenkins-ci-tidb/plugin-test 🟢 build success, plugin test success 4min Existing passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility-breaker Violation of forwards/backwards compatibility in a design-time piece. release-note size/M Denotes a PR that changes 30-99 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.

None yet

6 participants