mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-02 00:46:05 +00:00
fix(operations): a host that does not answer keeps the job worker going for the others
A job's libvirt call to a host that is up but stuck waits as long as the host does. Measured with the worker's loop: with two jobs stuck on one host, the other host's jobs ran but their progress was never read (both progress threads waited on the stuck host); with four stuck, a new job of another host stayed queued, every slot taken; cancelling them took all four control threads, so cancels, recovery and housekeeping stopped for every host. Now a host's jobs take at most half of the worker's slots (at least one; a migration counts on both its hosts), and the next queued job of another host starts instead. A host has at most one progress read and one control task (a cancel or a recovery inspection) at a time, and the control tasks of hosts leave one thread to housekeeping.
This commit is contained in:
parent
b2b2386db9
commit
6ca65e291a
5 changed files with 164 additions and 20 deletions
|
|
@ -51,12 +51,43 @@ class WorkerTestCase(TransactionTestCase):
|
|||
self.thread = fakes.start_worker(self.worker)
|
||||
|
||||
def tearDown(self):
|
||||
for barrier in fakes.BARRIERS.values():
|
||||
barrier.set()
|
||||
for event in [*fakes.BARRIERS.values(), *fakes.STUCK.values()]:
|
||||
event.set()
|
||||
if self.thread:
|
||||
fakes.stop_worker(self.worker, self.thread)
|
||||
connection.close()
|
||||
|
||||
def job(self, host, n):
|
||||
return self.submit("test.host", {"host": host, "n": n}, f"key-h{host}-{n:04d}")
|
||||
|
||||
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)]
|
||||
self.start(concurrency=4)
|
||||
self.assertTrue(wait_for(lambda: sum(state(op) == Operation.RUNNING for op in stuck) == 2))
|
||||
# the other host's job runs beside them, and its progress is read
|
||||
healthy = self.submit("test.host", {"host": 2, "n": 0}, "key-h2-0000", barrier=True)
|
||||
self.assertTrue(wait_for(lambda: ("progress", 2) in fakes.HOST_CALLS))
|
||||
self.assertEqual(sum(state(op) == Operation.RUNNING for op in stuck), 2)
|
||||
self.assertEqual(fakes.HOST_CALLS.count(("progress", 1)), 1)
|
||||
fakes.BARRIERS["key-h2-0000"].set()
|
||||
self.assertTrue(wait_for(lambda: state(healthy) == Operation.SUCCEEDED))
|
||||
|
||||
def test_a_stuck_host_takes_one_control_thread(self):
|
||||
fakes.STUCK[1] = threading.Event()
|
||||
# they run until cancelled
|
||||
stuck = [self.submit("test.host", {"host": 1, "n": n}, f"key-h1-{n:04d}", barrier=True) for n in range(2)]
|
||||
healthy = self.submit("test.host", {"host": 2, "n": 0}, "key-h2-0000", barrier=True)
|
||||
self.start(concurrency=4)
|
||||
self.assertTrue(wait_for(lambda: all(state(op) == Operation.RUNNING for op in [*stuck, healthy])))
|
||||
for op in [*stuck, healthy]:
|
||||
jobs.cancel(op.pk, self.user)
|
||||
# the other host's cancel goes through; the stuck host's second cancel waits for its first
|
||||
self.assertTrue(wait_for(lambda: ("cancel", 2) in fakes.HOST_CALLS))
|
||||
self.assertEqual(fakes.HOST_CALLS.count(("cancel", 1)), 1)
|
||||
fakes.STUCK[1].set()
|
||||
self.assertTrue(wait_for(lambda: fakes.HOST_CALLS.count(("cancel", 1)) == 2))
|
||||
|
||||
def submit(self, kind, params, key, barrier=False):
|
||||
if barrier:
|
||||
fakes.BARRIERS[key] = threading.Event() # before the worker can see the job
|
||||
|
|
@ -316,3 +347,4 @@ class HostIdentityTestCase(TransactionTestCase):
|
|||
first = host_identity(self.dir)
|
||||
with patch("operations.worker.socket.gethostname", return_value="wvc-test-b"):
|
||||
self.assertEqual(host_identity(self.dir), first)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue