Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
...@@ -759,15 +759,15 @@ class LockSet: ...@@ -759,15 +759,15 @@ class LockSet:
self.__lock.release() self.__lock.release()
return set(result) 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. """Acquire a set of resource locks.
@param names: the names of the locks which shall be acquired @param names: the names of the locks which shall be acquired
(special lock names, or instance/node names) (special lock names, or instance/node names)
@param shared: whether to acquire in shared mode; by default an @param shared: whether to acquire in shared mode; by default an
exclusive lock will be acquired exclusive lock will be acquired
@param blocking: whether to block while trying to acquire or to @type timeout: float
operate in try-lock mode (this locking mode is not supported yet) @param timeout: Maximum time to acquire all locks
@return: True when all the locks are successfully acquired @return: True when all the locks are successfully acquired
...@@ -776,8 +776,7 @@ class LockSet: ...@@ -776,8 +776,7 @@ class LockSet:
locks requested will be acquired. locks requested will be acquired.
""" """
if not blocking: if timeout is not None:
# We don't have non-blocking mode for now
raise NotImplementedError raise NotImplementedError
# Check we don't already own locks at this level # Check we don't already own locks at this level
...@@ -961,26 +960,19 @@ class LockSet: ...@@ -961,26 +960,19 @@ class LockSet:
return True return True
def remove(self, names, blocking=1): def remove(self, names):
"""Remove elements from the lock set. """Remove elements from the lock set.
You can either not hold anything in the lockset or already hold a superset You can either not hold anything in the lockset or already hold a superset
of the elements you want to delete, exclusively. of the elements you want to delete, exclusively.
@param names: names of the resource to remove. @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 @return:: a list of locks which we removed; the list is always
equal to the names list if we were holding all the locks equal to the names list if we were holding all the locks
exclusively 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 # Support passing in a single resource to remove rather than many
if isinstance(names, basestring): if isinstance(names, basestring):
names = [names] names = [names]
...@@ -1135,7 +1127,7 @@ class GanetiLockManager: ...@@ -1135,7 +1127,7 @@ class GanetiLockManager:
""" """
return level == LEVEL_CLUSTER and (names is None or BGL in names) 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. """Acquire a set of resource locks, at the same level.
@param level: the level at which the locks shall be acquired; @param level: the level at which the locks shall be acquired;
...@@ -1144,8 +1136,8 @@ class GanetiLockManager: ...@@ -1144,8 +1136,8 @@ class GanetiLockManager:
(special lock names, or instance/node names) (special lock names, or instance/node names)
@param shared: whether to acquire in shared mode; by default @param shared: whether to acquire in shared mode; by default
an exclusive lock will be acquired an exclusive lock will be acquired
@param blocking: whether to block while trying to acquire or to @type timeout: float
operate in try-lock mode (this locking mode is not supported yet) @param timeout: Maximum time to acquire all locks
""" """
assert level in LEVELS, "Invalid locking level %s" % level assert level in LEVELS, "Invalid locking level %s" % level
...@@ -1164,8 +1156,7 @@ class GanetiLockManager: ...@@ -1164,8 +1156,7 @@ class GanetiLockManager:
" while owning some at a greater one") " while owning some at a greater one")
# Acquire the locks in the set. # Acquire the locks in the set.
return self.__keyring[level].acquire(names, shared=shared, return self.__keyring[level].acquire(names, shared=shared, timeout=timeout)
blocking=blocking)
def release(self, level, names=None): def release(self, level, names=None):
"""Release a set of resource locks, at the same level. """Release a set of resource locks, at the same level.
...@@ -1205,7 +1196,7 @@ class GanetiLockManager: ...@@ -1205,7 +1196,7 @@ class GanetiLockManager:
" while owning some at a greater one") " while owning some at a greater one")
return self.__keyring[level].add(names, acquired=acquired, shared=shared) 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. """Remove locks from the specified level.
You must either already own the locks you are trying to remove You must either already own the locks you are trying to remove
...@@ -1215,8 +1206,6 @@ class GanetiLockManager: ...@@ -1215,8 +1206,6 @@ class GanetiLockManager:
it must be a member of LEVELS_MOD it must be a member of LEVELS_MOD
@param names: the names of the locks which shall be removed @param names: the names of the locks which shall be removed
(special lock names, or instance/node names) (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 assert level in LEVELS_MOD, "Invalid or immutable level %s" % level
...@@ -1228,4 +1217,4 @@ class GanetiLockManager: ...@@ -1228,4 +1217,4 @@ class GanetiLockManager:
assert self._is_owned(level) or not self._upper_owned(level), ( assert self._is_owned(level) or not self._upper_owned(level), (
"Cannot remove locks at a level while not owning it or" "Cannot remove locks at a level while not owning it or"
" owning some at a greater one") " 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): ...@@ -871,11 +871,10 @@ class TestLockSet(_ThreadedTestCase):
self.assert_('one' not in self.ls._names()) self.assert_('one' not in self.ls._names())
def testRemoveNonBlocking(self): def testRemoveNonBlocking(self):
self.assertRaises(NotImplementedError, self.ls.remove, 'one', blocking=0)
self.ls.acquire('one') 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.ls.acquire(['two', 'three'])
self.assertEquals(self.ls.remove(['two', 'three'], blocking=0), self.assertEquals(self.ls.remove(['two', 'three']),
['two', 'three']) ['two', 'three'])
def testNoDoubleAdd(self): def testNoDoubleAdd(self):
......
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