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

sessionctx: add validation for tidb_enable_plan_replayer_continues_capture #40787

Merged
merged 15 commits into from
Jan 29, 2023
9 changes: 9 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,15 @@ func TestPlanReplayerCapture(t *testing.T) {
func TestPlanReplayerContinuesCapture(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t)
tk := testkit.NewTestKit(t, store)

tk.MustExec("set @@global.tidb_enable_historical_stats='OFF'")
_, err := tk.Exec("set @@global.tidb_enable_plan_replayer_continues_capture='ON'")
require.Error(t, err)
require.Equal(t, err.Error(), "tidb_enable_historical_stats should be enabled before enabling tidb_enable_plan_replayer_continues_capture")

tk.MustExec("set @@global.tidb_enable_historical_stats='ON'")
tk.MustExec("set @@global.tidb_enable_plan_replayer_continues_capture='ON'")

prHandle := dom.GetPlanReplayerHandle()
tk.MustExec("delete from mysql.plan_replayer_status;")
tk.MustExec("use test")
Expand Down
17 changes: 17 additions & 0 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -1188,12 +1188,29 @@ var defaultSysVars = []*SysVar{
/* The system variables below have GLOBAL and SESSION scope */
{Scope: ScopeGlobal | ScopeSession, Name: TiDBEnablePlanReplayerContinuesCapture, Value: BoolToOnOff(false), Type: TypeBool,
SetSession: func(s *SessionVars, val string) error {
historicalStatsEnabled, err := s.GlobalVarsAccessor.GetGlobalSysVar(TiDBEnableHistoricalStats)
if err != nil {
return err
}
if !TiDBOptOn(historicalStatsEnabled) && TiDBOptOn(val) {
return errors.Errorf("%v should be enabled before enabling %v", TiDBEnableHistoricalStats, TiDBEnablePlanReplayerContinuesCapture)
}
s.EnablePlanReplayedContinuesCapture = TiDBOptOn(val)
return nil
},
GetSession: func(vars *SessionVars) (string, error) {
return BoolToOnOff(vars.EnablePlanReplayedContinuesCapture), nil
},
Validation: func(vars *SessionVars, s string, s2 string, flag ScopeFlag) (string, error) {
historicalStatsEnabled, err := vars.GlobalVarsAccessor.GetGlobalSysVar(TiDBEnableHistoricalStats)
if err != nil {
return "", err
}
if !TiDBOptOn(historicalStatsEnabled) && TiDBOptOn(s) {
return "", errors.Errorf("%v should be enabled before enabling %v", TiDBEnableHistoricalStats, TiDBEnablePlanReplayerContinuesCapture)
}
return s, nil
},
},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBEnablePlanReplayerCapture, Value: BoolToOnOff(true), Type: TypeBool,
SetSession: func(s *SessionVars, val string) error {
Expand Down