patroni.dcs.etcd3 module¶
- exception patroni.dcs.etcd3.AuthFailed(code: int | None = None, error: str | None = None, status: int | None = None)¶
Bases:
InvalidArgument- error = 'etcdserver: authentication failed, invalid user ID or password'¶
- exception patroni.dcs.etcd3.AuthNotEnabled(code: int | None = None, error: str | None = None, status: int | None = None)¶
Bases:
FailedPrecondition- error = 'etcdserver: authentication is not enabled'¶
- exception patroni.dcs.etcd3.AuthOldRevision(code: int | None = None, error: str | None = None, status: int | None = None)¶
Bases:
InvalidArgument- error = 'etcdserver: revision of auth store is old'¶
- exception patroni.dcs.etcd3.DeadlineExceeded(code: int | None = None, error: str | None = None, status: int | None = None)¶
Bases:
Etcd3ClientError- code = 4¶
- error = 'context deadline exceeded'¶
- class patroni.dcs.etcd3.Etcd3(config: Dict[str, Any])¶
Bases:
AbstractEtcd- __init__(config: Dict[str, Any]) None¶
Prepare DCS paths, Citus group ID, initial values for state information and processing dependencies.
- Variables:
config –
dict, reference to config section of selected DCS. i.e.:zookeeperfor zookeeper,etcdfor etcd, etc…
- _abc_impl = <_abc._abc_data object>¶
- _citus_cluster_loader(path: str) Dict[int, Cluster]¶
Load and build all Patroni clusters from a single Citus cluster.
- Parameters:
path – the path in DCS where to load Cluster(s) from.
- Returns:
all Citus groups as
dict, with group IDs as keys andClusterobjects as values or aClusterobject representing the coordinator with filled Cluster.workers attribute.
- property _client: PatroniEtcd3Client¶
return correct type of etcd client
- _cluster_loader(path: str) Cluster¶
Load and build the
Clusterobject from DCS, which represents a single Patroni or Citus cluster.- Parameters:
path – the path in DCS where to load Cluster(s) from.
- Returns:
Clusterinstance.
- _delete_leader(*args: Any, **kwargs: Any) Any¶
Remove leader key from DCS.
This method should remove leader key if current instance is the leader.
- Parameters:
leader –
Leaderobject with information about the leader.- Returns:
Trueif successfully committed to DCS.
- _load_cluster(path: str, loader: Callable[[str], Cluster | Dict[int, Cluster]]) Cluster | Dict[int, Cluster]¶
Main abstract method that implements the loading of
Clusterinstance.Note
Internally this method should call the loader method that will build
Clusterobject which represents current state and topology of the cluster in DCS. This method supposed to be called only by theget_cluster()method.- Parameters:
path – the path in DCS where to load Cluster(s) from.
loader – one of
_cluster_loader()or_citus_cluster_loader().
- Raise:
DCSErrorin case of communication problems with DCS. If the current node was running as a primary and exception raised, instance would be demoted.
- _update_leader(**kwargs: Any)¶
Update
leaderkey (or session) ttl.Note
You have to use CAS (Compare And Swap) operation in order to update leader key, for example for etcd
prevValueparameter must be used.If update fails due to DCS not being accessible or because it is not able to process requests (hopefully temporary), the
DCSErrorexception should be raised.- Parameters:
leader – a reference to a current
leaderobject.- Returns:
Trueifleaderkey (or session) has been updated successfully.
- _write_failsafe(*args: Any, **kwargs: Any) Any¶
Write current cluster topology to DCS that will be used by failsafe mechanism (if enabled).
- Parameters:
value – failsafe topology serialized in JSON format.
- Returns:
Trueif successfully committed to DCS.
- _write_leader_optime(*args: Any, **kwargs: Any) Any¶
Write current WAL LSN into
/optime/leaderkey in DCS.- Parameters:
last_lsn – absolute WAL LSN in bytes.
- Returns:
Trueif successfully committed to DCS.
- _write_status(*args: Any, **kwargs: Any) Any¶
Write current WAL LSN and
confirmed_flush_lsnof permanent slots into the/statuskey in DCS.- Parameters:
value – status serialized in JSON format.
- Returns:
Trueif successfully committed to DCS.
- attempt_to_acquire_leader(**kwargs: Any)¶
Attempt to acquire leader lock.
Note
This method should create
/leaderkey with the value_name.The key must be created atomically. In case the key already exists it should not be overwritten and
Falsemust be returned.If key creation fails due to DCS not being accessible or because it is not able to process requests (hopefully temporary), the
DCSErrorexception should be raised.- Returns:
Trueif key has been created successfully.
- cancel_initialization(*args: Any, **kwargs: Any) Any¶
Removes the
initializekey for a cluster.- Returns:
Trueif successfully committed to DCS.
- delete_cluster(*args: Any, **kwargs: Any) Any¶
Delete cluster from DCS.
- Returns:
Trueif 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:
Trueif delete successful.
- initialize(*args: Any, **kwargs: Any) Any¶
Race for cluster initialization.
This method should atomically create
initializekey and returnTrue, otherwise it should returnFalse.- Parameters:
create_new –
Falseif 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:
Trueif key has been created successfully.
- set_config_value(*args: Any, **kwargs: Any) Any¶
Create or update
/configkey in DCS.- Parameters:
value – new value to set in the
configkey.version – for conditional update of the key/object.
- Returns:
Trueif successfully committed to DCS.
- set_failover_value(*args: Any, **kwargs: Any) Any¶
Create or update
/failoverkey.- Parameters:
value – value to set.
version – for conditional update of the key/object.
- Returns:
Trueif successfully committed to DCS.
- set_history_value(*args: Any, **kwargs: Any) Any¶
Set value for
historyin DCS.- Parameters:
value – new value of
historykey/object.- Returns:
Trueif successfully committed to DCS.
- set_sync_state_value(*args: Any, **kwargs: Any) Any¶
Set synchronous state in DCS.
- Parameters:
value – the new value of
/synckey.version – for conditional update of the key/object.
- Returns:
version of the new object or
Falsein case of error.
- take_leader(*args: Any, **kwargs: Any) Any¶
Establish a new leader in DCS.
Note
This method should create leader key with value of
_nameandttlofttl.Since it could be called only on initial cluster bootstrap it could create this key regardless, overwriting the key if necessary.
- Returns:
Trueif 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/+_nameand the value of data in a given DCS.- Parameters:
data – information about an instance (including connection strings).
- Returns:
Trueif successfully committed to DCS.
- watch(leader_version: str | None, 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
Truethis will reschedule the next run of the HA cycle.
- class patroni.dcs.etcd3.Etcd3Client(config: Dict[str, Any], dns_resolver: DnsCachingResolver, cache_ttl: int = 300)¶
Bases:
AbstractEtcdClientWithFailover- ERROR_CLS¶
alias of
Etcd3Error
- _abc_impl = <_abc._abc_data object>¶
- _prepare_request(kwargs: Dict[str, Any], params: Dict[str, Any] | None = None, method: str | None = None) Callable[[...], HTTPResponse]¶
returns: request_executor
- handle_auth_errors(func: Callable[[...], Any], *args: Any, retry: Retry | None = None, **kwargs: Any) Any¶
- exception patroni.dcs.etcd3.Etcd3ClientError(code: int | None = None, error: str | None = None, status: int | None = None)¶
Bases:
Etcd3Exception- classmethod get_subclasses() Iterator[Type[Etcd3ClientError]]¶
- exception patroni.dcs.etcd3.Etcd3Exception(message=None, payload=None)¶
Bases:
EtcdException
- exception patroni.dcs.etcd3.FailedPrecondition(code: int | None = None, error: str | None = None, status: int | None = None)¶
Bases:
Etcd3ClientError- code = 9¶
- class patroni.dcs.etcd3.GRPCCode(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)¶
Bases:
IntEnum- 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¶
- Unimplemented = 12¶
- Unknown = 2¶
- exception patroni.dcs.etcd3.InvalidArgument(code: int | None = None, error: str | None = None, status: int | None = None)¶
Bases:
Etcd3ClientError- code = 3¶
- exception patroni.dcs.etcd3.InvalidAuthToken(code: int | None = None, error: str | None = None, status: int | None = None)¶
Bases:
Etcd3ClientError- code = 16¶
- error = 'etcdserver: invalid auth token'¶
- class patroni.dcs.etcd3.KVCache(dcs: Etcd3, client: PatroniEtcd3Client)¶
Bases:
Thread- __init__(dcs: Etcd3, client: PatroniEtcd3Client) None¶
This constructor should always be called with keyword arguments. Arguments are:
group should be None; reserved for future extension when a ThreadGroup class is implemented.
target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.
name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.
args is a list or tuple of arguments for the target invocation. Defaults to ().
kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.
If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.
- 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.
- exception patroni.dcs.etcd3.LeaseNotFound(code: int | None = None, error: str | None = None, status: int | None = None)¶
Bases:
NotFound- error = 'etcdserver: requested lease not found'¶
- exception patroni.dcs.etcd3.NotFound(code: int | None = None, error: str | None = None, status: int | None = None)¶
Bases:
Etcd3ClientError- code = 5¶
- class patroni.dcs.etcd3.PatroniEtcd3Client(*args: Any, **kwargs: Any)¶
Bases:
Etcd3Client- _abc_impl = <_abc._abc_data object>¶
- exception patroni.dcs.etcd3.PermissionDenied(code: int | None = None, error: str | None = None, status: int | None = None)¶
Bases:
Etcd3ClientError- code = 7¶
- error = 'etcdserver: permission denied'¶
- class patroni.dcs.etcd3.ReAuthenticateMode(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)¶
Bases:
IntEnum- NOT_REQUIRED = 0¶
- REQUIRED = 1¶
- WITHOUT_WATCHER_RESTART = 2¶
Bases:
Etcd3ClientError
- exception patroni.dcs.etcd3.Unknown(code: int | None = None, error: str | None = None, status: int | None = None)¶
Bases:
Etcd3ClientError- code = 2¶
- exception patroni.dcs.etcd3.UnsupportedEtcdVersion(value: Any)¶
Bases:
PatroniException
- exception patroni.dcs.etcd3.UserEmpty(code: int | None = None, error: str | None = None, status: int | None = None)¶
Bases:
InvalidArgument- error = 'etcdserver: user name is empty'¶
- patroni.dcs.etcd3._raise_for_data(data: bytes | str | Dict[str, Dict[str, Any] | Any], status_code: int | None = None) Etcd3ClientError¶