Commit 5e0a6daf authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Rename LockSet.acquire parameter “blocking” to “timeout”



Also remove the “blocking” parameter from LockSet.remove and
GanetiLockManager.remove. There's no point in implementing timeouts on removal
unless we need them.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 2042aa94
......@@ -759,15 +759,15 @@ class LockSet:
self.__lock.release()
return set(result)
def acquire(self, names, blocking=1, shared=0):
def acquire(self, names, timeout=None, shared=0):
"""Acquire a set of resource locks.
@param names: the names of the locks which shall be acquired
(special lock names, or instance/node names)
@param shared: whether to acquire in shared mode; by default an
exclusive lock will be acquired
@param blocking: whether to block while trying to acquire or to
operate in try-lock mode (this locking mode is not supported yet)
@type timeout: float
@param timeout: Maximum time to acquire all locks
@return: True when all the locks are successfully acquired
......@@ -776,8 +776,7 @@ class LockSet:
locks requested will be acquired.
"""
if not blocking:
# We don't have non-blocking mode for now
if timeout is not None:
raise NotImplementedError
# Check we don't already own locks at this level
......@@ -961,26 +960,19 @@ class LockSet:
return True
def remove(self, names, blocking=1):
def remove(self, names):
"""Remove elements from the lock set.
You can either not hold anything in the lockset or already hold a superset
of the elements you want to delete, exclusively.
@param names: names of the resource to remove.
@param blocking: whether to block while trying to acquire or to
operate in try-lock mode (this locking mode is not supported
yet unless you are already holding exclusively the locks)
@return:: a list of locks which we removed; the list is always
equal to the names list if we were holding all the locks
exclusively
"""
if not blocking and not self._is_owned():
# We don't have non-blocking mode for now
raise NotImplementedError
# Support passing in a single resource to remove rather than many
if isinstance(names, basestring):
names = [names]
......@@ -1135,7 +1127,7 @@ class GanetiLockManager:
"""
return level == LEVEL_CLUSTER and (names is None or BGL in names)
def acquire(self, level, names, blocking=1, shared=0):
def acquire(self, level, names, timeout=None, shared=0):
"""Acquire a set of resource locks, at the same level.
@param level: the level at which the locks shall be acquired;
......@@ -1144,8 +1136,8 @@ class GanetiLockManager:
(special lock names, or instance/node names)
@param shared: whether to acquire in shared mode; by default
an exclusive lock will be acquired
@param blocking: whether to block while trying to acquire or to
operate in try-lock mode (this locking mode is not supported yet)
@type timeout: float
@param timeout: Maximum time to acquire all locks
"""
assert level in LEVELS, "Invalid locking level %s" % level
......@@ -1164,8 +1156,7 @@ class GanetiLockManager:
" while owning some at a greater one")
# Acquire the locks in the set.
return self.__keyring[level].acquire(names, shared=shared,
blocking=blocking)
return self.__keyring[level].acquire(names, shared=shared, timeout=timeout)
def release(self, level, names=None):
"""Release a set of resource locks, at the same level.
......@@ -1205,7 +1196,7 @@ class GanetiLockManager:
" while owning some at a greater one")
return self.__keyring[level].add(names, acquired=acquired, shared=shared)
def remove(self, level, names, blocking=1):
def remove(self, level, names):
"""Remove locks from the specified level.
You must either already own the locks you are trying to remove
......@@ -1215,8 +1206,6 @@ class GanetiLockManager:
it must be a member of LEVELS_MOD
@param names: the names of the locks which shall be removed
(special lock names, or instance/node names)
@param blocking: whether to block while trying to operate in
try-lock mode (this locking mode is not supported yet)
"""
assert level in LEVELS_MOD, "Invalid or immutable level %s" % level
......@@ -1228,4 +1217,4 @@ class GanetiLockManager:
assert self._is_owned(level) or not self._upper_owned(level), (
"Cannot remove locks at a level while not owning it or"
" owning some at a greater one")
return self.__keyring[level].remove(names, blocking=blocking)
return self.__keyring[level].remove(names)
......@@ -871,11 +871,10 @@ class TestLockSet(_ThreadedTestCase):
self.assert_('one' not in self.ls._names())
def testRemoveNonBlocking(self):
self.assertRaises(NotImplementedError, self.ls.remove, 'one', blocking=0)
self.ls.acquire('one')
self.assertEquals(self.ls.remove('one', blocking=0), ['one'])
self.assertEquals(self.ls.remove('one'), ['one'])
self.ls.acquire(['two', 'three'])
self.assertEquals(self.ls.remove(['two', 'three'], blocking=0),
self.assertEquals(self.ls.remove(['two', 'three']),
['two', 'three'])
def testNoDoubleAdd(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment