Coordination and locking utilities.
Coordinator
(agent_id=None, prefix='')¶Bases: object
Tooz coordination wrapper.
Coordination member id is created from concatenated prefix and agent_id parameters.
Parameters: |
|
---|
get_lock
(name)¶Return a Tooz backend lock.
Parameters: | name (str) – The lock name that is used to identify it across all nodes. |
---|
start
()¶stop
()¶Disconnect from coordination backend and stop heartbeat.
synchronized
(lock_name, blocking=True, coordinator=<cinder.coordination.Coordinator object>)¶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.
Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.