Skip to content

Commit 4609d8e

Browse files
committed
Changes as requested by lgfa29 and tgross. Primarily handling of batch
evals in face of purge.
1 parent 987d1ac commit 4609d8e

File tree

2 files changed

+12
-24
lines changed

2 files changed

+12
-24
lines changed

nomad/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ func DefaultConfig() *Config {
451451
ReconcileInterval: 60 * time.Second,
452452
EvalGCInterval: 5 * time.Minute,
453453
EvalGCThreshold: 1 * time.Hour,
454-
BatchEvalGCThreshold: 168 * time.Hour,
454+
BatchEvalGCThreshold: 24 * time.Hour,
455455
JobGCInterval: 5 * time.Minute,
456456
JobGCThreshold: 4 * time.Hour,
457457
NodeGCInterval: 5 * time.Minute,

nomad/core_sched.go

+11-23
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ OUTER:
137137
allEvalsGC := true
138138
var jobAlloc, jobEval []string
139139
for _, eval := range evals {
140-
gc, allocs, err := c.gcEval(eval, oldThreshold, oldThreshold, true)
140+
gc, allocs, err := c.gcEval(eval, oldThreshold, true)
141141
if err != nil {
142142
continue OUTER
143143
} else if gc {
@@ -246,9 +246,12 @@ func (c *CoreScheduler) evalGC(eval *structs.Evaluation) error {
246246
for raw := iter.Next(); raw != nil; raw = iter.Next() {
247247
eval := raw.(*structs.Evaluation)
248248

249-
// The Evaluation GC should not handle batch jobs since those need to be
250-
// garbage collected in one shot
251-
gc, allocs, err := c.gcEval(eval, oldThreshold, batchOldThreshold, false)
249+
gcThreshold := oldThreshold
250+
if eval.Type == structs.JobTypeBatch {
251+
gcThreshold = batchOldThreshold
252+
}
253+
254+
gc, allocs, err := c.gcEval(eval, gcThreshold, false)
252255
if err != nil {
253256
return err
254257
}
@@ -274,15 +277,10 @@ func (c *CoreScheduler) evalGC(eval *structs.Evaluation) error {
274277
// allocs are not older than the threshold. If the eval should be garbage
275278
// collected, the associated alloc ids that should also be removed are also
276279
// returned
277-
func (c *CoreScheduler) gcEval(eval *structs.Evaluation, thresholdIndex uint64, batchThresholdIndex uint64, allowBatch bool) (
280+
func (c *CoreScheduler) gcEval(eval *structs.Evaluation, thresholdIndex uint64, allowBatch bool) (
278281
bool, []string, error) {
279282
// Ignore non-terminal and new evaluations
280-
if !eval.TerminalStatus() {
281-
return false, nil, nil
282-
}
283-
284-
if (eval.Type == structs.JobTypeBatch && eval.ModifyIndex > batchThresholdIndex) ||
285-
(eval.Type != structs.JobTypeBatch && eval.ModifyIndex > thresholdIndex) {
283+
if !eval.TerminalStatus() || eval.ModifyIndex > thresholdIndex {
286284
return false, nil, nil
287285
}
288286

@@ -319,19 +317,9 @@ func (c *CoreScheduler) gcEval(eval *structs.Evaluation, thresholdIndex uint64,
319317
// - allowBatch and the job is dead
320318
//
321319
// If we cannot collect outright, check if a partial GC may occur
322-
collect := false
323-
if job == nil {
324-
collect = true
325-
} else if job.Status != structs.JobStatusDead {
326-
collect = false
327-
} else if job.Stop {
328-
collect = true
329-
} else if allowBatch {
330-
collect = true
331-
}
332-
320+
collect := job == nil || job.Status == structs.JobStatusDead && (job.Stop || allowBatch)
333321
if !collect {
334-
oldAllocs := olderVersionTerminalAllocs(allocs, job, batchThresholdIndex)
322+
oldAllocs := olderVersionTerminalAllocs(allocs, job, thresholdIndex)
335323
gcEval := (len(oldAllocs) == len(allocs))
336324
return gcEval, oldAllocs, nil
337325
}

0 commit comments

Comments
 (0)