kazoo.protocol.states

Kazoo State and Event objects

Public API

class kazoo.protocol.states.EventType[source]

Zookeeper Event

Represents a Zookeeper event. Events trigger watch functions which will receive a EventType attribute as their event argument.

CREATED

A node has been created.

DELETED

A node has been deleted.

CHANGED

The data for a node has changed.

CHILD

The children under a node have changed (a child was added or removed). This event does not indicate the data for a child node has changed, which must have its own watch established.

NONE

The connection state has been altered.

class kazoo.protocol.states.KazooState[source]

High level connection state values

States inspired by Netflix Curator.

SUSPENDED

The connection has been lost but may be recovered. We should operate in a “safe mode” until then. When the connection is resumed, it may be discovered that the session expired. A client should not assume that locks are valid during this time.

CONNECTED

The connection is alive and well.

LOST

The connection has been confirmed dead. Any ephemeral nodes will need to be recreated upon re-establishing a connection. If locks were acquired or recipes using ephemeral nodes are in use, they can be considered lost as well.

class kazoo.protocol.states.KeeperState[source]

Zookeeper State

Represents the Zookeeper state. Watch functions will receive a KeeperState attribute as their state argument.

AUTH_FAILED

Authentication has failed, this is an unrecoverable error.

CONNECTED

Zookeeper is connected.

CONNECTED_RO

Zookeeper is connected in read-only state.

CONNECTING

Zookeeper is currently attempting to establish a connection.

EXPIRED_SESSION

The prior session was invalid, all prior ephemeral nodes are gone.

class kazoo.protocol.states.WatchedEvent(type, state, path)[source]

A change on ZooKeeper that a Watcher is able to respond to.

The WatchedEvent includes exactly what happened, the current state of ZooKeeper, and the path of the node that was involved in the event. An instance of WatchedEvent will be passed to registered watch functions.

type

A EventType attribute indicating the event type.

state

A KeeperState attribute indicating the Zookeeper state.

path

The path of the node for the watch event.

class kazoo.protocol.states.ZnodeStat(czxid, mzxid, ctime, mtime, version, cversion, aversion, ephemeralOwner, dataLength, numChildren, pzxid)[source]

A ZnodeStat structure with convenience properties

When getting the value of a znode from Zookeeper, the properties for the znode known as a “Stat structure” will be retrieved. The ZnodeStat object provides access to the standard Stat properties and additional properties that are more readable and use Python time semantics (seconds since epoch instead of ms).

Note

The original Zookeeper Stat name is in parens next to the name when it differs from the convenience attribute. These are not functions, just attributes.

creation_transaction_id(czxid)

The transaction id of the change that caused this znode to be created.

last_modified_transaction_id(mzxid)

The transaction id of the change that last modified this znode.

created(ctime)

The time in seconds from epoch when this znode was created. (ctime is in milliseconds)

last_modified(mtime)

The time in seconds from epoch when this znode was last modified. (mtime is in milliseconds)

version

The number of changes to the data of this znode.

acl_version(aversion)

The number of changes to the ACL of this znode.

owner_session_id(ephemeralOwner)

The session id of the owner of this znode if the znode is an ephemeral node. If it is not an ephemeral node, it will be None. (ephemeralOwner will be 0 if it is not ephemeral)

data_length(dataLength)

The length of the data field of this znode.

children_count(numChildren)

The number of children of this znode.

Private API

class kazoo.protocol.states.Callback(type, func, args)[source]

A callback that is handed to a handler for dispatch

Parameters:
  • type – Type of the callback, currently is only ‘watch’

  • func – Callback function

  • args – Argument list for the callback function