-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Reconcile child summaries correctly #5205
Merged
+242
−1
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7f4f55b
wip cluster with raw exec enabled
b038333
Fix bug in reconcile summaries that affects periodic/parameterized jobs
9451812
Use IsParameterized/isPeriodic methods
be32301
Refactor to find jobs with child instances more effeciently
946d477
fix linting
e58fcf7
revert unintended change
b403c9b
code review comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ import ( | |
"sort" | ||
"time" | ||
|
||
"reflect" | ||
|
||
log "github.com/hashicorp/go-hclog" | ||
"github.com/hashicorp/go-memdb" | ||
multierror "github.com/hashicorp/go-multierror" | ||
|
@@ -3049,12 +3051,86 @@ func (s *StateStore) ReconcileJobSummaries(index uint64) error { | |
if err != nil { | ||
return err | ||
} | ||
// COMPAT: Remove after 0.11 | ||
// Iterate over jobs to build a list of parent jobs and their children | ||
parentMap := make(map[string][]*structs.Job) | ||
for { | ||
rawJob := iter.Next() | ||
if rawJob == nil { | ||
break | ||
} | ||
job := rawJob.(*structs.Job) | ||
if job.ParentID != "" { | ||
children := parentMap[job.ParentID] | ||
children = append(children, job) | ||
parentMap[job.ParentID] = children | ||
} | ||
} | ||
|
||
// Get all the jobs again | ||
iter, err = txn.Get("jobs", "id") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for { | ||
rawJob := iter.Next() | ||
if rawJob == nil { | ||
break | ||
} | ||
job := rawJob.(*structs.Job) | ||
|
||
if job.IsParameterized() || job.IsPeriodic() { | ||
// COMPAT: Remove after 0.11 | ||
|
||
// The following block of code fixes incorrect child summaries due to a bug | ||
// See https://github.com/hashicorp/nomad/issues/3886 for details | ||
summaryIter, err := txn.Get("job_summary", "id", job.Namespace, job.ID) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use txn.First? |
||
if err != nil { | ||
return err | ||
} | ||
|
||
rawSummary := summaryIter.Next() | ||
if rawSummary != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if rawSummary == nil { continue} |
||
oldSummary := rawSummary.(*structs.JobSummary) | ||
|
||
// Create an empty summary | ||
summary := &structs.JobSummary{ | ||
JobID: job.ID, | ||
Namespace: job.Namespace, | ||
Summary: make(map[string]structs.TaskGroupSummary), | ||
Children: &structs.JobChildrenSummary{}, | ||
} | ||
|
||
// Iterate over children of this job if any to fix summary counts | ||
children := parentMap[job.ID] | ||
for _, childJob := range children { | ||
switch childJob.Status { | ||
case structs.JobStatusPending: | ||
summary.Children.Pending++ | ||
case structs.JobStatusDead: | ||
summary.Children.Dead++ | ||
case structs.JobStatusRunning: | ||
summary.Children.Running++ | ||
} | ||
} | ||
|
||
// Insert the job summary if its different | ||
if !reflect.DeepEqual(summary, oldSummary) { | ||
// Set the create index of the summary same as the job's create index | ||
// and the modify index to the current index | ||
summary.CreateIndex = job.CreateIndex | ||
summary.ModifyIndex = index | ||
|
||
if err := txn.Insert("job_summary", summary); err != nil { | ||
return fmt.Errorf("error inserting job summary: %v", err) | ||
} | ||
} | ||
} | ||
|
||
// Done with handling a parent job, continue to next | ||
continue | ||
} | ||
|
||
// Create a job summary for the job | ||
summary := &structs.JobSummary{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove