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

variable: fix information_schema.VARIABLES_INFO DEFAULT_VALUE not right problem #49524

Merged
merged 11 commits into from
Jan 11, 2024

Conversation

jiyfhust
Copy link
Contributor

@jiyfhust jiyfhust commented Dec 17, 2023

What problem does this PR solve?

Issue Number: close #49461, close #49968, close #50155

Problem Summary:

What changed and how does it work?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Without this pr, deploy a cluster:

mysql> select VARIABLE_NAME, VARIABLE_SCOPE, DEFAULT_VALUE, CURRENT_VALUE from information_schema.VARIABLES_INFO where DEFAULT_VALUE != CURRENT_VALUE and variable_name in ('tidb_txn_mode', 'tidb_enable_async_commit','tidb_enable_1pc', 'tidb_mem_oom_action', 'tidb_enable_auto_analyze', 'tidb_row_format_version', 'tidb_txn_assertion_level', 'tidb_enable_mutation_checker', 'tidb_pessimistic_txn_fair_locking');
+-----------------------------------+----------------+---------------+---------------+
| VARIABLE_NAME                     | VARIABLE_SCOPE | DEFAULT_VALUE | CURRENT_VALUE |
+-----------------------------------+----------------+---------------+---------------+
| tidb_row_format_version           | SESSION,GLOBAL | 1             | 2             |
| tidb_pessimistic_txn_fair_locking | SESSION,GLOBAL | OFF           | ON            |
| tidb_enable_async_commit          | SESSION,GLOBAL | OFF           | ON            |
| tidb_enable_mutation_checker      | SESSION,GLOBAL | OFF           | ON            |
| tidb_txn_mode                     | SESSION,GLOBAL |               | pessimistic   |
| tidb_txn_assertion_level          | SESSION,GLOBAL | OFF           | FAST          |
| tidb_enable_1pc                   | SESSION,GLOBAL | OFF           | ON            |
+-----------------------------------+----------------+---------------+---------------+
7 rows in set (0.07 sec)

With this pr:


mysql> select VARIABLE_NAME, VARIABLE_SCOPE, DEFAULT_VALUE, CURRENT_VALUE from information_schema.VARIABLES_INFO where DEFAULT_VALUE != CURRENT_VALUE and variable_name in ('tidb_txn_mode', 'tidb_enable_async_commit','tidb_enable_1pc', 'tidb_mem_oom_action', 'tidb_enable_auto_analyze', 'tidb_row_format_version', 'tidb_txn_assertion_level', 'tidb_enable_mutation_checker', 'tidb_pessimistic_txn_fair_locking');
Empty set (0.01 sec)


mysql> select VARIABLE_NAME, VARIABLE_SCOPE, DEFAULT_VALUE, CURRENT_VALUE from information_schema.VARIABLES_INFO where variable_name in ('tidb_txn_mode', 'tidb_enable_async_commit','tidb_enable_1pc', 'tidb_mem_oom_action', 'tidb_enable_auto_analyze', 'tidb_row_format_version', 'tidb_txn_assertion_level', 'tidb_enable_mutation_checker', 'tidb_pessimistic_txn_fair_locking');
+-----------------------------------+----------------+---------------+---------------+
| VARIABLE_NAME                     | VARIABLE_SCOPE | DEFAULT_VALUE | CURRENT_VALUE |
+-----------------------------------+----------------+---------------+---------------+
| tidb_mem_oom_action               | GLOBAL         | CANCEL        | CANCEL        |
| tidb_enable_1pc                   | SESSION,GLOBAL | ON            | ON            |
| tidb_enable_async_commit          | SESSION,GLOBAL | ON            | ON            |
| tidb_enable_auto_analyze          | GLOBAL         | ON            | ON            |
| tidb_row_format_version           | SESSION,GLOBAL | 2             | 2             |
| tidb_txn_mode                     | SESSION,GLOBAL | pessimistic   | pessimistic   |
| tidb_pessimistic_txn_fair_locking | SESSION,GLOBAL | ON            | ON            |
| tidb_txn_assertion_level          | SESSION,GLOBAL | FAST          | FAST          |
| tidb_enable_mutation_checker      | SESSION,GLOBAL | ON            | ON            |
+-----------------------------------+----------------+---------------+---------------+
9 rows in set (0.01 sec)

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.

fix the behavior to show the right default value for some variables

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-triage-completed release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 17, 2023
Copy link

tiprow bot commented Dec 17, 2023

Hi @jiyfhust. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

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 kubernetes/test-infra repository.

@jiyfhust
Copy link
Contributor Author

/retest

Copy link

tiprow bot commented Dec 18, 2023

@jiyfhust: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

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 kubernetes/test-infra repository.

Copy link

codecov bot commented Dec 18, 2023

Codecov Report

Merging #49524 (5697500) into master (2ab23da) will decrease coverage by 4.6804%.
Report is 137 commits behind head on master.
The diff coverage is 98.9361%.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #49524        +/-   ##
================================================
- Coverage   71.8744%   67.1941%   -4.6804%     
================================================
  Files          1437       2574      +1137     
  Lines        345629     859614    +513985     
================================================
+ Hits         248419     577610    +329191     
- Misses        76977     258076    +181099     
- Partials      20233      23928      +3695     
Flag Coverage Δ
integration 37.8891% <81.5789%> (?)
unit 79.2628% <97.7011%> (+7.3884%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 73.6130% <ø> (+17.3001%) ⬆️
parser ∅ <ø> (∅)
br 69.6423% <ø> (+18.3568%) ⬆️

@jiyfhust
Copy link
Contributor Author

/cc @dveeden
PTAL

@ti-chi-bot ti-chi-bot bot requested a review from dveeden December 20, 2023 01:05
pkg/sessionctx/variable/sysvar.go Outdated Show resolved Hide resolved
pkg/executor/infoschema_reader.go Outdated Show resolved Hide resolved
@dveeden
Copy link
Contributor

dveeden commented Dec 20, 2023

/ok-to-test

@ti-chi-bot ti-chi-bot bot added the ok-to-test Indicates a PR is ready to be tested. label Dec 20, 2023
@dveeden
Copy link
Contributor

dveeden commented Dec 20, 2023

/check-issue-triage-complete

@ti-chi-bot ti-chi-bot bot added needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 21, 2023
@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 22, 2023
}
case TiDBEnableAsyncCommit, TiDBEnable1PC:
if config.GetGlobalConfig().Store == "tikv" {
varVal = On
Copy link
Member

Choose a reason for hiding this comment

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

Can we retrieve the default value from a centralized location instead of hard coding it here? This could be a problem if we ever need to change the default value in the future but forget to modify this here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

diff --git a/pkg/sessionctx/variable/sysvar.go b/pkg/sessionctx/variable/sysvar.go
index 532cd0f..e74cdf9 100644
--- a/pkg/sessionctx/variable/sysvar.go
+++ b/pkg/sessionctx/variable/sysvar.go
@@ -2093,7 +2093,7 @@ var defaultSysVars = []*SysVar{
                s.ShardAllocateStep = TidbOptInt64(val, DefTiDBShardAllocateStep)
                return nil
        }},
-       {Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableAsyncCommit, Value: BoolToOnOff(DefTiDBEnableAsyncCommit), Type: TypeBool, 
+       {Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableAsyncCommit, Value: defaultTiDBEnableAsyncCommit(), Type: TypeBool, SetSess
                s.EnableAsyncCommit = TiDBOptOn(val)
                return nil
        }},
@@ -2965,6 +2965,13 @@ var defaultSysVars = []*SysVar{
                }},
 }
 
+func defaultTiDBEnableAsyncCommit() string {
+       if config.GetGlobalConfig().Store == "tikv" {
+               return On
+       }
+       return BoolToOnOff(DefTiDBEnableAsyncCommit)
+}
+

I tried this way. But it seems defaultSysVars is inited early than config.GetGlobalConfig(), so it can't work.
Maybe we can set variable.GetSysVars after config.GetGlobalConfig() loaded, but it is also "hard coding".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • if we need set diffrent defalut value for diffrent store types for example TiDBEnableAsyncCommit,we need do that after config.GetGlobalConfig() loaded
  • others,we can move into defaultSysVars, for example TiDBRowFormatVersion.

/cc @JmPotato

Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like this PR has minimal changes to fix the bug. If we want a more elegant way to make it, some questions should be answered before:

  1. Do we need to keep the "right" default value for unistore which is only used for testing ? If we do not need it, we can make variables like TiDBEnableAsyncCommit configured statically without reading global config.
  2. If cluster upgrades from an old one. What is the right default value for the variables that don't want to change. Just like tidb_pessimistic_txn_fair_locking, it should keep the old default value 'OFF' after upgrading and 'ON' for a new cluster.

@ti-chi-bot ti-chi-bot bot requested a review from JmPotato December 22, 2023 03:21
Copy link

ti-chi-bot bot commented Jan 11, 2024

[LGTM Timeline notifier]

Timeline:

  • 2023-12-27 06:37:20.360528106 +0000 UTC m=+1634131.397755033: ☑️ agreed by lcwangchao.
  • 2024-01-11 01:43:29.557427441 +0000 UTC m=+493999.141681142: ☑️ agreed by bb7133.

@Defined2014
Copy link
Contributor

Defined2014 commented Jan 11, 2024

Also could close #50155, please add it on Issue Number

@jiyfhust
Copy link
Contributor Author

Also could close #50155, please add it on Issue Number

Added.

@ti-chi-bot ti-chi-bot bot added needs-cherry-pick-release-5.4 Should cherry pick this PR to release-5.4 branch. needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.1 branch. and removed do-not-merge/needs-triage-completed labels Jan 11, 2024
@easonn7
Copy link

easonn7 commented Jan 11, 2024

/approve

Copy link

ti-chi-bot bot commented Jan 11, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bb7133, easonn7, hawkingrei, lcwangchao

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added the approved label Jan 11, 2024
@ti-chi-bot ti-chi-bot bot merged commit 205b5bb into pingcap:master Jan 11, 2024
21 of 22 checks passed
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-6.5: #50334.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jan 11, 2024
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.1: #50336.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jan 11, 2024
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jan 11, 2024
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.5: #50338.

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-5.4: #50339.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jan 11, 2024
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jan 11, 2024
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-6.1: #50340.

@jiyfhust jiyfhust deleted the fix_variables_info_defaultvalue branch January 12, 2024 01:04
@ti-chi-bot ti-chi-bot removed the needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. label Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm needs-cherry-pick-release-5.4 Should cherry pick this PR to release-5.4 branch. needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.1 branch. needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. ok-to-test Indicates a PR is ready to be tested. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
9 participants