-
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
session, executor: support setting tidb_enable_stmt_summary in session scope #12217
session, executor: support setting tidb_enable_stmt_summary in session scope #12217
Conversation
/bench |
@@ Benchmark Diff @@
================================================================================
--- tidb: d438e103bea6ab98c2406903980e2077cce7652c
+++ tidb: c09f1bed50dc328e99d29b476424fa7b3e573797
tikv: 8519bf55a00197f6304c8a99580d437248d47601
pd: 06e2034f4f8c58f04ce293180c1eaf515424a58e
================================================================================
test-1: < oltp_insert >
* QPS : 21336.35 ± 0.0908% (std=13.70) delta: 0.72%
* AvgMs : 11.99 ± 0.0556% (std=0.00) delta: -0.73%
* PercentileMs99 : 43.23 ± 2.1650% (std=0.58) delta: -0.72%
test-2: < oltp_update_non_index >
* QPS : 29117.58 ± 0.2031% (std=36.56) delta: -0.23%
* AvgMs : 8.78 ± 0.0854% (std=0.00) delta: 0.14%
* PercentileMs99 : 31.37 ± 0.0000% (std=0.00) delta: 1.82%
test-3: < oltp_read_write >
* QPS : 36857.90 ± 0.8002% (std=180.47) delta: 0.19%
* AvgMs : 139.45 ± 0.7974% (std=0.69) delta: -0.19%
* PercentileMs99 : 260.76 ± 1.0791% (std=2.30) delta: -0.71%
test-4: < oltp_point_select >
* QPS : 75552.29 ± 1.4060% (std=591.27) delta: 0.28%
* AvgMs : 3.39 ± 1.2397% (std=0.02) delta: 0.06%
* PercentileMs99 : 7.56 ± 0.0000% (std=0.00) delta: 0.00%
test-5: < oltp_update_index >
* QPS : 16945.28 ± 0.1970% (std=23.14) delta: 0.42%
* AvgMs : 15.11 ± 0.1655% (std=0.02) delta: -0.43%
* PercentileMs99 : 48.34 ± 0.0000% (std=0.00) delta: -0.71%
|
domain/global_vars_cache_test.go
Outdated
@@ -14,7 +14,7 @@ | |||
package domain | |||
|
|||
import ( | |||
"sync/atomic" | |||
"github.com/pingcap/tidb/util/stmtsummary" |
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.
Please re-arrange the order the imported package
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.
Addressed.
350a256
to
fc0be6e
Compare
Codecov Report
@@ Coverage Diff @@
## master #12217 +/- ##
===========================================
Coverage 81.0924% 81.0924%
===========================================
Files 454 454
Lines 98606 98606
===========================================
Hits 79962 79962
Misses 12876 12876
Partials 5768 5768 |
/bench |
007b3d8
to
4910651
Compare
// isEnabled converts a string value to bool. | ||
func (ssMap *stmtSummaryByDigestMap) isEnabled(enable string) bool { | ||
switch { | ||
case strings.EqualFold(enable, "ON") || enable == "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.
We can covert "ON" to "1" when setting the value.
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.
Seems already converted in ValidateSetSystemVar
.
We can simply return enable == "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.
ValidateSetSystemVar
is executed in variable.SetSessionSystemVar
, but variable.SetSessionSystemVar
doesn't return converted value in SetExecutor.setSysVariable
, so stmtsummary.StmtSummaryByDigestMap
gets a raw value and a conversion is needed.
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 added normalizeEnableValue
to convert.
sessionEnabled string | ||
// setInSession indicates whether statement summary has been set in any session. | ||
globalEnabled string | ||
defaultEnabled bool |
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 think we can remove defaultEnabled
.
If the value is not 1
, then enabled is 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.
Default value should be defined once in the whole project so that it's convenient to modify.
Since DefTiDBEnableStmtSummary
is already defined and is used in variable.defaultSysVars
, we should reuse DefTiDBEnableStmtSummary
as the default value in stmtsummary
.
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 global default is used once it is loaded, the DefTiDBEnableStmtSummary
is not needed.
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.
Addressed.
@@ Benchmark Diff @@
================================================================================
--- tidb: c5cad51459bf6967685fbea3c56553b7efb8cdbe
+++ tidb: 007b3d8b70e44a8092134e90fe97c0e61604f1f6
tikv: 2364333636896356a9b3c48d33807951d73d02ed
pd: cfa5706aec6466da3d2a2c4d0c6e713779fde67e
================================================================================
test-1: < oltp_read_write >
* QPS : 37340.83 ± 0.8921% (std=246.42) delta: 1.42%
* AvgMs : 137.66 ± 0.8978% (std=0.91) delta: -1.40%
* PercentileMs99 : 257.95 ± 0.0000% (std=0.00) delta: -1.08%
test-2: < oltp_point_select >
* QPS : 84005.32 ± 1.5337% (std=1024.54) delta: 1.56%
* AvgMs : 3.05 ± 1.4445% (std=0.04) delta: -1.61%
* PercentileMs99 : 5.84 ± 1.1309% (std=0.05) delta: -1.85%
test-3: < oltp_insert >
* QPS : 21413.20 ± 0.3090% (std=44.27) delta: 0.60%
* AvgMs : 11.95 ± 0.3137% (std=0.02) delta: -0.58%
* PercentileMs99 : 42.92 ± 1.0903% (std=0.38) delta: -1.08%
test-4: < oltp_update_index >
* QPS : 16917.79 ± 0.6630% (std=85.11) delta: -0.05%
* AvgMs : 15.13 ± 0.6478% (std=0.08) delta: 0.04%
* PercentileMs99 : 48.86 ± 1.0683% (std=0.43) delta: -0.37%
test-5: < oltp_update_non_index >
* QPS : 29082.91 ± 0.4025% (std=76.67) delta: -0.01%
* AvgMs : 8.80 ± 0.4545% (std=0.02) delta: 0.02%
* PercentileMs99 : 31.15 ± 1.0788% (std=0.27) delta: -0.71%
|
atomic.StoreInt32(&variable.EnableStmtSummary, 1) | ||
// SetEnabled enables or disables statement summary in global(cluster) or session(server) scope. | ||
func (ssMap *stmtSummaryByDigestMap) SetEnabled(enable string, inSession bool) { | ||
enable = ssMap.normalizeEnableValue(enable) |
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 don't need to do this, the enable string
already normalized by ValidateSetSystemVar
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.
ValidateSetSystemVar
is executed in variable.SetSessionSystemVar
, but variable.SetSessionSystemVar
doesn't return converted value in SetExecutor.setSysVariable
, so stmtsummary.StmtSummaryByDigestMap
gets a raw value and a conversion is needed.
if !ssMap.isSet(ssMap.enabledWrapper.sessionEnabled) { | ||
needClear = !ssMap.isEnabled(enable) | ||
} | ||
} |
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.
Maybe this is simpler.
ssMap.ssMap.enabledWrapper.Lock()
if inSession {
ssMap.enabledWrapper.sessionEnabled = enable
} else {
ssMap.enabledWrapper.globalEnabled = enable
}
sessionEnabled := ssMap.enabledWrapper.sessionEnabled
globalEnabled := ssMap.enabledWrapper.globalEnabled
ssMap.ssMap.enabledWrapper.UnLock()
if ssMap.IsSet(sessionEnable) {
needClear = !ssMap.IsEnabled(sessionEnable)
} else {
needClear = !ssMap.IsEnabled(globalEnable)
}
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.
Addressed.
ba19b41
to
e869935
Compare
LGTM |
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.
For all PRs that need cherry-pick, please add a short "Release Note" to the PR Description.
You can refer to the released notes from previous version:
|
||
// isEnabled converts a string value to bool. | ||
// 1 indicates true, 0 or '' indicates false. | ||
func (ssMap *stmtSummaryByDigestMap) isEnabled(enable string) bool { |
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.
func (ssMap *stmtSummaryByDigestMap) isEnabled(enable string) bool { | |
func (ssMap *stmtSummaryByDigestMap) isEnabled(value string) bool { |
How about renaming to "value"? "enable" is a verb.
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.
Addressed.
} | ||
|
||
// isSet judges whether the variable is set. | ||
func (ssMap *stmtSummaryByDigestMap) isSet(enable string) bool { |
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.
ditto
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.
Addressed.
07160ff
to
fd8ec51
Compare
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
/run-all-tests |
/run-all-tests |
cherry pick to release-3.0 failed |
cherry pick to release-3.1 failed |
…n scope (pingcap#12217) cherry-pick 12217 to release-3.0
…n scope (pingcap#12217) cherry-pick 12217 to release-3.0
…n session scope (pingcap#12217) (pingcap#12308)" This reverts commit f33c908.
…n scope (pingcap#12217) (pingcap#12308) cherry-pick 12308 to release-3.1
It seems that, not for sure, we failed to cherry-pick this commit to release-3.0. Please comment '/run-cherry-picker' to try to trigger the cherry-picker if we did fail to cherry-pick this commit before. @djshow832 PTAL. |
What problem does this PR solve?
Support setting tidb_enable_stmt_summary in session scope. It was only supported in global scope. Actually, session scope here equals server scope, and global scope here equals cluster scope.
What is changed and how it works?
When statement summary is enabled in global scope, it'll work immediately on the current server and work in 2 seconds on the other servers in the cluster.
When statement summary is enabled in session scope, it'll work immediately on the current server, and subsequent settings in the global scope won't work.
If tidb_enable_stmt_summary is set to '' in session scope, then tidb_enable_stmt_summary in global scope works in the current server.
Check List
Tests
Code changes
Side effects
Related changes
Release Note