diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 588381729384e67498203cac1f0c614533b09dba..7e6d879d4d05ba1c7ea35a216388cee623c0e82c 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -2096,6 +2096,8 @@ def _WaitForSync(lu, instance, oneshot=False, unlock=False): for dev in instance.disks: lu.cfg.SetDiskID(dev, node) + # TODO: Convert to utils.Retry + retries = 0 degr_retries = 10 # in seconds, as we sleep 1 second each time while True: diff --git a/lib/jqueue.py b/lib/jqueue.py index 91a721a01606201005042a9bc03eace6e421bdec..73d6a0ed571e34ce841a6cd52178a72f28df2455 100644 --- a/lib/jqueue.py +++ b/lib/jqueue.py @@ -1140,21 +1140,13 @@ class JobQueue(object): as such by the clients """ - logging.debug("Waiting for changes in job %s", job_id) - - job_info = None - log_entries = None - - end_time = time.time() + timeout - while True: - delta_time = end_time - time.time() - if delta_time < 0: - return constants.JOB_NOTCHANGED + job = self._LoadJobUnlocked(job_id) + if not job: + logging.debug("Job %s not found", job_id) + return None - job = self._LoadJobUnlocked(job_id) - if not job: - logging.debug("Job %s not found", job_id) - break + def _CheckForChanges(): + logging.debug("Waiting for changes in job %s", job_id) status = job.CalcStatus() job_info = self._GetJobInfoUnlocked(job, fields) @@ -1168,28 +1160,24 @@ class JobQueue(object): job_info = serializer.LoadJson(serializer.DumpJson(job_info)) log_entries = serializer.LoadJson(serializer.DumpJson(log_entries)) - if status not in (constants.JOB_STATUS_QUEUED, - constants.JOB_STATUS_RUNNING, - constants.JOB_STATUS_WAITLOCK): - # Don't even try to wait if the job is no longer running, there will be - # no changes. - break - - if (prev_job_info != job_info or + # Don't even try to wait if the job is no longer running, there will be + # no changes. + if (status not in (constants.JOB_STATUS_QUEUED, + constants.JOB_STATUS_RUNNING, + constants.JOB_STATUS_WAITLOCK) or + prev_job_info != job_info or (log_entries and prev_log_serial != log_entries[0][0])): - break - - logging.debug("Waiting again") + logging.debug("Job %s changed", job_id) + return (job_info, log_entries) - # Release the queue lock while waiting - job.change.wait(delta_time) + raise utils.RetryAgain() - logging.debug("Job %s changed", job_id) - - if job_info is None and log_entries is None: - return None - else: - return (job_info, log_entries) + try: + # Setting wait function to release the queue lock while waiting + return utils.Retry(_CheckForChanges, utils.RETRY_REMAINING_TIME, timeout, + wait_fn=job.change.wait) + except utils.RetryTimeout: + return constants.JOB_NOTCHANGED @utils.LockedMethod @_RequireOpenQueue