mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 12:46:49 +00:00
fix(operations): a housekeeping pass is not started while one runs
The worker started housekeeping every 10 minutes on its control threads whether or not the last pass had ended. A pass stuck on a host (the cleanup of an idle upload on a host that does not answer) took one more thread each time, and after four passes no control thread was left for cancels and recovery. The next pass now starts only after the last one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
parent
db1db4cb32
commit
d69d149d97
2 changed files with 18 additions and 1 deletions
|
|
@ -60,6 +60,20 @@ class WorkerTestCase(TransactionTestCase):
|
|||
def job(self, host, n):
|
||||
return self.submit("test.host", {"host": host, "n": n}, f"key-h{host}-{n:04d}")
|
||||
|
||||
def test_a_stuck_housekeeping_pass_is_not_started_again(self):
|
||||
stuck, passes = threading.Event(), []
|
||||
|
||||
def housekeeping():
|
||||
passes.append(1)
|
||||
stuck.wait(10)
|
||||
with patch("operations.worker.HOUSEKEEPING_EVERY", 0), patch("operations.worker.housekeeping", housekeeping):
|
||||
self.start()
|
||||
self.assertTrue(wait_for(lambda: passes))
|
||||
time.sleep(0.5) # ten ticks
|
||||
self.assertEqual(len(passes), 1)
|
||||
stuck.set()
|
||||
self.assertTrue(wait_for(lambda: len(passes) > 1))
|
||||
|
||||
def test_a_stuck_host_takes_half_the_slots_and_one_progress_read(self):
|
||||
fakes.STUCK[1] = threading.Event()
|
||||
stuck = [self.job(1, n) for n in range(4)]
|
||||
|
|
|
|||
|
|
@ -111,6 +111,7 @@ class Worker:
|
|||
self.progress_pool = ThreadPoolExecutor(PROGRESS_THREADS, thread_name_prefix="wvc-progress")
|
||||
self.recovery = Scheduler(self)
|
||||
self._last = {"heartbeat": 0.0, "progress": 0.0, "housekeeping": 0.0}
|
||||
self.housekeeping = None # the future of the last housekeeping pass
|
||||
|
||||
# -- process ------------------------------------------------------------
|
||||
|
||||
|
|
@ -194,7 +195,9 @@ class Worker:
|
|||
self._claim()
|
||||
if now - self._last["housekeeping"] >= HOUSEKEEPING_EVERY:
|
||||
self._last["housekeeping"] = now
|
||||
self.control.submit(_guarded, housekeeping)
|
||||
# one pass at a time: a pass stuck on a host (an upload's cleanup) holds one control thread, not all
|
||||
if self.housekeeping is None or self.housekeeping.done():
|
||||
self.housekeeping = self.control.submit(_guarded, housekeeping)
|
||||
|
||||
def _mine(self, pks):
|
||||
"""This worker's active jobs among pks; used only inside fenced."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue