Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#45127
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
  • Loading branch information
wshwsh12 authored and ti-chi-bot committed Jul 5, 2023
1 parent c096a5a commit 7ab8cab
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
32 changes: 32 additions & 0 deletions executor/index_merge_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"regexp"
"strconv"
"strings"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -1073,3 +1074,34 @@ func TestOrderByWithLimit(t *testing.T) {
}
}
}

func TestProcessInfoRaceWithIndexScan(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test;")
tk.MustExec("drop table if exists t1;")
tk.MustExec("create table t1(c1 int, c2 int, c3 int, c4 int, c5 int, key(c1), key(c2), key(c3), key(c4),key(c5));")
insertStr := "insert into t1 values(0, 0, 0, 0 , 0)"
for i := 1; i < 100; i++ {
insertStr += fmt.Sprintf(", (%d, %d, %d, %d, %d)", i, i, i, i, i)
}
tk.MustExec(insertStr)

tk.Session().SetSessionManager(&testkit.MockSessionManager{
PS: []*util.ProcessInfo{tk.Session().ShowProcess()},
})

wg := sync.WaitGroup{}
wg.Add(1)
go func() {
defer wg.Done()
for i := 0; i <= 100; i++ {
ps := tk.Session().ShowProcess()
util.GenLogFields(233, ps, true)
}
}()
for i := 0; i <= 100; i++ {
tk.MustQuery("select /*+ use_index(t1, c1) */ c1 from t1 where c1 = 0 union all select /*+ use_index(t1, c2) */ c2 from t1 where c2 = 0 union all select /*+ use_index(t1, c3) */ c3 from t1 where c3 = 0 ")
}
wg.Wait()
}
4 changes: 4 additions & 0 deletions executor/jointest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ go_test(
],
flaky = True,
race = "on",
<<<<<<< HEAD:executor/jointest/BUILD.bazel
shard_count = 50,
=======
shard_count = 30,
>>>>>>> af04707eda7 (*: fix data race in ProcessInfo (#45127)):executor/test/indexmergereadtest/BUILD.bazel
deps = [
"//config",
"//meta/autoid",
Expand Down
2 changes: 2 additions & 0 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1572,6 +1572,8 @@ func (s *session) SetProcessInfo(sql string, t time.Time, command byte, maxExecu
DiskTracker: s.sessionVars.DiskTracker,
StatsInfo: plannercore.GetStatsInfo,
OOMAlarmVariablesInfo: s.getOomAlarmVariablesInfo(),
TableIDs: s.sessionVars.StmtCtx.TableIDs,
IndexNames: s.sessionVars.StmtCtx.IndexNames,
MaxExecutionTime: maxExecutionTime,
RedactSQL: s.sessionVars.EnableRedactLog,
ResourceGroupName: s.sessionVars.ResourceGroupName,
Expand Down
2 changes: 2 additions & 0 deletions util/processinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ type ProcessInfo struct {
Port string
ResourceGroupName string
PlanExplainRows [][]string
TableIDs []int64
IndexNames []string
OOMAlarmVariablesInfo OOMAlarmVariablesInfo
ID uint64
CurTxnStartTS uint64
Expand Down
9 changes: 9 additions & 0 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,21 @@ func GenLogFields(costTime time.Duration, info *ProcessInfo, needTruncateSQL boo
logFields = append(logFields, zap.String("database", info.DB))
}
var tableIDs, indexNames string
<<<<<<< HEAD
if len(info.StmtCtx.TableIDs) > 0 {
tableIDs = strings.Replace(fmt.Sprintf("%v", info.StmtCtx.TableIDs), " ", ",", -1)
logFields = append(logFields, zap.String("table_ids", tableIDs))
}
if len(info.StmtCtx.IndexNames) > 0 {
indexNames = strings.Replace(fmt.Sprintf("%v", info.StmtCtx.IndexNames), " ", ",", -1)
=======
if len(info.TableIDs) > 0 {
tableIDs = strings.ReplaceAll(fmt.Sprintf("%v", info.TableIDs), " ", ",")
logFields = append(logFields, zap.String("table_ids", tableIDs))
}
if len(info.IndexNames) > 0 {
indexNames = strings.ReplaceAll(fmt.Sprintf("%v", info.IndexNames), " ", ",")
>>>>>>> af04707eda7 (*: fix data race in ProcessInfo (#45127))
logFields = append(logFields, zap.String("index_names", indexNames))
}
logFields = append(logFields, zap.Uint64("txn_start_ts", info.CurTxnStartTS))
Expand Down

0 comments on commit 7ab8cab

Please sign in to comment.