Coordination and locking utilities.
Bases: object
Tooz coordination wrapper.
Coordination member id is created from concatenated prefix and agent_id parameters.
Parameters: |
|
---|
Return a Tooz backend lock.
Parameters: | name (str) – The lock name that is used to identify it across all nodes. |
---|
Coordinator heartbeat.
Method that every couple of seconds (config: coordination.heartbeat) sends heartbeat to prove that the member is not dead.
If connection to coordination backend is broken it tries to reconnect every couple of seconds (config: coordination.initial_reconnect_backoff up to coordination.max_reconnect_backoff)
Connect to coordination backend and start heartbeat.
Disconnect from coordination backend and stop heartbeat.
Bases: tooz.locking.Lock
Lock with dynamic name.
Parameters: |
|
---|
Using it like so:
with Lock('mylock'):
...
ensures that only one process at a time will execute code in context. Lock name can be formatted using Python format string syntax:
Lock('foo-{volume.id}, {'volume': ...,})
Available field names are keys of lock_data.
Attempts to acquire lock.
Parameters: | blocking – If True, blocks until the lock is acquired. If False, returns right away. Otherwise, the value is used as a timeout value and the call returns maximum after this number of seconds. |
---|---|
Returns: | returns true if acquired (false if not) |
Return type: | bool |
Attempts to release lock.
The behavior of releasing a lock which was not acquired in the first place is undefined. :return: returns true if released (false if not) :rtype: bool
Synchronization decorator.
Parameters: |
|
---|---|
Raises tooz.coordination.LockAcquireFailed: | |
if lock is not acquired |
Decorating a method like so:
@synchronized('mylock')
def foo(self, *args):
...
ensures that only one process will execute the foo method at a time.
Different methods can share the same lock:
@synchronized('mylock')
def foo(self, *args):
...
@synchronized('mylock')
def bar(self, *args):
...
This way only one of either foo or bar can be executing at a time.
Lock name can be formatted using Python format string syntax:
@synchronized('{f_name}-{vol.id}-{snap[name]}')
def foo(self, vol, snap):
...
Available field names are: decorated function parameters and f_name as a decorated function name.