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: support encoding resource group name into session states #42886

Merged
merged 1 commit into from
Apr 14, 2023
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
3 changes: 2 additions & 1 deletion sessionctx/sessionstates/session_states.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,6 @@ type SessionStates struct {
LastInsertID uint64 `json:"last-insert-id,omitempty"`
Warnings []stmtctx.SQLWarn `json:"warnings,omitempty"`
// Define it as string to avoid cycle import.
Bindings string `json:"bindings,omitempty"`
Bindings string `json:"bindings,omitempty"`
ResourceGroupName string `json:"rs-group,omitempty"`
}
13 changes: 13 additions & 0 deletions sessionctx/sessionstates/session_states_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,19 @@ func TestSessionCtx(t *testing.T) {
tk.MustQuery("select @@last_plan_from_binding").Check(testkit.Rows("1"))
},
},
{
// check ResourceGroupName
setFunc: func(tk *testkit.TestKit) any {
tk.MustExec("SET GLOBAL tidb_enable_resource_control='on'")
tk.MustExec("CREATE RESOURCE GROUP rg1 ru_per_sec = 100")
tk.MustExec("SET RESOURCE GROUP `rg1`")
require.Equal(t, "rg1", tk.Session().GetSessionVars().ResourceGroupName)
return nil
},
checkFunc: func(tk *testkit.TestKit, param any) {
tk.MustQuery("SELECT CURRENT_RESOURCE_GROUP()").Check(testkit.Rows("rg1"))
},
},
}

for _, tt := range tests {
Expand Down
2 changes: 2 additions & 0 deletions sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -2467,6 +2467,7 @@ func (s *SessionVars) EncodeSessionStates(_ context.Context, sessionStates *sess
sessionStates.SequenceLatestValues = s.SequenceState.GetAllStates()
sessionStates.FoundInPlanCache = s.PrevFoundInPlanCache
sessionStates.FoundInBinding = s.PrevFoundInBinding
sessionStates.ResourceGroupName = s.ResourceGroupName

// Encode StatementContext. We encode it here to avoid circle dependency.
sessionStates.LastAffectedRows = s.StmtCtx.PrevAffectedRows
Expand Down Expand Up @@ -2500,6 +2501,7 @@ func (s *SessionVars) DecodeSessionStates(_ context.Context, sessionStates *sess
s.SequenceState.SetAllStates(sessionStates.SequenceLatestValues)
s.FoundInPlanCache = sessionStates.FoundInPlanCache
s.FoundInBinding = sessionStates.FoundInBinding
s.ResourceGroupName = sessionStates.ResourceGroupName

// Decode StatementContext.
s.StmtCtx.SetAffectedRows(uint64(sessionStates.LastAffectedRows))
Expand Down