kazoo.recipe.barrier

Zookeeper Barriers

Maintainer:None
Status:Unknown

Public API

class kazoo.recipe.barrier.Barrier(client, path)[source]

Kazoo Barrier

Implements a barrier to block processing of a set of nodes until a condition is met at which point the nodes will be allowed to proceed. The barrier is in place if its node exists.

Warning

The wait() function does not handle connection loss and may raise ConnectionLossException if the connection is lost while waiting.

__init__(client, path)[source]

Create a Kazoo Barrier

Parameters:
  • client – A KazooClient instance.
  • path – The barrier path to use.
create()[source]

Establish the barrier if it doesn’t exist already

remove()[source]

Remove the barrier

Returns:Whether the barrier actually needed to be removed.
Return type:bool
wait(timeout=None)[source]

Wait on the barrier to be cleared

Returns:True if the barrier has been cleared, otherwise False.
Return type:bool
class kazoo.recipe.barrier.DoubleBarrier(client, path, num_clients, identifier=None)[source]

Kazoo Double Barrier

Double barriers are used to synchronize the beginning and end of a distributed task. The barrier blocks when entering it until all the members have joined, and blocks when leaving until all the members have left.

Note

You should register a listener for session loss as the process will no longer be part of the barrier once the session is gone. Connection losses will be retried with the default retry policy.

__init__(client, path, num_clients, identifier=None)[source]

Create a Double Barrier

Parameters:
  • client – A KazooClient instance.
  • path – The barrier path to use.
  • num_clients (int) – How many clients must enter the barrier to proceed.
  • identifier – An identifier to use for this member of the barrier when participating. Defaults to the hostname + process id.
enter()[source]

Enter the barrier, blocks until all nodes have entered

leave()[source]

Leave the barrier, blocks until all nodes have left