Skip to content

Commit

Permalink
*: fix data race caused by analyzeStatus. (pingcap#15526)
Browse files Browse the repository at this point in the history
  • Loading branch information
reafans authored Mar 21, 2020
1 parent b05e01f commit 8116534
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion statistics/analyze_jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func GetAllAnalyzeJobs() []*AnalyzeJob {
}
jobs = append(jobs, analyzeStatus.history...)
analyzeStatus.Unlock()
sort.Slice(jobs, func(i int, j int) bool { return jobs[i].updateTime.Before(jobs[j].updateTime) })
sort.Slice(jobs, func(i int, j int) bool { return jobs[i].getUpdateTime().Before(jobs[j].getUpdateTime()) })
return jobs
}

Expand Down Expand Up @@ -119,3 +119,9 @@ func (job *AnalyzeJob) Finish(meetError bool) {
job.updateTime = time.Now()
job.Mutex.Unlock()
}

func (job *AnalyzeJob) getUpdateTime() time.Time {
job.Mutex.Lock()
defer job.Mutex.Unlock()
return job.updateTime
}

0 comments on commit 8116534

Please sign in to comment.