Skip to content

Commit

Permalink
sessionctx: support encoding resource group name into session states (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
djshow832 authored Apr 14, 2023
1 parent d01a6fd commit 477fbaf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
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 @@ -2474,6 +2474,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 @@ -2507,6 +2508,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

0 comments on commit 477fbaf

Please sign in to comment.