Add sanity check to SaveState
Also just reuse the task states snapshot taken by `Alloc()` instead of doing a redundant copy.
This commit is contained in:
parent
29d755abdf
commit
e7dd443447
|
@ -180,12 +180,9 @@ func (r *AllocRunner) SaveState() error {
|
|||
|
||||
func (r *AllocRunner) saveAllocRunnerState() error {
|
||||
// Create the snapshot.
|
||||
r.taskStatusLock.RLock()
|
||||
states := copyTaskStates(r.taskStates)
|
||||
r.taskStatusLock.RUnlock()
|
||||
|
||||
alloc := r.Alloc()
|
||||
r.allocLock.Lock()
|
||||
states := alloc.TaskStates
|
||||
allocClientStatus := r.allocClientStatus
|
||||
allocClientDescription := r.allocClientDescription
|
||||
r.allocLock.Unlock()
|
||||
|
|
|
@ -92,6 +92,13 @@ func persistState(path string, data interface{}) error {
|
|||
if err := os.Rename(tmpPath, path); err != nil {
|
||||
return fmt.Errorf("failed to rename tmp to path: %v", err)
|
||||
}
|
||||
|
||||
// Sanity check since users have reported empty state files on disk
|
||||
if stat, err := os.Stat(path); err != nil {
|
||||
return fmt.Errorf("unable to stat state file %s: %v", path, err)
|
||||
} else if stat.Size() == 0 {
|
||||
return fmt.Errorf("persisted invalid state file %s; see https://github.com/hashicorp/nomad/issues/1367")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue