From 686d24f08f16f5dddba9792f001157402df8cb3a Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Thu, 22 Nov 2012 18:37:15 +0100 Subject: [PATCH] Support opportunistic locks in mcpu/LUs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Similar to βshare_locksβ, a new dictionary containing booleans for each locking level is added to βcmdlib.LogicalUnitβ. Logical units wanting to make use of opportunistic locks will be able to configure this dictionary accordingly. Signed-off-by: Michael Hanselmann <hansmi@google.com> Reviewed-by: Guido Trotter <ultrotter@google.com> --- lib/cmdlib.py | 7 ++++++- lib/mcpu.py | 12 ++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index b62732545..0d4b3df6e 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -138,13 +138,18 @@ class LogicalUnit(object): self.owned_locks = context.glm.list_owned self.context = context self.rpc = rpc_runner - # Dicts used to declare locking needs to mcpu + + # Dictionaries used to declare locking needs to mcpu self.needed_locks = None self.share_locks = dict.fromkeys(locking.LEVELS, 0) + self.opportunistic_locks = dict.fromkeys(locking.LEVELS, False) + self.add_locks = {} self.remove_locks = {} + # Used to force good behavior when calling helper functions self.recalculate_locks = {} + # logging self.Log = processor.Log # pylint: disable=C0103 self.LogWarning = processor.LogWarning # pylint: disable=C0103 diff --git a/lib/mcpu.py b/lib/mcpu.py index f737f7e14..8f4946932 100644 --- a/lib/mcpu.py +++ b/lib/mcpu.py @@ -275,7 +275,7 @@ class Processor(object): if not self._enable_locks: raise errors.ProgrammerError("Attempted to use disabled locks") - def _AcquireLocks(self, level, names, shared, timeout): + def _AcquireLocks(self, level, names, shared, opportunistic, timeout): """Acquires locks via the Ganeti lock manager. @type level: int @@ -284,6 +284,8 @@ class Processor(object): @param names: Lock names @type shared: bool @param shared: Whether the locks should be acquired in shared mode + @type opportunistic: bool + @param opportunistic: Whether to acquire opportunistically @type timeout: None or float @param timeout: Timeout for acquiring the locks @raise LockAcquireTimeout: In case locks couldn't be acquired in specified @@ -298,7 +300,8 @@ class Processor(object): priority = None acquired = self.context.glm.acquire(level, names, shared=shared, - timeout=timeout, priority=priority) + timeout=timeout, priority=priority, + opportunistic=opportunistic) if acquired is None: raise LockAcquireTimeout() @@ -384,6 +387,7 @@ class Processor(object): lu.DeclareLocks(level) share = lu.share_locks[level] + opportunistic = lu.opportunistic_locks[level] try: assert adding_locks ^ acquiring_locks, \ @@ -393,7 +397,7 @@ class Processor(object): # Acquiring locks needed_locks = lu.needed_locks[level] - self._AcquireLocks(level, needed_locks, share, + self._AcquireLocks(level, needed_locks, share, opportunistic, calc_timeout()) else: # Adding locks @@ -457,7 +461,7 @@ class Processor(object): # and in a shared fashion otherwise (to prevent concurrent run with # an exclusive LU. self._AcquireLocks(locking.LEVEL_CLUSTER, locking.BGL, - not lu_class.REQ_BGL, calc_timeout()) + not lu_class.REQ_BGL, False, calc_timeout()) elif lu_class.REQ_BGL: raise errors.ProgrammerError("Opcode '%s' requires BGL, but locks are" " disabled" % op.OP_ID) -- GitLab