Review fixes
This commit is contained in:
parent
302a0cf382
commit
efbb2894c7
13
nomad/fsm.go
13
nomad/fsm.go
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"github.com/armon/go-metrics"
|
||||
|
@ -723,12 +724,11 @@ func (n *nomadFSM) reconcileQueuedAllocations(index uint64) error {
|
|||
}
|
||||
|
||||
// Get the job summary from the fsm state store
|
||||
raw, err := n.state.JobSummaryByID(job.ID)
|
||||
originalSummary, err := n.state.JobSummaryByID(job.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
summary := raw.Copy()
|
||||
summary.ModifyIndex = index
|
||||
summary := originalSummary.Copy()
|
||||
|
||||
// Add the allocations scheduler has made to queued since these
|
||||
// allocations are never getting placed until the scheduler is invoked
|
||||
|
@ -765,8 +765,11 @@ func (n *nomadFSM) reconcileQueuedAllocations(index uint64) error {
|
|||
summary.Summary[tg] = tgSummary
|
||||
}
|
||||
|
||||
if err := n.state.UpsertJobSummary(index, summary); err != nil {
|
||||
return err
|
||||
if !reflect.DeepEqual(summary, originalSummary) {
|
||||
summary.ModifyIndex = index
|
||||
if err := n.state.UpsertJobSummary(index, summary); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -414,30 +414,35 @@ func (s *StateStore) DeleteJob(index uint64, jobID string) error {
|
|||
pSummary := existing.Copy()
|
||||
if pSummary.Children != nil {
|
||||
|
||||
modified := false
|
||||
switch job.Status {
|
||||
case structs.JobStatusPending:
|
||||
pSummary.Children.Pending--
|
||||
pSummary.Children.Dead++
|
||||
modified = true
|
||||
case structs.JobStatusRunning:
|
||||
pSummary.Children.Running--
|
||||
pSummary.Children.Dead++
|
||||
modified = true
|
||||
case structs.JobStatusDead:
|
||||
default:
|
||||
return fmt.Errorf("unknown old job status %q", job.Status)
|
||||
}
|
||||
|
||||
// Update the modify index
|
||||
pSummary.ModifyIndex = index
|
||||
if modified {
|
||||
// Update the modify index
|
||||
pSummary.ModifyIndex = index
|
||||
|
||||
watcher.Add(watch.Item{Table: "job_summary"})
|
||||
watcher.Add(watch.Item{JobSummary: job.ParentID})
|
||||
watcher.Add(watch.Item{Table: "job_summary"})
|
||||
watcher.Add(watch.Item{JobSummary: job.ParentID})
|
||||
|
||||
// Insert the summary
|
||||
if err := txn.Insert("job_summary", pSummary); err != nil {
|
||||
return fmt.Errorf("job summary insert failed: %v", err)
|
||||
}
|
||||
if err := txn.Insert("index", &IndexEntry{"job_summary", index}); err != nil {
|
||||
return fmt.Errorf("index update failed: %v", err)
|
||||
// Insert the summary
|
||||
if err := txn.Insert("job_summary", pSummary); err != nil {
|
||||
return fmt.Errorf("job summary insert failed: %v", err)
|
||||
}
|
||||
if err := txn.Insert("index", &IndexEntry{"job_summary", index}); err != nil {
|
||||
return fmt.Errorf("index update failed: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue