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

Class GanetiLockManager

source code

The Ganeti Locking Library

The purpose of this small library is to manage locking for ganeti clusters in a central place, while at the same time doing dynamic checks against possible deadlocks. It will also make it easier to transition to a different lock type should we migrate away from python threads.

Instance Methods [hide private]
 
__init__(self, node_uuids, nodegroups, instance_names, networks)
Constructs a new GanetiLockManager object.
source code
 
AddToLockMonitor(self, provider)
Registers a new lock with the monitor.
source code
 
QueryLocks(self, fields)
Queries information from all locks.
source code
 
_names(self, level)
List the lock names at the given level.
source code
 
is_owned(self, level)
Check whether we are owning locks at the given level
source code
 
list_owned(self, level)
Get the set of owned locks at the given level
source code
 
check_owned(self, level, names, shared=-1)
Check if locks at a certain level are owned in a specific mode.
source code
 
owning_all(self, level)
Checks whether current thread owns all locks at a certain level.
source code
 
_upper_owned(self, level)
Check that we don't own any lock at a level greater than the given one.
source code
 
_BGL_owned(self)
Check if the current thread owns the BGL.
source code
 
acquire(self, level, names, timeout=None, shared=0, priority=None, opportunistic=False)
Acquire a set of resource locks, at the same level.
source code
 
downgrade(self, level, names=None)
Downgrade a set of resource locks from exclusive to shared mode.
source code
 
release(self, level, names=None)
Release a set of resource locks, at the same level.
source code
 
add(self, level, names, acquired=0, shared=0)
Add locks at the specified level.
source code
 
remove(self, level, names)
Remove locks from the specified level.
source code
Static Methods [hide private]
 
_contains_BGL(level, names)
Check if the level contains the BGL.
source code
Class Variables [hide private]
  _instance = None
Method Details [hide private]

__init__(self, node_uuids, nodegroups, instance_names, networks)
(Constructor)

source code 

Constructs a new GanetiLockManager object.

There should be only a GanetiLockManager object at any time, so this function raises an error if this is not the case.

Parameters:
  • node_uuids - list of node UUIDs
  • nodegroups - list of nodegroup uuids
  • instance_names - list of instance names

AddToLockMonitor(self, provider)

source code 

Registers a new lock with the monitor.

See LockMonitor.RegisterLock.

QueryLocks(self, fields)

source code 

Queries information from all locks.

See LockMonitor.QueryLocks.

_names(self, level)

source code 

List the lock names at the given level.

This can be used for debugging/testing purposes.

Parameters:
  • level - the level whose list of locks to get

check_owned(self, level, names, shared=-1)

source code 

Check if locks at a certain level are owned in a specific mode.

owning_all(self, level)

source code 

Checks whether current thread owns all locks at a certain level.

See Also: LockSet.owning_all

_BGL_owned(self)

source code 

Check if the current thread owns the BGL.

Both an exclusive or a shared acquisition work.

_contains_BGL(level, names)
Static Method

source code 

Check if the level contains the BGL.

Check if acting on the given level and set of names will change the status of the Big Ganeti Lock.

acquire(self, level, names, timeout=None, shared=0, priority=None, opportunistic=False)

source code 

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

Parameters:
  • level (member of locking.LEVELS) - the level at which the locks shall be acquired
  • 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) - Maximum time to acquire all locks
  • priority (integer) - Priority for acquiring lock
  • opportunistic (boolean) - Acquire locks opportunistically; use the return value to determine which locks were actually acquired

downgrade(self, level, names=None)

source code 

Downgrade a set of resource locks from exclusive to shared mode.

You must have acquired the locks in exclusive mode.

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

release(self, level, 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:
  • level (member of locking.LEVELS) - the level at which the locks shall be released
  • 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, level, names, acquired=0, shared=0)

source code 

Add locks at the specified level.

Parameters:
  • level (member of locking.LEVELS_MOD) - the level at which the locks shall be added
  • names (list of strings) - names of the locks to acquire
  • acquired (integer (0/1) used as a boolean) - whether to acquire the newly added locks
  • shared (integer (0/1) used as a boolean) - whether the acquisition will be shared

remove(self, level, names)

source code 

Remove locks from the specified level.

You must either already own the locks you are trying to remove exclusively or not own any lock at an upper level.

Parameters:
  • level (member of locking.LEVELS_MOD) - the level at which the locks shall be removed
  • names (list of strings) - the names of the locks which shall be removed (special lock names, or instance/node names)