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, nodes, instances)
Constructs a new GanetiLockManager object.
source code
 
QueryLocks(self, fields, sync)
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
 
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
 
_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)
Acquire a set of resource locks, at the same level.
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, nodes, instances)
(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:
  • nodes - list of node names
  • instances - list of instance names

QueryLocks(self, fields, sync)

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

_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)

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

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)