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

bindInfo: fix datarace on bindings #40846

Merged
merged 11 commits into from
Jan 30, 2023
11 changes: 11 additions & 0 deletions bindinfo/bind_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ type BindRecord struct {
Bindings []Binding
}

// Copy get the copy of bindRecord
func (br *BindRecord) Copy() *BindRecord {
nbr := &BindRecord{
OriginalSQL: br.OriginalSQL,
Db: br.Db,
}
nbr.Bindings = make([]Binding, len(br.Bindings))
copy(nbr.Bindings, br.Bindings)
return nbr
}

// HasEnabledBinding checks if there are any enabled bindings in bind record.
func (br *BindRecord) HasEnabledBinding() bool {
for _, binding := range br.Bindings {
Expand Down
1 change: 0 additions & 1 deletion executor/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ go_library(
"//util/servermemorylimit",
"//util/set",
"//util/size",
"//util/slice",
"//util/sqlexec",
"//util/stmtsummary",
"//util/stringutil",
Expand Down
6 changes: 4 additions & 2 deletions executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ import (
"github.com/pingcap/tidb/util/memory"
"github.com/pingcap/tidb/util/sem"
"github.com/pingcap/tidb/util/set"
"github.com/pingcap/tidb/util/slice"
"github.com/pingcap/tidb/util/sqlexec"
"github.com/pingcap/tidb/util/stringutil"
"golang.org/x/exp/slices"
Expand Down Expand Up @@ -317,7 +316,10 @@ func (e *ShowExec) fetchShowBind() error {
} else {
tmp = domain.GetDomain(e.ctx).BindHandle().GetAllBindRecord()
}
bindRecords := slice.Copy(tmp)
bindRecords := make([]*bindinfo.BindRecord, 0)
for _, bindRecord := range tmp {
bindRecords = append(bindRecords, bindRecord.Copy())
}
// Remove the invalid bindRecord.
ind := 0
for _, bindData := range bindRecords {
Expand Down