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

Driver Kill() does not block Stats() #1454

Merged
merged 1 commit into from
Jul 23, 2016
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
40 changes: 21 additions & 19 deletions client/alloc_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,9 @@ func (r *AllocRunner) SaveState() error {
}

// Save state for each task
r.taskLock.RLock()
defer r.taskLock.RUnlock()
runners := r.getTaskRunners()
var mErr multierror.Error
for _, tr := range r.tasks {
for _, tr := range runners {
if err := r.saveTaskRunnerState(tr); err != nil {
mErr.Errors = append(mErr.Errors, err)
}
Expand Down Expand Up @@ -431,29 +430,25 @@ OUTER:
}

// Update the task groups
r.taskLock.RLock()
for _, task := range tg.Tasks {
tr := r.tasks[task.Name]
runners := r.getTaskRunners()
for _, tr := range runners {
tr.Update(update)
}
r.taskLock.RUnlock()

case <-r.destroyCh:
break OUTER
}
}

// Destroy each sub-task
r.taskLock.Lock()
for _, tr := range r.tasks {
runners := r.getTaskRunners()
for _, tr := range runners {
tr.Destroy()
}

// Wait for termination of the task runners
for _, tr := range r.tasks {
for _, tr := range runners {
<-tr.WaitCh()
}
r.taskLock.Unlock()

// Final state sync
r.syncStatus()
Expand Down Expand Up @@ -494,6 +489,19 @@ func (r *AllocRunner) StatsReporter() AllocStatsReporter {
return r
}

// getTaskRunners is a helper that returns a copy of the task runners list using
// the taskLock.
func (r *AllocRunner) getTaskRunners() []*TaskRunner {
// Get the task runners
r.taskLock.RLock()
defer r.taskLock.RUnlock()
runners := make([]*TaskRunner, 0, len(r.tasks))
for _, tr := range r.tasks {
runners = append(runners, tr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we know how many task runners we are going to return and not filtering them

runners := make([]*TaskRunner,len(r.tasks))
for i, tr := range r.tasks {
  runners[i] = tr
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r.tasks is a map

}
return runners
}

// LatestAllocStats returns the latest allocation stats. If the optional taskFilter is set
// the allocation stats will only include the given task.
func (r *AllocRunner) LatestAllocStats(taskFilter string) (*cstructs.AllocResourceUsage, error) {
Expand All @@ -517,13 +525,7 @@ func (r *AllocRunner) LatestAllocStats(taskFilter string) (*cstructs.AllocResour
}
} else {
// Get the task runners
r.taskLock.RLock()
runners := make([]*TaskRunner, 0, len(r.tasks))
for _, tr := range r.tasks {
runners = append(runners, tr)
}
r.taskLock.RUnlock()

runners := r.getTaskRunners()
for _, tr := range runners {
l := tr.LatestResourceUsage()
if l != nil {
Expand Down