On Wed, Jun 4, 2014 at 10:20 AM, 'Klaus Aehlig' via ganeti-devel <
[email protected]> wrote:

> Instead of only polling make mcpu ask wconfd to hand out the
> locks as soon as they become available. For the time being,
> we still poll to find out if the request was granted. Nevertheless,
> this will ensure that locks are handed out in the intended order,
> in particular honoring job priorities.
>
> Signed-off-by: Klaus Aehlig <[email protected]>
> ---
>  lib/mcpu.py | 22 ++++++++++++----------
>  1 file changed, 12 insertions(+), 10 deletions(-)
>
> diff --git a/lib/mcpu.py b/lib/mcpu.py
> index 952b3c0..3c33ea6 100644
> --- a/lib/mcpu.py
> +++ b/lib/mcpu.py
> @@ -395,22 +395,24 @@ class Processor(object):
>        locks =
> self.wconfd.Client().OpportunisticLockUnion(self._wconfdcontext,
>                                                            request)
>      elif timeout is None:
> +      # TODO: use correct priority instead of 0
> +      self.wconfd.Client().UpdateLocksWaiting(self._wconfdcontext, 0,
> request)
>        while True:
> -        ## TODO: use asynchronous wait instead of polling
> -        blockedon =
> self.wconfd.Client().TryUpdateLocks(self._wconfdcontext,
> -                                                        request)
> -        logging.debug("Requesting %s for %s blocked on %s",
> -                      request, self._wconfdcontext, blockedon)
> -        if not blockedon:
> +        pending =
> self.wconfd.Client().HasPendingRequest(self._wconfdcontext)
> +        if not pending:
>            break
>          time.sleep(random.random())
>

Are we sure that the request is always fulfilled? If it gets cancelled, the
request is also removed from 'pending', right?


>      else:
>        logging.debug("Trying %ss to request %s for %s",
>                      timeout, request, self._wconfdcontext)
> -      ## TODO: use blocking wait instead of polling
> -      blocked = utils.SimpleRetry([],
> self.wconfd.Client().TryUpdateLocks, 0.1,
> -                                  timeout, args=[self._wconfdcontext,
> request])
> -      if blocked:
> +      # TODO: use correct priority instead of 0
> +      self.wconfd.Client().UpdateLocksWaiting(self._wconfdcontext, 0,
> request)
> +      pending = utils.SimpleRetry(False,
> self.wconfd.Client().HasPendingRequest,
> +                                  0.1, timeout,
> args=[self._wconfdcontext])
> +      if pending:
> +        # drop the pending request and all locks potentially obtained in
> the
> +        # timne since the last poll.
>

s/timne/time/


> +        self.wconfd.Client().FreeLocksLevel(self._wconfdcontext,
> levelname)
>          raise LockAcquireTimeout()
>
>      return locks
> --
> 1.9.1.423.g4596e3a
>
>
Rest LGTM

Reply via email to