patroni.dcs.etcd3 module

exception patroni.dcs.etcd3.AuthFailed(code: Optional[int] = None, error: Optional[str] = None, status: Optional[int] = None)

Bases: patroni.dcs.etcd3.InvalidArgument

error = 'etcdserver: authentication failed, invalid user ID or password'
exception patroni.dcs.etcd3.AuthNotEnabled(code: Optional[int] = None, error: Optional[str] = None, status: Optional[int] = None)

Bases: patroni.dcs.etcd3.FailedPrecondition

error = 'etcdserver: authentication is not enabled'
exception patroni.dcs.etcd3.DeadlineExceeded(code: Optional[int] = None, error: Optional[str] = None, status: Optional[int] = None)

Bases: patroni.dcs.etcd3.Etcd3ClientError

code = 4
error = 'context deadline exceeded'
class patroni.dcs.etcd3.Etcd3(config: Dict[str, Any])

Bases: patroni.dcs.etcd.AbstractEtcd

attempt_to_acquire_leader(**kwargs: Any)

Attempt to acquire leader lock.

Note

This method should create /leader key with the value _name.

The key must be created atomically. In case the key already exists it should not be overwritten and False must be returned.

If key creation fails due to DCS not being accessible or because it is not able to process requests (hopefully temporary), the DCSError exception should be raised.

Returns

True if key has been created successfully.

cancel_initialization(*args: Any, **kwargs: Any) Any

Removes the initialize key for a cluster.

Returns

True if successfully committed to DCS.

property cluster_prefix: str
create_lease() None
delete_cluster(*args: Any, **kwargs: Any) Any

Delete cluster from DCS.

Returns

True if successfully committed to DCS.

delete_sync_state(*args: Any, **kwargs: Any) Any

Delete the synchronous state from DCS.

Parameters

version – for conditional deletion of the key/object.

Returns

True if delete successful.

initialize(*args: Any, **kwargs: Any) Any

Race for cluster initialization.

This method should atomically create initialize key and return True, otherwise it should return False.

Parameters
  • create_newFalse if the key should already exist (in the case we are setting the system_id).

  • sysid – PostgreSQL cluster system identifier, if specified, is written to the key.

Returns

True if key has been created successfully.

static member(node: Dict[str, str]) patroni.dcs.Member
refresh_lease() bool
set_config_value(*args: Any, **kwargs: Any) Any

Create or update /config key in DCS.

Parameters
  • value – new value to set in the config key.

  • version – for conditional update of the key/object.

Returns

True if successfully committed to DCS.

set_failover_value(*args: Any, **kwargs: Any) Any

Create or update /failover key.

Parameters
  • value – value to set.

  • version – for conditional update of the key/object.

Returns

True if successfully committed to DCS.

set_history_value(*args: Any, **kwargs: Any) Any

Set value for history in DCS.

Parameters

value – new value of history key/object.

Returns

True if successfully committed to DCS.

set_socket_options(sock: socket.socket, socket_options: Optional[Collection[Tuple[int, int, int]]]) None
set_sync_state_value(*args: Any, **kwargs: Any) Any

Set synchronous state in DCS.

Parameters
  • value – the new value of /sync key.

  • version – for conditional update of the key/object.

Returns

version of the new object or False in case of error.

set_ttl(ttl: int) Optional[bool]

Set the new ttl value for DCS keys.

take_leader(*args: Any, **kwargs: Any) Any

Establish a new leader in DCS.

Note

This method should create leader key with value of _name and ttl of ttl.

Since it could be called only on initial cluster bootstrap it could create this key regardless, overwriting the key if necessary.

Returns

True if successfully committed to DCS.

touch_member(*args: Any, **kwargs: Any) Any

Update member key in DCS.

Note

This method should create or update key with the name with /members/ + _name and the value of data in a given DCS.

Parameters

data – information about an instance (including connection strings).

Returns

True if successfully committed to DCS.

watch(leader_version: Optional[str], timeout: float) bool

Sleep if the current node is a leader, otherwise, watch for changes of leader key with a given timeout.

Parameters
  • leader_version – version of a leader key.

  • timeout – timeout in seconds.

Returns

if True this will reschedule the next run of the HA cycle.

class patroni.dcs.etcd3.Etcd3Client(config: Dict[str, Any], dns_resolver: patroni.dcs.etcd.DnsCachingResolver, cache_ttl: int = 300)

Bases: patroni.dcs.etcd.AbstractEtcdClientWithFailover

ERROR_CLS

alias of patroni.dcs.etcd3.Etcd3Error

authenticate() bool
call_rpc(method: str, fields: Dict[str, Any], retry: Optional[patroni.utils.Retry] = None) Dict[str, Any]
deleteprefix(key: str, retry: Optional[patroni.utils.Retry] = None) Dict[str, Any]
deleterange(*args: Any, **kwargs: Any) Any
handle_auth_errors(func: Callable[[...], Any], *args: Any, **kwargs: Any) Any
lease_grant(*args: Any, **kwargs: Any) Any
lease_keepalive(ID: str, retry: Optional[patroni.utils.Retry] = None) Optional[str]
prefix(key: str, serializable: bool = True, retry: Optional[patroni.utils.Retry] = None) Dict[str, Any]
put(*args: Any, **kwargs: Any) Any
range(*args: Any, **kwargs: Any) Any
txn(compare: Dict[str, Any], success: Dict[str, Any], failure: Optional[Dict[str, Any]] = None, retry: Optional[patroni.utils.Retry] = None) Dict[str, Any]
watchprefix(key: str, start_revision: Optional[str] = None, filters: Optional[List[Dict[str, Any]]] = None, read_timeout: Optional[float] = None) urllib3.response.HTTPResponse
watchrange(key: str, range_end: Optional[Union[bytes, str]] = None, start_revision: Optional[str] = None, filters: Optional[List[Dict[str, Any]]] = None, read_timeout: Optional[float] = None) urllib3.response.HTTPResponse

returns: response object

exception patroni.dcs.etcd3.Etcd3ClientError(code: Optional[int] = None, error: Optional[str] = None, status: Optional[int] = None)

Bases: patroni.dcs.etcd3.Etcd3Exception

as_dict() Dict[str, Any]
classmethod get_subclasses() Iterator[Type[patroni.dcs.etcd3.Etcd3ClientError]]
exception patroni.dcs.etcd3.Etcd3Error(value: Any)

Bases: patroni.exceptions.DCSError

exception patroni.dcs.etcd3.Etcd3Exception(message=None, payload=None)

Bases: etcd.EtcdException

exception patroni.dcs.etcd3.FailedPrecondition(code: Optional[int] = None, error: Optional[str] = None, status: Optional[int] = None)

Bases: patroni.dcs.etcd3.Etcd3ClientError

code = 9
class patroni.dcs.etcd3.GRPCCode(value)

Bases: enum.IntEnum

An enumeration.

Aborted = 10
AlreadyExists = 6
Canceled = 1
DataLoss = 15
DeadlineExceeded = 4
FailedPrecondition = 9
Internal = 13
InvalidArgument = 3
NotFound = 5
OK = 0
OutOfRange = 11
PermissionDenied = 7
ResourceExhausted = 8
Unauthenticated = 16
Unavailable = 14
Unimplemented = 12
Unknown = 2
exception patroni.dcs.etcd3.InvalidArgument(code: Optional[int] = None, error: Optional[str] = None, status: Optional[int] = None)

Bases: patroni.dcs.etcd3.Etcd3ClientError

code = 3
exception patroni.dcs.etcd3.InvalidAuthToken(code: Optional[int] = None, error: Optional[str] = None, status: Optional[int] = None)

Bases: patroni.dcs.etcd3.Etcd3ClientError

code = 16
error = 'etcdserver: invalid auth token'
class patroni.dcs.etcd3.KVCache(dcs: patroni.dcs.etcd3.Etcd3, client: patroni.dcs.etcd3.PatroniEtcd3Client)

Bases: threading.Thread

copy() List[Dict[str, Any]]
delete(name: str, mod_revision: str) Tuple[bool, Optional[Dict[str, Any]]]
get(name: str) Optional[Dict[str, Any]]
is_ready() bool

Must be called only when holding the lock on condition

kill_stream() None
run() None

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

set(value: Dict[str, Any], overwrite: bool = False) Tuple[bool, Optional[Dict[str, Any]]]
exception patroni.dcs.etcd3.LeaseNotFound(code: Optional[int] = None, error: Optional[str] = None, status: Optional[int] = None)

Bases: patroni.dcs.etcd3.NotFound

error = 'etcdserver: requested lease not found'
exception patroni.dcs.etcd3.NotFound(code: Optional[int] = None, error: Optional[str] = None, status: Optional[int] = None)

Bases: patroni.dcs.etcd3.Etcd3ClientError

code = 5
class patroni.dcs.etcd3.PatroniEtcd3Client(*args: Any, **kwargs: Any)

Bases: patroni.dcs.etcd3.Etcd3Client

authenticate() bool
call_rpc(method: str, fields: Dict[str, Any], retry: Optional[patroni.utils.Retry] = None) Dict[str, Any]
configure(etcd3: patroni.dcs.etcd3.Etcd3) None
get_cluster(path: str) List[Dict[str, Any]]
set_base_uri(value: str) None
start_watcher() None
txn(compare: Dict[str, Any], success: Dict[str, Any], failure: Optional[Dict[str, Any]] = None, retry: Optional[patroni.utils.Retry] = None) Dict[str, Any]
exception patroni.dcs.etcd3.PermissionDenied(code: Optional[int] = None, error: Optional[str] = None, status: Optional[int] = None)

Bases: patroni.dcs.etcd3.Etcd3ClientError

code = 7
error = 'etcdserver: permission denied'
exception patroni.dcs.etcd3.Unavailable(code: Optional[int] = None, error: Optional[str] = None, status: Optional[int] = None)

Bases: patroni.dcs.etcd3.Etcd3ClientError

code = 14
exception patroni.dcs.etcd3.Unknown(code: Optional[int] = None, error: Optional[str] = None, status: Optional[int] = None)

Bases: patroni.dcs.etcd3.Etcd3ClientError

code = 2
exception patroni.dcs.etcd3.UnsupportedEtcdVersion(value: Any)

Bases: patroni.exceptions.PatroniException

exception patroni.dcs.etcd3.UserEmpty(code: Optional[int] = None, error: Optional[str] = None, status: Optional[int] = None)

Bases: patroni.dcs.etcd3.InvalidArgument

error = 'etcdserver: user name is empty'
patroni.dcs.etcd3.base64_decode(v: str) str
patroni.dcs.etcd3.base64_encode(v: Union[str, bytes]) str
patroni.dcs.etcd3.build_range_request(key: str, range_end: Optional[Union[bytes, str]] = None) Dict[str, Any]
patroni.dcs.etcd3.prefix_range_end(v: str) bytes
patroni.dcs.etcd3.to_bytes(v: Union[str, bytes]) bytes