-
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
*: add scope check when get system variables #6958
Changes from 2 commits
8fb0a84
3781767
ded54b4
1e7805f
13f1cfd
a79d5ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -69,7 +69,7 @@ const ( | |||
var ( | ||||
UnknownStatusVar = terror.ClassVariable.New(CodeUnknownStatusVar, "unknown status variable") | ||||
UnknownSystemVar = terror.ClassVariable.New(CodeUnknownSystemVar, "unknown system variable '%s'") | ||||
ErrIncorrectScope = terror.ClassVariable.New(CodeIncorrectScope, "Incorrect variable scope") | ||||
ErrIncorrectScope = terror.ClassVariable.New(CodeIncorrectScope, "Variable '%s' is a %s variable") | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use Line 256 in 3db7594
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed. These error codes can be refined. Will fix |
||||
ErrUnknownTimeZone = terror.ClassVariable.New(CodeUnknownTimeZone, "unknown or incorrect time zone: %s") | ||||
ErrReadOnly = terror.ClassVariable.New(CodeReadOnly, "variable is read only") | ||||
) | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,6 +137,25 @@ func SetSessionSystemVar(vars *SessionVars, name string, value types.Datum) erro | |
return vars.SetSystemVar(name, sVal) | ||
} | ||
|
||
// ValidateGetSystemVar check if system variable exists and validate it's scope when get system variable. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/check/checks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok. will fix |
||
func ValidateGetSystemVar(name string, isGlobal bool) error { | ||
sysVar, exists := SysVars[name] | ||
if !exists { | ||
return UnknownSystemVar.GenByArgs(name) | ||
} | ||
switch sysVar.Scope { | ||
case ScopeGlobal, ScopeNone: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why handle There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if !isGlobal { | ||
return ErrIncorrectScope.GenByArgs(name, "GLOBAL") | ||
} | ||
case ScopeSession: | ||
if isGlobal { | ||
return ErrIncorrectScope.GenByArgs(name, "SESSION") | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// TiDBOptOn could be used for all tidb session variable options, we use "ON"/1 to turn on those options. | ||
func TiDBOptOn(opt string) bool { | ||
return strings.EqualFold(opt, "ON") || opt == "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.
Why should we care if it is set explicitly or not?
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.
if the scope constraint is not set explicitly, the behavior is to choose the right scope automatically. So the scope check should't happen here, logically. For example:
for a
global
variablemax_connections
,select @@max_connections
works, and for asession
variablewarning_count
,select @@warnging_count
works as well.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.
You are right. I got something here: