Developers

Interfaces

class tooz.coordination.CoordinationDriver[source]

Bases: object

__weakref__

list of weak references to the object (if defined)

static create_group(group_id)[source]

Request the creation of a group asynchronously.

Parameters:group_id (str) – the id of the group to create
Returns:None
Return type:CoordAsyncResult
static delete_group(group_id)[source]

Delete a group asynchronously.

Parameters:group_id (str) – the id of the group to leave
Returns:Result
Return type:CoordAsyncResult
static get_groups()[source]

Return the list composed by all groups ids asynchronously.

Returns:the list of all created group ids
Return type:CoordAsyncResult
static get_leader(group_id)[source]

Return the leader for a group.

Parameters:group_id – the id of the group:
Returns:the leader
Return type:CoordAsyncResult
static get_lock(name)[source]

Return a distributed lock.

Parameters:name – The lock name that is used to identify it across all nodes.
static get_member_capabilities(group_id, member_id)[source]

Return the capabilities of a member asynchronously.

Parameters:
  • group_id (str) – the id of the group of the member
  • member_id (str) – the id of the member
Returns:

capabilities of a member

Return type:

CoordAsyncResult

static get_members(group_id)[source]

Return the list of all members ids of the specified group asynchronously.

Returns:list of all created group ids
Return type:CoordAsyncResult
static heartbeat()[source]

Method to run once in a while to be sure that the member is not dead and is still an active member of a group.

static join_group(group_id, capabilities='')[source]

Join a group and establish group membership asynchronously.

Parameters:
  • group_id (str) – the id of the group to join
  • capabilities (object (typically str)) – the capabilities of the joined member
Returns:

None

Return type:

CoordAsyncResult

static leave_group(group_id)[source]

Leave a group asynchronously.

Parameters:group_id (str) – the id of the group to leave
Returns:None
Return type:CoordAsyncResult
static run_watchers()[source]

Run the watchers callback.

static stand_down_group_leader(group_id)[source]

Stand down as the group leader if we are.

Parameters:group_id – The group where we don’t want to be a leader anymore
start()[source]

Start the service engine.

If needed, the establishment of a connection to the servers is initiated.

stop()[source]

Stop the service engine.

If needed, the connection to servers is closed and the client will disappear from all joined groups.

unwatch_elected_as_leader(group_id, callback)[source]

Call a function when member gets elected as leader.

The callback functions will be executed when run_watchers is called.

Parameters:
  • group_id – The group id to watch
  • callback – The function to execute when a member leaves this group
unwatch_join_group(group_id, callback)[source]

Stop executing a function when a group_id sees a new member joined.

Parameters:
  • group_id – The group id to unwatch
  • callback – The function that was executed when a member joined this group
unwatch_leave_group(group_id, callback)[source]

Stop executing a function when a group_id sees a new member leaving.

Parameters:
  • group_id – The group id to unwatch
  • callback – The function that was executed when a member left this group
static update_capabilities(group_id, capabilities)[source]

Update capabilities of the caller in the specified group asynchronously.

Parameters:
  • group_id (str) – the id of the group of the current member
  • capabilities (object (typically str)) – the capabilities of the updated member
Returns:

None

Return type:

CoordAsyncResult

watch_elected_as_leader(group_id, callback)[source]

Call a function when member gets elected as leader.

The callback functions will be executed when run_watchers is called.

Parameters:
  • group_id – The group id to watch
  • callback – The function to execute when a member leaves this group
watch_join_group(group_id, callback)[source]

Call a function when group_id sees a new member joined.

The callback functions will be executed when run_watchers is called.

Parameters:
  • group_id – The group id to watch
  • callback – The function to execute when a member joins this group
watch_leave_group(group_id, callback)[source]

Call a function when group_id sees a new member leaving.

The callback functions will be executed when run_watchers is called.

Parameters:
  • group_id – The group id to watch
  • callback – The function to execute when a member leaves this group

File

class tooz.drivers.file.FileDriver(member_id, parsed_url, options)[source]

Bases: tooz.coordination.CoordinationDriver

A file based driver.

__init__(member_id, parsed_url, options)[source]

Initialize the file driver.

IPC

class tooz.drivers.ipc.IPCDriver(member_id, parsed_url, options)[source]

Bases: tooz.coordination.CoordinationDriver

A IPC based driver.

__init__(member_id, parsed_url, options)[source]

Initialize the IPC driver.

Memcached

class tooz.drivers.memcached.MemcachedDriver(member_id, parsed_url, options)[source]

Bases: tooz.coordination.CoordinationDriver

A memcached based driver.

Mysql

class tooz.drivers.mysql.MySQLDriver(member_id, parsed_url, options)[source]

Bases: tooz.coordination.CoordinationDriver

A mysql based driver.

__init__(member_id, parsed_url, options)[source]

Initialize the MySQL driver.

PostgreSQL

class tooz.drivers.pgsql.PostgresDriver(member_id, parsed_url, options)[source]

Bases: tooz.coordination.CoordinationDriver

A PostgreSQL based driver.

__init__(member_id, parsed_url, options)[source]

Initialize the PostgreSQL driver.

Redis

class tooz.drivers.redis.RedisDriver(member_id, parsed_url, options)[source]

Bases: tooz.coordination.CoordinationDriver

Redis provides a few nice benefits that act as a poormans zookeeper.

  • Durability (when setup with AOF mode).
  • Consistent, note that this is still restricted to only one redis server, without the recently released redis (alpha) clustering > 1 server will not be consistent when partitions or failures occur (even redis clustering docs state it is not a fully AP or CP solution, which means even with it there will still be potential inconsistencies).
  • Master/slave failover (when setup with redis sentinel), giving some notion of HA (values can be lost when a failover transition occurs).

To use a sentinel the connection URI must point to the Sentinel server. At connection time the sentinel will be asked for the current IP and port of the master and then connect there. The connection URI for sentinel should be written as follows:

redis://<sentinel host>:<sentinel port>?sentinel=<master name>

Additional sentinel hosts are listed with mutiple sentinel_fallback parameters as follows:

redis://<sentinel host>:<sentinel port>?sentinel=<master name>&
sentinel_fallback=<other sentinel host>:<sentinel port>& sentinel_fallback=<other sentinel host>:<sentinel port>& sentinel_fallback=<other sentinel host>:<sentinel port>

Further resources/links:

Note that this client will itself retry on transaction failure (when they keys being watched have changed underneath the current transaction). Currently the number of attempts that are tried is infinite (this might be addressed in https://github.com/andymccurdy/redis-py/issues/566 when that gets worked on). See http://redis.io/topics/transactions for more information on this topic.

Zake

class tooz.drivers.zake.ZakeDriver(member_id, parsed_url, options)[source]

Bases: tooz.drivers.zookeeper.KazooDriver

The driver using the Zake client which mimic a fake Kazoo client without the need of real ZooKeeper servers.

Zookeeper

class tooz.drivers.zookeeper.BaseZooKeeperDriver(member_id, parsed_url, options)[source]

Bases: tooz.coordination.CoordinationDriver

Initialize the zookeeper driver.

Parameters:timeout – connection timeout to wait when first connecting to the zookeeper server
class tooz.drivers.zookeeper.KazooDriver(member_id, parsed_url, options)[source]

Bases: tooz.drivers.zookeeper.BaseZooKeeperDriver

The driver using the Kazoo client against real ZooKeeper servers.

Table Of Contents

Previous topic

Lock

This Page