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

ddl: fix DATA RACE in the TestIndexChange #43952

Merged
merged 1 commit into from
May 18, 2023
Merged
Changes from all 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
11 changes: 6 additions & 5 deletions ddl/index_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package ddl_test

import (
"context"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -46,7 +47,7 @@ func TestIndexChange(t *testing.T) {
// set up hook
prevState := model.StateNone
addIndexDone := false
var jobID int64
var jobID atomic.Int64
var (
deleteOnlyTable table.Table
writeOnlyTable table.Table
Expand All @@ -56,7 +57,7 @@ func TestIndexChange(t *testing.T) {
if job.SchemaState == prevState {
return
}
jobID = job.ID
jobID.Store(job.ID)
ctx1 := testNewContext(store)
prevState = job.SchemaState
require.NoError(t, dom.Reload())
Expand Down Expand Up @@ -92,12 +93,12 @@ func TestIndexChange(t *testing.T) {
time.Sleep(50 * time.Millisecond)
}
v := getSchemaVer(t, tk.Session())
checkHistoryJobArgs(t, tk.Session(), jobID, &historyJobArgs{ver: v, tbl: publicTable.Meta()})
checkHistoryJobArgs(t, tk.Session(), jobID.Load(), &historyJobArgs{ver: v, tbl: publicTable.Meta()})

prevState = model.StateNone
var noneTable table.Table
onJobUpdatedExportedFunc2 := func(job *model.Job) {
jobID = job.ID
jobID.Store(job.ID)
if job.SchemaState == prevState {
return
}
Expand All @@ -124,7 +125,7 @@ func TestIndexChange(t *testing.T) {
tc.OnJobUpdatedExported.Store(&onJobUpdatedExportedFunc2)
tk.MustExec("alter table t drop index c2")
v = getSchemaVer(t, tk.Session())
checkHistoryJobArgs(t, tk.Session(), jobID, &historyJobArgs{ver: v, tbl: noneTable.Meta()})
checkHistoryJobArgs(t, tk.Session(), jobID.Load(), &historyJobArgs{ver: v, tbl: noneTable.Meta()})
}

func checkIndexExists(ctx sessionctx.Context, tbl table.Table, indexValue interface{}, handle int64, exists bool) error {
Expand Down