mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 17:36:05 +00:00
fix(jobs): recovery that cannot read a job's state for an hour ends it uncertain
Recovery retried a reconcile that raised every 10 minutes with no end. A
job whose compute was gone for good stayed running ("Waiting for
recovery") and kept its claims: it could not be resolved (only uncertain
jobs can), cancelled, or have its compute deleted. After an hour of
failed reconciles the job ends uncertain with the last error; it keeps
its claims, and an administrator checks the VM and resolves it. A
reconcile that answers restarts the hour.
This commit is contained in:
parent
cd722c6a00
commit
2afb7be196
6 changed files with 188 additions and 143 deletions
|
|
@ -9,7 +9,7 @@ from operations import jobs
|
|||
from operations.jobs import Outcome
|
||||
from operations.models import Claim, Operation, WorkerLease, acquire
|
||||
from operations.tests import fakes
|
||||
from operations.worker import ABANDONED, STALL_LIMIT, STALLED, WAITING, Scheduler
|
||||
from operations.worker import ABANDONED, RECOVERY_LIMIT, STALL_LIMIT, STALLED, UNREACHABLE, WAITING, Scheduler
|
||||
|
||||
|
||||
class FakeWorker:
|
||||
|
|
@ -163,6 +163,27 @@ class RecoveryTestCase(TransactionTestCase):
|
|||
self.assertEqual((op.state, op.phase), (Operation.RUNNING, WAITING))
|
||||
self.assertEqual(self.scheduler.attempts[op.pk], 1)
|
||||
|
||||
def test_a_host_unreachable_for_the_recovery_limit_ends_the_job_uncertain(self):
|
||||
op = self.orphan({})
|
||||
for now in (1000, 1000 + RECOVERY_LIMIT - 1, 1000 + RECOVERY_LIMIT):
|
||||
self.scheduler.next_try[op.pk] = 0
|
||||
with patch("operations.worker.time.monotonic", return_value=now), \
|
||||
patch.object(fakes.ScriptedKind, "reconcile", side_effect=OSError("host down")):
|
||||
self.run_due()
|
||||
self.assertEqual(self.reload(op).state,
|
||||
Operation.UNCERTAIN if now == 1000 + RECOVERY_LIMIT else Operation.RUNNING)
|
||||
self.assertTrue(words(op.error).endswith(UNREACHABLE))
|
||||
self.assertTrue(Claim.objects.filter(operation=op).exists())
|
||||
|
||||
def test_an_answer_restarts_the_recovery_limit(self):
|
||||
op = self.orphan({})
|
||||
with patch("operations.worker.time.monotonic", return_value=1000), \
|
||||
patch.object(fakes.ScriptedKind, "reconcile", side_effect=OSError("host down")):
|
||||
self.run_due()
|
||||
self.scheduler.next_try[op.pk] = 0
|
||||
self.run_at(1100, Outcome(Operation.RUNNING))
|
||||
self.assertNotIn(op.pk, self.scheduler.failing_since)
|
||||
|
||||
def test_a_job_that_never_recorded_its_intent_fails(self):
|
||||
op = self.orphan({}, effects=False)
|
||||
self.run_due()
|
||||
|
|
|
|||
|
|
@ -44,6 +44,9 @@ STALLED = gettext_noop("libvirt's merge finished copying but never completed (fo
|
|||
ABANDONED = gettext_noop("The worker that ran this job stopped responding; an administrator must make sure it "
|
||||
"is no longer running, then resolve this job")
|
||||
WAITING = gettext_noop("Waiting for recovery")
|
||||
RECOVERY_LIMIT = 3600 # a host gone for good would keep its jobs and their claims forever
|
||||
UNREACHABLE = gettext_noop("Recovery could not read the job's state for an hour; check the VM, then "
|
||||
"resolve this job")
|
||||
ACTIVE = (Operation.RUNNING, Operation.CANCELLING)
|
||||
|
||||
|
||||
|
|
@ -387,6 +390,7 @@ class Scheduler:
|
|||
self.attempts = {}
|
||||
self.errors = {}
|
||||
self.stalled_since = {}
|
||||
self.failing_since = {}
|
||||
self.inflight = set()
|
||||
|
||||
def schedule_orphans(self):
|
||||
|
|
@ -409,7 +413,7 @@ class Scheduler:
|
|||
self.inflight.discard(op_id) # its host's control task still runs: a later tick
|
||||
|
||||
def _done(self, op_id):
|
||||
for table in (self.next_try, self.attempts, self.errors, self.stalled_since):
|
||||
for table in (self.next_try, self.attempts, self.errors, self.stalled_since, self.failing_since):
|
||||
table.pop(op_id, None)
|
||||
|
||||
def _take_over(self, op):
|
||||
|
|
@ -462,12 +466,18 @@ class Scheduler:
|
|||
try:
|
||||
outcome = jobs.get_kind(op.kind).reconcile(op)
|
||||
except Exception as err:
|
||||
now = time.monotonic()
|
||||
if now - self.failing_since.setdefault(op_id, now) >= RECOVERY_LIMIT:
|
||||
self._finish(op, jobs.Outcome(Operation.UNCERTAIN, error=self._error(
|
||||
op_id, [*utils.public_error(err), *utils.say(UNREACHABLE)])))
|
||||
return
|
||||
n = self.attempts.get(op_id, 0)
|
||||
self.attempts[op_id] = n + 1
|
||||
self.next_try[op_id] = time.monotonic() + BACKOFF[min(n, len(BACKOFF) - 1)]
|
||||
self.next_try[op_id] = now + BACKOFF[min(n, len(BACKOFF) - 1)]
|
||||
self._phase(op_id, WAITING)
|
||||
logger.warning("recovery of job %s waits: %s", op_id, utils.safe_text(err))
|
||||
return
|
||||
self.failing_since.pop(op_id, None)
|
||||
if outcome.state == Operation.RUNNING:
|
||||
now = time.monotonic()
|
||||
if not outcome.stalled:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue