Skip to content

Commit

Permalink
fix race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
korotkov-aerospike committed Jan 9, 2025
1 parent 152ce7c commit 08c783b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
3 changes: 1 addition & 2 deletions pkg/service/estimates.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ func RestoreJobStatus(job *jobInfo) *model.RestoreJobStatus {
}

if job.status == model.JobStatusRunning {
status.CurrentRestore = NewRunningJob(job.startTime, status.ReadRecords,
job.totalRecords)
status.CurrentRestore = NewRunningJob(job.startTime, status.ReadRecords, job.totalRecords)
}

if job.err != nil {
Expand Down
12 changes: 12 additions & 0 deletions pkg/service/jobs_holder.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ func (h *RestoreJobsHolder) finishJob(id model.RestoreJobID, err error) {
})
}

func (h *RestoreJobsHolder) getStatus(id model.RestoreJobID) (*model.RestoreJobStatus, error) {
var result *model.RestoreJobStatus
h.Apply(id, func(value *jobInfo) {
result = RestoreJobStatus(value)
})

if result != nil {
return result, nil
}
return nil, NewErrJobNotFound(id)
}

func (h *RestoreJobsHolder) getJob(id model.RestoreJobID) (*jobInfo, error) {
if job, exists := h.Load(id); exists {
return job, nil
Expand Down
7 changes: 1 addition & 6 deletions pkg/service/restore_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,7 @@ func (r *dataRestorer) restoreFromPath(

// JobStatus returns the status of the job with the given id.
func (r *dataRestorer) JobStatus(jobID model.RestoreJobID) (*model.RestoreJobStatus, error) {
job, err := r.restoreJobs.getJob(jobID)
if err != nil {
return nil, err
}

return RestoreJobStatus(job), nil
return r.restoreJobs.getStatus(jobID)
}

func recordsInBackup(ctx context.Context, request *model.RestoreRequest) (uint64, error) {
Expand Down

0 comments on commit 08c783b

Please sign in to comment.