Skip to content

Commit

Permalink
ddl: fix data race in pause ddl test (pingcap#44438)
Browse files Browse the repository at this point in the history
  • Loading branch information
ywqzzy committed Jun 6, 2023
1 parent 70c5cfc commit 223564a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions ddl/pausetest/pause_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"math/rand"
"strings"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -444,23 +445,27 @@ func TestResumeJobPositive(t *testing.T) {
var pauseRS []sqlexec.RecordSet
var resumeRS []sqlexec.RecordSet
var resumeErr error
var mu sync.Mutex
isPaused := false
// Test when pause cannot be retried and adding index succeeds.
hook.OnJobRunBeforeExported = func(job *model.Job) {
logger.Info("OnJobRunAfterExported, before pause,", zap.Int("Job Type:", int(job.Type)),
zap.Int("Job State:", int(job.State)), zap.Int("Job Schema State:", int(job.SchemaState)))
mu.Lock()
defer mu.Unlock()
logger.Info("OnJobRunBeforeExported, before pause,", zap.Int("Job Type", int(job.Type)),
zap.Int("Job State", int(job.State)), zap.Int("Job Schema State", int(job.SchemaState)))
if job.Type == model.ActionAddIndex && job.State == model.JobStateRunning &&
job.SchemaState == model.StateWriteReorganization {
logger.Info("Paused by hook.OnGetJobAfterExported")
logger.Info("Paused by hook.OnGetJobBeforeExported")
jobID = job.ID
stmt := fmt.Sprintf("admin pause ddl jobs %d", jobID)
pauseRS, pauseErr = tkCommand.Session().Execute(context.Background(), stmt)

isPaused = true
}
}

hook.OnGetJobBeforeExported = func(jobType string) {
mu.Lock()
defer mu.Unlock()
if isPaused {
resumeFunc := func() {
time.Sleep(1 * time.Second)
Expand Down

0 comments on commit 223564a

Please sign in to comment.