diff options
author | James E. Blair <jim@acmegating.com> | 2022-02-28 14:18:10 -0800 |
---|---|---|
committer | James E. Blair <jim@acmegating.com> | 2022-03-02 11:08:18 -0800 |
commit | c4f5d733e40461bc259c2923e721ec595d2d9068 (patch) | |
tree | 2784b4c17866d7f22c8df093932a199b88dad75b /zuul/zk | |
parent | 5b3d0bbe48bdd4195090989f8cfaf952c6f701e4 (diff) | |
download | zuul-c4f5d733e40461bc259c2923e721ec595d2d9068.tar.gz |
Check if job request is still queued before yielding
When iterating over job requests, we can end up yielding requests
which are no longer present because they have been completed, or
are in progress by another merger or executor. We can't catch
all of those cases, which is why we try to lock it and if the lock
fails, move on to the next. But we can catch some of them and
avoid the attempted lock (and therefore extra network traffic and
warning messages). This change double checks the current state
inside the generator before yielding.
Change-Id: I7e2b319a79f6a608ffaf261e65e9532e3486a47f
Diffstat (limited to 'zuul/zk')
-rw-r--r-- | zuul/zk/executor.py | 8 | ||||
-rw-r--r-- | zuul/zk/job_request_queue.py | 6 |
2 files changed, 12 insertions, 2 deletions
diff --git a/zuul/zk/executor.py b/zuul/zk/executor.py index 44d9b23db..ee6aaacf4 100644 --- a/zuul/zk/executor.py +++ b/zuul/zk/executor.py @@ -122,7 +122,13 @@ class ExecutorApi: return sorted(requests) def next(self): - yield from self.inState(BuildRequest.REQUESTED) + for request in self.inState(BuildRequest.REQUESTED): + for queue in self.zone_queues.values(): + request2 = queue._cached_requests.get(request.path) + if (request2 and + request2.state == BuildRequest.REQUESTED): + yield request2 + break def submit(self, request, params): return self.zone_queues[request.zone].submit(request, params) diff --git a/zuul/zk/job_request_queue.py b/zuul/zk/job_request_queue.py index b16db7ca1..7df63f740 100644 --- a/zuul/zk/job_request_queue.py +++ b/zuul/zk/job_request_queue.py @@ -190,7 +190,11 @@ class JobRequestQueue(ZooKeeperSimpleBase): return sorted(requests) def next(self): - yield from self.inState(self.request_class.REQUESTED) + for request in self.inState(self.request_class.REQUESTED): + request = self._cached_requests.get(request.path) + if (request and + request.state == self.request_class.REQUESTED): + yield request def submit(self, request, params, needs_result=False): log = get_annotated_logger(self.log, event=request.event_id) |