Skip to content

Commit

Permalink
address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
morgo committed May 19, 2021
1 parent e90fe9d commit 3ed42bd
Showing 1 changed file with 6 additions and 25 deletions.
31 changes: 6 additions & 25 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,29 +492,10 @@ func UnregisterSysVar(name string) {
sysVarsLock.Unlock()
}

// copySv deep copies the sysvar struct to avoid a race
func copySv(src *SysVar) (dest *SysVar) {
return &SysVar{
Scope: src.Scope,
Name: src.Name,
Value: src.Value,
Type: src.Type,
MinValue: src.MinValue,
MaxValue: src.MaxValue,
AutoConvertNegativeBool: src.AutoConvertNegativeBool,
AutoConvertOutOfRange: src.AutoConvertOutOfRange,
ReadOnly: src.ReadOnly,
PossibleValues: src.PossibleValues,
AllowEmpty: src.AllowEmpty,
AllowEmptyAll: src.AllowEmptyAll,
AllowAutoValue: src.AllowAutoValue,
Validation: src.Validation,
SetSession: src.SetSession,
SetGlobal: src.SetGlobal,
IsHintUpdatable: src.IsHintUpdatable,
Hidden: src.Hidden,
Aliases: src.Aliases,
}
// Clone deep copies the sysvar struct to avoid a race
func (sv *SysVar) Clone() *SysVar {
dst := *sv
return &dst
}

// GetSysVar returns sys var info for name as key.
Expand All @@ -525,7 +506,7 @@ func GetSysVar(name string) *SysVar {
if sysVars[name] == nil {
return nil
}
return copySv(sysVars[name])
return sysVars[name].Clone()
}

// SetSysVar sets a sysvar. This will not propagate to the cluster, so it should only be
Expand All @@ -543,7 +524,7 @@ func GetSysVars() map[string]*SysVar {
defer sysVarsLock.RUnlock()
copy := make(map[string]*SysVar, len(sysVars))
for name, sv := range sysVars {
copy[name] = copySv(sv)
copy[name] = sv.Clone()
}
return copy
}
Expand Down

0 comments on commit 3ed42bd

Please sign in to comment.