patroni.dcs.consul module

class _patroni.dcs.consul.Consul(_config: Dict[ str, Any], mpp: AbstractMPP) View on GitHub

Bases: AbstractDCS +

__init\\__(config: Dict[ str, Any], mpp: AbstractMPP) → None View on GitHub

Prepare DCS paths, MPP object, initial values for state information and processing dependencies. +

Variables

configdict, reference to config section of selected DCS. i.e.: zookeeper for zookeeper, etcd for etcd, etc… +

abc_impl = <_abc._abc_data object>_

+

cluster_from_nodes(_nodes: Dict[ str, Any]) → Cluster View on GitHub

+

property \\__consistency: str_

+

delete_leader(**kwargs: Any_) → Any View on GitHub

Remove leader key from DCS. + This method should remove leader key if current instance is the leader. +

Parameters

leaderLeader object with information about the leader.

Returns

True if successfully committed to DCS. +

do_attempt_to_acquire_leader(_retry: Retry) → bool View on GitHub

+

do_refresh_session(_force: bool = False) → bool View on GitHub
Returns

!True if it had to create new session +

load_cluster(_path: str, loader: Callable[[ str], Cluster | Dict[ int, Cluster]]) → Cluster | Dict[ int, Cluster] View on GitHub

Main abstract method that implements the loading of Cluster instance. + Note

  Internally this method should call the _loader_ method that will build `+Cluster+` object which represents current state and topology of the cluster in DCS. This method supposed to be called only by the `+get_cluster()+` method.
  +
  Parameters:::
  Raise:::
    `+DCSError+` in case of communication problems with DCS. If the current node was running as a primary and exception raised, instance would be demoted.
+
mpp_cluster_loader(_path: str) → Dict[ int, Cluster] View on GitHub

Load and build all PostgreSQL clusters from a single MPP cluster. +

Parameters

path – the path in DCS where to load Cluster(s) from.

Returns

all MPP groups as dict, with group IDs as keys and Cluster objects as values. +

postgresql_cluster_loader(_path: str) → Cluster View on GitHub

Load and build the Cluster object from DCS, which represents a single PostgreSQL cluster. +

Parameters

path – the path in DCS where to load Cluster from.

Returns

Cluster instance. +

static \\__run_and_handle_exceptions(_method: Callable[[…​], Any], *args: Any, **kwargs: Any) → Any View on GitHub

+

_set_service_name() → None View on GitHub

+

update_leader(**kwargs: Any) View on GitHub

Update leader key (or session) ttl. + Note

You have to use CAS (Compare And Swap) operation in order to update leader key, for example for etcd `+prevValue+` parameter must be used.
  If update fails due to DCS not being accessible or because it is not able to process requests (hopefully temporary), the `+DCSError+` exception should be raised.
  +
  Parameters:::
    *leader* – a reference to a current `+leader+` object.
  Returns:::
    `+True+` if `+leader+` key (or session) has been updated successfully.
+
update_service(_data: Dict[ str, Any]) → bool | None View on GitHub

+

write_failsafe(**kwargs: Any_) → Any View on GitHub

Write current cluster topology to DCS that will be used by failsafe mechanism (if enabled). +

Parameters

value – failsafe topology serialized in JSON format.

Returns

True if successfully committed to DCS. +

write_leader_optime(**kwargs: Any_) → Any View on GitHub

Write current WAL LSN into /optime/leader key in DCS. +

Parameters

last_lsn – absolute WAL LSN in bytes.

Returns

True if successfully committed to DCS. +

write_status(**kwargs: Any_) → Any View on GitHub

Write current WAL LSN and confirmed_flush_lsn of permanent slots into the /status key in DCS. +

Parameters

value – status serialized in JSON format.

Returns

True if successfully committed to DCS. +

adjust_ttl() → None View on GitHub

+

attempt_to_acquire_leader(**kwargs: Any) View on GitHub

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(**kwargs: Any) → Any View on GitHub

Removes the initialize key for a cluster. +

Returns

True if successfully committed to DCS. +

create_session() → None View on GitHub

+

delete_cluster(**kwargs: Any) → Any View on GitHub

Delete cluster from DCS. +

Returns

True if successfully committed to DCS. +

delete_sync_state(**kwargs: Any) → Any View on GitHub

Delete the synchronous state from DCS. +

Parameters

version – for conditional deletion of the key/object.

Returns

True if delete successful. +

deregister_service(**kwargs: Any) → Any View on GitHub

+

initialize(**kwargs: Any) → Any View on GitHub

Race for cluster initialization. + This method should atomically create initialize key and return True, otherwise it should return False. +

Parameters
Returns

True if key has been created successfully. +

static _member(_node: Dict[ str, str]) → Member View on GitHub

+

refresh_session() → bool View on GitHub

+

register_service(**kwargs: Any) → Any View on GitHub

+

reload_config(config: Config | Dict[ str, Any]) → None View on GitHub

Load and set relevant values from configuration. + Sets loop_wait, ttl and retry_timeout properties. +

Parameters

config – Loaded configuration information object or dictionary of key value pairs. +

retry(method: Callable[[…​], Any], *args: Any, **kwargs: Any) → Any View on GitHub

+

set_config_value(**kwargs: Any) → Any View on GitHub

Create or update /config key in DCS. +

Parameters
Returns

True if successfully committed to DCS. +

set_failover_value(**kwargs: Any) → Any View on GitHub

Create or update /failover key. +

Parameters
Returns

True if successfully committed to DCS. +

set_history_value(**kwargs: Any) → Any View on GitHub

Set value for history in DCS. +

Parameters

value – new value of history key/object.

Returns

True if successfully committed to DCS. +

set_retry_timeout(retry_timeout: int) → None View on GitHub

Set the new value for retry_timeout. +

set_sync_state_value(**kwargs: Any) → Any View on GitHub

Set synchronous state in DCS. +

Parameters
Returns

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

set_ttl(ttl: int) → bool | None View on GitHub

Set the new ttl value for DCS keys. +

take_leader() → bool View on GitHub

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(**kwargs: Any) → Any View on GitHub

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.
+
property _ttl: int_

Get current ttl value. +

update_service(**kwargs: Any) → Any View on GitHub

+

watch(leader_version: int | None, timeout: float) → bool View on GitHub

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

Parameters
Returns

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

class _patroni.dcs.consul.ConsulClient(*args: Any, _**kwargs: Any) View on GitHub

Bases: Consul +

__init\\__(*args: Any, **kwargs: Any) → None View on GitHub

Consul client with Patroni customisations. + Note

Parameters, _token_, _cert_ and _ca_cert_ are not passed to the parent class `+consul.base.Consul+`.
+
Original class documentation,
+
\\__\\__
_token_ is an optional `+ACL+``+ +``+token+`. If supplied it will be used by default for all requests made with this client session. It’s still possible to override this token by passing a token explicitly for a request.
_consistency_ sets the consistency mode to use by default for all reads that support the consistency option. It’s still possible to override this by passing explicitly for a given request. _consistency_ can be either ‘default’, ‘consistent’ or ‘stale’.
_dc_ is the datacenter that this agent will communicate with. By default, the datacenter of the host is used.
_verify_ is whether to verify the SSL certificate for HTTPS requests
  _cert_ client side certificates for HTTPS requests
  \\__\\__
  +
  Parameters:::
+
connect(*args: Any, **kwargs: Any) → HTTPClient View on GitHub

+

http_connect(*args: Any, **kwargs: Any) → HTTPClient View on GitHublink:#patroni.dcs.consul.ConsulClient. http_connect[]

+

reload_config(config: Dict[ str, Any]) → None View on GitHub
exception _patroni.dcs.consul.ConsulError(_value: Any) View on GitHub

Bases: DCSError

_exception _patroni.dcs.consul.ConsulInternalError View on GitHub

Bases: ConsulException + An internal Consul server error occurred

class _patroni.dcs.consul.HTTPClient(_host: str = '127.0.0.1', port: int = 8500, token: str | None = None, scheme: str = ' http', verify: bool = True, cert: str | None = None, ca_cert: str | None = None) View on GitHub

Bases: object +

__init\\__(host: str = '127.0.0.1', port: int = 8500, token: str | None = None, scheme: str = ' http', verify: bool = True, cert: str | None = None, ca_cert: str | None = None) → None View on GitHub

+

static _response(_response: HTTPResponse) → Response View on GitHub

+

set_read_timeout(timeout: float) → None View on GitHub

+

set_ttl(ttl: int) → bool View on GitHub

+

property _ttl: int_

+

uri(path: str, params: None | Dict[ str, Any] | List[ Tuple[ str, Any]] | Tuple[ Tuple[ str, Any], …​] = None) → str View on GitHub
_exception _patroni.dcs.consul.InvalidSession View on GitHub

Bases: ConsulException + invalid session

_exception _patroni.dcs.consul.InvalidSessionTTL View on GitHub

Bases: ConsulException + Session TTL is too small or too big

class _patroni.dcs.consul.Response(_code, headers, body, content) View on GitHub

Bases: NamedTuple +

_asdict() View on GitHub

Return a new dict which maps field names to their values. +

field_defaults = \{}_

+

fields = ('code', 'headers', 'body', 'content')_

+

classmethod \\__make(_iterable) View on GitHub

Make a new Response object from a sequence or iterable +

replace(**kwds_) View on GitHub

Return a new Response object replacing specified fields with new values +

body_: str_

Alias for field number 2 +

code_: int_

Alias for field number 0 +

content_: bytes_

Alias for field number 3 +

headers_: Mapping[ str, str] | Mapping[ bytes, bytes] | None_

Alias for field number 1

patroni.dcs.consul.catch_consul_errors(func: Callable[[…​], Any]) → Callable[[…​], Any] View on GitHub
patroni.dcs.consul.force_if_last_failed(func: Callable[[…​], Any]) → Callable[[…​], Any] View on GitHub
patroni.dcs.consul.service_name_from_scope_name(scope_name: str) → str View on GitHub

Translate scope name to service name which can be used in dns. + 230 = 253 - len(‘replica.’) - len(‘.service.consul’)


© Copyright 2015 Compose, Zalando SE. Revision 9d231aee.

Built with Sphinx using a theme provided by Read the Docs.

Read the Docs v: latest

+ Builds