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

system_variables: remove the limitation for set tidb_gc_life_time (#35411) #35467

Merged
merged 1 commit into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions executor/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1702,3 +1702,19 @@ func TestInstanceScopeSwitching(t *testing.T) {
tk.MustExec("set tidb_enable_legacy_instance_scope = 0")
tk.MustGetErrCode("set tidb_general_log = 1", errno.ErrGlobalVariable)
}

func TestGcMaxWaitTime(t *testing.T) {
store, clean := testkit.CreateMockStore(t)
defer clean()
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")

tk.MustExec("set global tidb_gc_max_wait_time = 1000")
tk.MustExec("set global tidb_gc_life_time = \"72h\"")
tk.MustExec("set global tidb_gc_life_time = \"24h\"")
tk.MustExec("set global tidb_gc_life_time = \"10m\"")

tk.MustExec("set global tidb_gc_max_wait_time = 86400")
tk.MustExec("set global tidb_gc_life_time = \"72h\"")
tk.MustExec("set global tidb_gc_max_wait_time = 1000")
}
15 changes: 5 additions & 10 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,9 +583,7 @@ var defaultSysVars = []*SysVar{
}, SetGlobal: func(s *SessionVars, val string) error {
return setTiDBTableValue(s, "tikv_gc_run_interval", val, "GC run interval, at least 10m, in Go format.")
}},
{Scope: ScopeGlobal, Name: TiDBGCLifetime, Value: "10m0s", Type: TypeDuration, MinValue: int64(time.Minute * 10), MaxValue: uint64(time.Hour * 24 * 365), Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) {
return checkTiKVGCLifeTime(vars, normalizedValue, originalValue, scope)
}, GetGlobal: func(s *SessionVars) (string, error) {
{Scope: ScopeGlobal, Name: TiDBGCLifetime, Value: "10m0s", Type: TypeDuration, MinValue: int64(time.Minute * 10), MaxValue: uint64(time.Hour * 24 * 365), GetGlobal: func(s *SessionVars) (string, error) {
return getTiDBTableValue(s, "tikv_gc_life_time", "10m0s")
}, SetGlobal: func(s *SessionVars, val string) error {
return setTiDBTableValue(s, "tikv_gc_life_time", val, "All versions within life time will not be collected by GC, at least 10m, in Go format.")
Expand All @@ -612,13 +610,10 @@ var defaultSysVars = []*SysVar{
}, SetGlobal: func(s *SessionVars, val string) error {
return setTiDBTableValue(s, "tikv_gc_scan_lock_mode", val, "Mode of scanning locks, \"physical\" or \"legacy\"")
}},
{Scope: ScopeGlobal, Name: TiDBGCMaxWaitTime, Value: strconv.Itoa(DefTiDBGCMaxWaitTime), Type: TypeInt, MinValue: 600, MaxValue: 31536000,
Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) {
return checkGCTxnMaxWaitTime(vars, normalizedValue, originalValue, scope)
}, SetGlobal: func(s *SessionVars, val string) error {
GCMaxWaitTime.Store(TidbOptInt64(val, DefTiDBGCMaxWaitTime))
return nil
}},
{Scope: ScopeGlobal, Name: TiDBGCMaxWaitTime, Value: strconv.Itoa(DefTiDBGCMaxWaitTime), Type: TypeInt, MinValue: 600, MaxValue: 31536000, SetGlobal: func(s *SessionVars, val string) error {
GCMaxWaitTime.Store(TidbOptInt64(val, DefTiDBGCMaxWaitTime))
return nil
}},
{Scope: ScopeGlobal, Name: TiDBTableCacheLease, Value: strconv.Itoa(DefTiDBTableCacheLease), Type: TypeUnsigned, MinValue: 1, MaxValue: 10, SetGlobal: func(s *SessionVars, sVal string) error {
var val int64
val, err := strconv.ParseInt(sVal, 10, 64)
Expand Down
33 changes: 0 additions & 33 deletions sessionctx/variable/varsutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,36 +512,3 @@ var GAFunction4ExpressionIndex = map[string]struct{}{
ast.VitessHash: {},
ast.TiDBShard: {},
}

func checkGCTxnMaxWaitTime(vars *SessionVars,
normalizedValue string,
originalValue string,
scope ScopeFlag) (string, error) {
ival, err := strconv.Atoi(normalizedValue)
if err != nil {
return originalValue, errors.Trace(err)
}
GcLifeTimeStr, _ := getTiDBTableValue(vars, "tikv_gc_life_time", "10m0s")
GcLifeTimeDuration, err := time.ParseDuration(GcLifeTimeStr)
if err != nil {
return originalValue, errors.Trace(err)
}
if GcLifeTimeDuration.Seconds() > (float64)(ival) {
return originalValue, errors.Trace(ErrWrongValueForVar.GenWithStackByArgs(TiDBGCMaxWaitTime, normalizedValue))
}
return normalizedValue, nil
}

func checkTiKVGCLifeTime(vars *SessionVars,
normalizedValue string,
originalValue string,
scope ScopeFlag) (string, error) {
gcLifetimeDuration, err := time.ParseDuration(normalizedValue)
if err != nil {
return originalValue, errors.Trace(err)
}
if gcLifetimeDuration.Seconds() > float64(GCMaxWaitTime.Load()) {
return originalValue, errors.Trace(ErrWrongValueForVar.GenWithStackByArgs(TiDBGCLifetime, normalizedValue))
}
return normalizedValue, nil
}