From abaa9c5c5bd09af774fda30d76d5767b06128df4 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Mon, 14 Jun 2021 11:27:48 -0400 Subject: [PATCH 1/2] Reuse allocsCh if allocIndex remains the same --- nomad/deploymentwatcher/deployment_watcher.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nomad/deploymentwatcher/deployment_watcher.go b/nomad/deploymentwatcher/deployment_watcher.go index 3286fb165da..8360a2f50ce 100644 --- a/nomad/deploymentwatcher/deployment_watcher.go +++ b/nomad/deploymentwatcher/deployment_watcher.go @@ -416,6 +416,7 @@ func (w *deploymentWatcher) watch() { } allocIndex := uint64(1) + allocsCh := w.getAllocsCh(allocIndex) var updates *allocUpdates rollback, deadlineHit := false, false @@ -487,7 +488,7 @@ FAIL: break FAIL } - case updates = <-w.getAllocsCh(allocIndex): + case updates = <-allocsCh: if err := updates.err; err != nil { if err == context.Canceled || w.ctx.Err() == context.Canceled { return @@ -531,6 +532,8 @@ FAIL: if res.createEval || len(res.allowReplacements) != 0 { w.createBatchedUpdate(res.allowReplacements, allocIndex) } + + allocsCh = w.getAllocsCh(allocIndex) } } From ea33e83081a4780f9c36c85eb3bb6d01855b49d3 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Mon, 14 Jun 2021 15:38:44 -0400 Subject: [PATCH 2/2] Update nomad/deploymentwatcher/deployment_watcher.go Co-authored-by: Tim Gross --- nomad/deploymentwatcher/deployment_watcher.go | 1 + 1 file changed, 1 insertion(+) diff --git a/nomad/deploymentwatcher/deployment_watcher.go b/nomad/deploymentwatcher/deployment_watcher.go index 8360a2f50ce..896b48e4463 100644 --- a/nomad/deploymentwatcher/deployment_watcher.go +++ b/nomad/deploymentwatcher/deployment_watcher.go @@ -533,6 +533,7 @@ FAIL: w.createBatchedUpdate(res.allowReplacements, allocIndex) } + // only start a new blocking query if we haven't returned early allocsCh = w.getAllocsCh(allocIndex) } }