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

topsql: fix nil pointer panic in stmtctx #30181

Merged
merged 7 commits into from
Nov 29, 2021
Merged
Changes from 4 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
9 changes: 9 additions & 0 deletions sessionctx/stmtctx/stmtctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,19 @@ func (sc *StatementContext) GetPlanDigest() (normalized string, planDigest *pars
// GetResourceGroupTagger returns the implementation of tikvrpc.ResourceGroupTagger related to self.
func (sc *StatementContext) GetResourceGroupTagger() tikvrpc.ResourceGroupTagger {
return func(req *tikvrpc.Request) {
if req == nil {
return
}
req.ResourceGroupTag = sc.GetResourceGroupTagByLabel(
resourcegrouptag.GetResourceGroupLabelByKey(resourcegrouptag.GetFirstKeyFromRequest(req)))
}
}

// GetResourceGroupTagByLabel gets the resource group of the statement based on the label.
func (sc *StatementContext) GetResourceGroupTagByLabel(label tipb.ResourceGroupTagLabel) []byte {
if sc == nil {
return nil
}
switch label {
case tipb.ResourceGroupTagLabel_ResourceGroupTagLabelRow:
v := sc.resourceGroupTagWithRow.Load()
Expand All @@ -316,6 +322,9 @@ func (sc *StatementContext) GetResourceGroupTagByLabel(label tipb.ResourceGroupT
return nil
}
newTag := resourcegrouptag.EncodeResourceGroupTag(sqlDigest, sc.planDigest, label)
if newTag == nil {
return nil
}
switch label {
case tipb.ResourceGroupTagLabel_ResourceGroupTagLabelRow:
sc.resourceGroupTagWithRow.Store(newTag)
Expand Down