diff --git a/executor/set_test.go b/executor/set_test.go index e06ab579be68e..dcc80182841eb 100644 --- a/executor/set_test.go +++ b/executor/set_test.go @@ -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") +} diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index 9cdb8f8a7dd49..169b1be0feec7 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -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.") @@ -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) diff --git a/sessionctx/variable/varsutil.go b/sessionctx/variable/varsutil.go index 495fc1f4d5b58..39ec20cbe2fb1 100644 --- a/sessionctx/variable/varsutil.go +++ b/sessionctx/variable/varsutil.go @@ -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 -}