Skip to content

Commit

Permalink
system_variables: remove the limitation for set tidb_gc_life_time (pi…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot authored Jun 21, 2022
1 parent 1a89dec commit 40f19cb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 43 deletions.
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
}

0 comments on commit 40f19cb

Please sign in to comment.