Skip to content

Commit

Permalink
executor: fix AnalyzeStatus unit test data race (pingcap#15481)
Browse files Browse the repository at this point in the history
  • Loading branch information
reafans authored Mar 19, 2020
1 parent 3235d82 commit e382f5b
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions statistics/analyze_jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ const (

// AddNewAnalyzeJob adds new analyze job.
func AddNewAnalyzeJob(job *AnalyzeJob) {
analyzeStatus.Lock()
job.updateTime = time.Now()
job.State = pending
analyzeStatus.Lock()
analyzeStatus.jobs[job] = struct{}{}
analyzeStatus.Unlock()
}
Expand Down Expand Up @@ -92,32 +92,30 @@ func GetAllAnalyzeJobs() []*AnalyzeJob {

// Start marks status of the analyze job as running and update the start time.
func (job *AnalyzeJob) Start() {
now := time.Now()
job.Mutex.Lock()
job.State = running
now := time.Now()
job.StartTime = now
job.updateTime = now
job.Mutex.Unlock()
}

// Update updates the row count of analyze job.
func (job *AnalyzeJob) Update(rowCount int64) {
now := time.Now()
job.Mutex.Lock()
job.RowCount += rowCount
job.updateTime = now
job.updateTime = time.Now()
job.Mutex.Unlock()
}

// Finish update the status of analyze job to finished or failed according to `meetError`.
func (job *AnalyzeJob) Finish(meetError bool) {
now := time.Now()
job.Mutex.Lock()
if meetError {
job.State = failed
} else {
job.State = finished
}
job.updateTime = now
job.updateTime = time.Now()
job.Mutex.Unlock()
}

0 comments on commit e382f5b

Please sign in to comment.