Skip to content

Commit

Permalink
bindInfo: fix datarace on bindings (#40846)
Browse files Browse the repository at this point in the history
close #40843
  • Loading branch information
Yisaer committed Jan 30, 2023
1 parent 11839ac commit 86a6694
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
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

0 comments on commit 86a6694

Please sign in to comment.