Skip to content
Snippets Groups Projects
Commit 211b6132 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

mcpu: Improve lock reporting with timeouts


Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 407339d0
No related branches found
No related tags found
No related merge requests found
...@@ -221,7 +221,7 @@ class Processor(object): ...@@ -221,7 +221,7 @@ class Processor(object):
self.rpc = rpc.RpcRunner(context.cfg) self.rpc = rpc.RpcRunner(context.cfg)
self.hmclass = HooksMaster self.hmclass = HooksMaster
def _ReportLocks(self, level, names, shared, acquired): def _ReportLocks(self, level, names, shared, timeout, acquired, result):
"""Reports lock operations. """Reports lock operations.
@type level: int @type level: int
...@@ -229,18 +229,29 @@ class Processor(object): ...@@ -229,18 +229,29 @@ class Processor(object):
@type names: list or string @type names: list or string
@param names: Lock names @param names: Lock names
@type shared: bool @type shared: bool
@param shared: Whether the lock should be acquired in shared mode @param shared: Whether the locks should be acquired in shared mode
@type timeout: None or float
@param timeout: Timeout for acquiring the locks
@type acquired: bool @type acquired: bool
@param acquired: Whether the lock has already been acquired @param acquired: Whether the locks have already been acquired
@type result: None or set
@param result: Result from L{locking.GanetiLockManager.acquire}
""" """
parts = [] parts = []
# Build message # Build message
if acquired: if acquired:
parts.append("acquired") if result is None:
parts.append("timeout")
else:
parts.append("acquired")
else: else:
parts.append("waiting") parts.append("waiting")
if timeout is None:
parts.append("blocking")
else:
parts.append("timeout=%0.6fs" % timeout)
parts.append(locking.LEVEL_NAMES[level]) parts.append(locking.LEVEL_NAMES[level])
...@@ -263,6 +274,28 @@ class Processor(object): ...@@ -263,6 +274,28 @@ class Processor(object):
if self._cbs: if self._cbs:
self._cbs.ReportLocks(msg) self._cbs.ReportLocks(msg)
def _AcquireLocks(self, level, names, shared, timeout):
"""Acquires locks via the Ganeti lock manager.
@type level: int
@param level: Lock level
@type names: list or string
@param names: Lock names
@type shared: bool
@param shared: Whether the locks should be acquired in shared mode
@type timeout: None or float
@param timeout: Timeout for acquiring the locks
"""
self._ReportLocks(level, names, shared, timeout, False, None)
acquired = self.context.glm.acquire(level, names, shared=shared,
timeout=timeout)
self._ReportLocks(level, names, shared, timeout, True, acquired)
return acquired
def _ExecLU(self, lu): def _ExecLU(self, lu):
"""Logical Unit execution sequence. """Logical Unit execution sequence.
...@@ -328,13 +361,8 @@ class Processor(object): ...@@ -328,13 +361,8 @@ class Processor(object):
# Acquiring locks # Acquiring locks
needed_locks = lu.needed_locks[level] needed_locks = lu.needed_locks[level]
self._ReportLocks(level, needed_locks, share, False) acquired = self._AcquireLocks(level, needed_locks, share,
acquired = self.context.glm.acquire(level, calc_timeout())
needed_locks,
shared=share,
timeout=calc_timeout())
# TODO: Report timeout
self._ReportLocks(level, needed_locks, share, True)
if acquired is None: if acquired is None:
raise _LockAcquireTimeout() raise _LockAcquireTimeout()
...@@ -392,22 +420,11 @@ class Processor(object): ...@@ -392,22 +420,11 @@ class Processor(object):
while True: while True:
try: try:
self._ReportLocks(locking.LEVEL_CLUSTER, [locking.BGL], # Acquire the Big Ganeti Lock exclusively if this LU requires it,
not lu_class.REQ_BGL, False) # and in a shared fashion otherwise (to prevent concurrent run with
try: # an exclusive LU.
# Acquire the Big Ganeti Lock exclusively if this LU requires it, if self._AcquireLocks(locking.LEVEL_CLUSTER, locking.BGL,
# and in a shared fashion otherwise (to prevent concurrent run with not lu_class.REQ_BGL, calc_timeout()) is None:
# an exclusive LU.
acquired_bgl = self.context.glm.acquire(locking.LEVEL_CLUSTER,
[locking.BGL],
shared=not lu_class.REQ_BGL,
timeout=calc_timeout())
finally:
# TODO: Report timeout
self._ReportLocks(locking.LEVEL_CLUSTER, [locking.BGL],
not lu_class.REQ_BGL, True)
if acquired_bgl is None:
raise _LockAcquireTimeout() raise _LockAcquireTimeout()
try: try:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment