Package ganeti :: Module locking :: Class LockSet
[hide private]
[frames] | no frames]

Class LockSet

source code

Implements a set of locks.

This abstraction implements a set of shared locks for the same resource type, distinguished by name. The user can lock a subset of the resources and the LockSet will take care of acquiring the locks always in the same order, thus preventing deadlock.

All the locks needed in the same set must be acquired together, though.

Instance Methods [hide private]
 
__init__(self, members, name, monitor=None)
Constructs a new LockSet.
source code
 
_GetLockName(self, mname)
Returns the name for a member lock.
source code
 
_is_owned(self)
Is the current thread a current level owner?
source code
 
_add_owned(self, name=None)
Note the current thread owns the given lock
source code
 
_del_owned(self, name=None)
Note the current thread owns the given lock
source code
 
_list_owned(self)
Get the set of resource names owned by the current thread
source code
 
_release_and_delete_owned(self)
Release and delete all resources owned by the current thread
source code
 
__names(self)
Return the current set of names.
source code
 
_names(self)
Return a copy of the current set of elements.
source code
 
acquire(self, names, timeout=None, shared=0, test_notify=None)
Acquire a set of resource locks.
source code
 
__acquire_inner(self, names, want_all, shared, timeout_fn, test_notify)
Inner logic for acquiring a number of locks.
source code
 
release(self, names=None)
Release a set of resource locks, at the same level.
source code
 
add(self, names, acquired=0, shared=0)
Add a new set of elements to the set
source code
 
remove(self, names)
Remove elements from the lock set.
source code
Instance Variables [hide private]
string name
the name of the lockset
Method Details [hide private]

__init__(self, members, name, monitor=None)
(Constructor)

source code 

Constructs a new LockSet.

Parameters:
  • members (list of strings) - initial members of the set
  • monitor (LockMonitor) - Lock monitor with which to register member locks

__names(self)

source code 

Return the current set of names.

Only call this function while holding __lock and don't iterate on the result after releasing the lock.

_names(self)

source code 

Return a copy of the current set of elements.

Used only for debugging purposes.

acquire(self, names, timeout=None, shared=0, test_notify=None)

source code 

Acquire a set of resource locks.

Parameters:
  • names (list of strings (or string)) - the names of the locks which shall be acquired (special lock names, or instance/node names)
  • shared (integer (0/1) used as a boolean) - whether to acquire in shared mode; by default an exclusive lock will be acquired
  • timeout (float or None) - Maximum time to acquire all locks
  • test_notify (callable or None) - Special callback function for unittesting
Returns:
Set of all locks successfully acquired or None in case of timeout
Raises:
  • errors.LockError - when any lock we try to acquire has been deleted before we succeed. In this case none of the locks requested will be acquired.

__acquire_inner(self, names, want_all, shared, timeout_fn, test_notify)

source code 

Inner logic for acquiring a number of locks.

Parameters:
  • names - Names of the locks to be acquired
  • want_all - Whether all locks in the set should be acquired
  • shared - Whether to acquire in shared mode
  • timeout_fn - Function returning remaining timeout
  • test_notify - Special callback function for unittesting

release(self, names=None)

source code 

Release a set of resource locks, at the same level.

You must have acquired the locks, either in shared or in exclusive mode, before releasing them.

Parameters:
  • names (list of strings, or None) - the names of the locks which shall be released (defaults to all the locks acquired at that level).

add(self, names, acquired=0, shared=0)

source code 

Add a new set of elements to the set

Parameters:
  • names (list of strings) - names of the new elements to add
  • acquired (integer (0/1) used as a boolean) - pre-acquire the new resource?
  • shared (integer (0/1) used as a boolean) - is the pre-acquisition shared?

remove(self, names)

source code 

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.

Parameters:
  • names (list of strings) - names of the resource to remove.
Returns:
a list of locks which we removed; the list is always equal to the names list if we were holding all the locks exclusively