- class patroni.dcs.etcd. AbstractEtcd ( config : Dict [ str , Any ] , mpp : AbstractMPP , client_cls : Type [ AbstractEtcdClientWithFailover ] , retry_errors_cls : Type [ Exception ] | Tuple [ Type [ Exception ] , ... ] ) View on GitHub
- 
         Bases: AbstractDCS- __init__ ( config : Dict [ str , Any ] , mpp : AbstractMPP , client_cls : Type [ AbstractEtcdClientWithFailover ] , retry_errors_cls : Type [ Exception ] | Tuple [ Type [ Exception ] , ... ] ) None View on GitHub
- 
           Prepare DCS paths, MPP object, initial values for state information and processing dependencies. - Parameters :
- 
             - 
               config – dict, reference to config section of selected DCS. i.e.:zookeeperfor zookeeper,etcdfor etcd, etc…
- 
               mpp – an object implementing AbstractMPPinterface.
 
- 
               
 
 - _abc_impl = <_abc._abc_data object>
 - abstract property _client : AbstractEtcdClientWithFailover View on GitHub
- 
           return correct type of etcd client 
 - _handle_exception ( e : Exception , name : str = '' , do_sleep : bool = False , raise_ex : Exception | None = None ) None View on GitHub
 - _run_and_handle_exceptions ( method : Callable [ [ ... ] , Any ] , * args : Any , ** kwargs : Any ) Any View on GitHub
 - get_etcd_client ( config : Dict [ str , Any ] , client_cls : Type [ AbstractEtcdClientWithFailover ] ) AbstractEtcdClientWithFailover View on GitHub
 - handle_etcd_exceptions ( func : Callable [ [ ... ] , Any ] , * args : Any , ** 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,ttlandretry_timeoutproperties.- Parameters :
- 
             config – Loaded configuration information object or dictionary of key value pairs. 
 
 - set_retry_timeout ( retry_timeout : int ) None View on GitHub
- 
           Set the new value for retry_timeout . 
 - set_socket_options ( sock : socket , socket_options : Collection [ Tuple [ int , int , int ] ] | None ) None View on GitHub
 - set_ttl ( ttl : int ) bool | None View on GitHub
- 
           Set the new ttl value for DCS keys. 
 - property ttl : int View on GitHub
- 
           Get current ttlvalue.
 
- class patroni.dcs.etcd. AbstractEtcdClientWithFailover ( config : Dict [ str , Any ] , dns_resolver : DnsCachingResolver , cache_ttl : int = 300 ) View on GitHub
- 
         Bases: ABC,Client,StaleEtcdNodeGuard- __init__ ( config : Dict [ str , Any ] , dns_resolver : DnsCachingResolver , cache_ttl : int = 300 ) None View on GitHub
 - _abc_impl = <_abc._abc_data object>
 - _calculate_timeouts ( etcd_nodes : int , timeout : float | None = None ) Tuple [ int , float , int ] View on GitHub
- 
           Calculate a request timeout and number of retries per single etcd node. In case if the timeout per node is too small (less than one second) we will reduce the number of nodes. For the cluster with only one node we will try to do 2 retries. For clusters with 2 nodes we will try to do 1 retry for every node. No retries for clusters with 3 or more nodes. We better rely on switching to a different node. 
 - _do_http_request ( retry : Retry | None , machines_cache : List [ str ] , request_executor : Callable [ [ ... ] , HTTPResponse ] , method : str , path : str , fields : Dict [ str , Any ] | None = None , ** kwargs : Any ) Any View on GitHub
 - _get_headers ( ) Dict [ str , str ] View on GitHub
 - _get_machines_cache_from_config ( ) List [ str ] View on GitHub
 - _get_machines_cache_from_dns ( host : str , port : int ) List [ str ] View on GitHub
- 
           One host might be resolved into multiple ip addresses. We will make list out of it 
 - _get_machines_cache_from_srv ( srv : str , srv_suffix : str | None = None ) List [ str ] View on GitHub
- 
           Fetch list of etcd-cluster member by resolving _etcd-server._tcp. SRV record. This record should contain list of host and peer ports which could be used to run ‘GET http:/ /{host}:{port}/members’ request (peer protocol) 
 - _get_machines_list ( machines_cache : List [ str ] ) List [ str ] View on GitHub
- 
           Gets list of members from Etcd cluster using API - Parameters :
- 
             machines_cache – initial list of Etcd members 
- Returns :
- 
             list of clientURLs retrieved from Etcd cluster 
- Raises :
- 
             EtcdConnectionFailed – if failed 
 
 - abstract _get_members ( base_uri : str , ** kwargs : Any ) List [ str ] View on GitHub
- 
           returns: list of clientURLs 
 - _load_machines_cache ( ) bool View on GitHub
- 
           This method should fill up _machines_cachefrom scratch. It could happen only in two cases: 1. During class initialization 2. When all etcd members failed
 - _prepare_common_parameters ( etcd_nodes : int , timeout : float | None = None ) Dict [ str , Any ] View on GitHub
 - abstract _prepare_get_members ( etcd_nodes : int ) Dict [ str , Any ] View on GitHub
- 
           returns: request parameters 
 - abstract _prepare_request ( kwargs : Dict [ str , Any ] , params : Dict [ str , Any ] | None = None , method : str | None = None ) Callable [ [ ... ] , HTTPResponse ] View on GitHub
- 
           returns: request_executor 
 - _refresh_machines_cache ( machines_cache : List [ str ] | None = None ) bool View on GitHub
- 
           Get etcd cluster topology using Etcd API and put it to self._machines_cache - Parameters :
- 
             machines_cache – the list of nodes we want to run through executing API request in addition to values stored in the self._machines_cache 
- Returns :
- 
             Trueif self._machines_cache was updated with new values
- Raises :
- 
             EtcdException – if failed to get topology and machines_cachewas specified.
 The self._machines_cache will not be updated if nodes from the list are not accessible or if they are not returning correct results. 
 - static _update_dns_cache ( func : Callable [ [ str , int ] , None ] , machines : List [ str ] ) None View on GitHub
 - api_execute ( path : str , method : str , params : Dict [ str , Any ] | None = None , timeout : float | None = None ) Any View on GitHub
- 
           Executes the query. 
 - property machines : List [ str ] View on GitHub
- 
           Original machinesmethod(property) ofetcd.Clientclass raise exception when it failed to get list of etcd cluster members. This method is being called only when request failed on one of the etcd members duringapi_executecall. For us it’s more important to execute original request rather then get new topology of etcd cluster. So we will catch this exception and return empty list of machines. Later, during nextapi_executecall we will forcefully update machines_cache.Also this method implements the same timeout-retry logic as api_execute, because the original method was retrying 2 times with theread_timeouton each node.After the next refactoring the whole logic was moved to the _get_machines_list() method. 
 - property machines_cache : List [ str ] View on GitHub
 - reload_config ( config : Dict [ str , Any ] ) None View on GitHub
 - set_base_uri ( value : str ) None View on GitHub
 - set_machines_cache_ttl ( cache_ttl : int ) None View on GitHub
 - set_read_timeout ( timeout : float ) None View on GitHub
 
- class patroni.dcs.etcd. DnsCachingResolver ( cache_time : float = 600.0 , cache_fail_time : float = 30.0 ) View on GitHub
- 
         Bases: Thread- __init__ ( cache_time : float = 600.0 , cache_fail_time : float = 30.0 ) None View on GitHub
- 
           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 the argument tuple 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. 
 - static _do_resolve ( host : str , port : int ) List [ Tuple [ AddressFamily , SocketKind , int , str , Tuple [ str , int ] | Tuple [ str , int , int , int ] | Tuple [ int , bytes ] ] ] View on GitHub
 - remove ( host : str , port : int ) None View on GitHub
 - resolve ( host : str , port : int ) List [ Tuple [ AddressFamily , SocketKind , int , str , Tuple [ str , int ] | Tuple [ str , int , int , int ] | Tuple [ int , bytes ] ] ] View on GitHub
 - resolve_async ( host : str , port : int , attempt : int = 0 ) None View on GitHub
 - run ( ) None View on GitHub
- 
           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. 
 
- class patroni.dcs.etcd. Etcd ( config : Dict [ str , Any ] , mpp : AbstractMPP ) View on GitHub
- 
         Bases: AbstractEtcd- __init__ ( config : Dict [ str , Any ] , mpp : AbstractMPP ) None View on GitHub
- 
           Prepare DCS paths, MPP object, initial values for state information and processing dependencies. - Parameters :
- 
             - 
               config – dict, reference to config section of selected DCS. i.e.:zookeeperfor zookeeper,etcdfor etcd, etc…
- 
               mpp – an object implementing AbstractMPPinterface.
 
- 
               
 
 - _abc_impl = <_abc._abc_data object>
 - property _client : EtcdClient View on GitHub
- 
           return correct type of etcd client 
 - _cluster_from_nodes ( etcd_index : int , nodes : Dict [ str , EtcdResult ] ) Cluster View on GitHub
 - _delete_leader ( * args : Any , ** kwargs : Any ) Any View on GitHub
- 
           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.
 
 - _do_attempt_to_acquire_leader ( ) bool View on GitHub
 - _do_update_leader ( ) bool View on GitHub
 - _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 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 _postgresql_cluster_loader()or_mpp_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.
 
 - _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 andClusterobjects as values.
 
 - _postgresql_cluster_loader ( path : str ) Cluster View on GitHub
- 
           Load and build the Clusterobject from DCS, which represents a single PostgreSQL cluster.- Parameters :
- 
             path – the path in DCS where to load Clusterfrom.
- Returns :
- 
             Clusterinstance.
 
 - _update_leader ( ** kwargs : Any ) View on GitHub
- 
           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 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 :
- 
             Trueif successfully committed to DCS.
 
 - _write_leader_optime ( * args : Any , ** kwargs : Any ) Any View on GitHub
- 
           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 View on GitHub
- 
           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 ) View on GitHub
- 
           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 View on GitHub
- 
           Removes the initializekey for a cluster.- Returns :
- 
             Trueif successfully committed to DCS.
 
 - delete_cluster ( * args : Any , ** kwargs : Any ) Any View on GitHub
- 
           Delete cluster from DCS. - Returns :
- 
             Trueif successfully committed to DCS.
 
 - delete_sync_state ( * args : Any , ** kwargs : Any ) Any View on GitHub
- 
           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 View on GitHub
- 
           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.
 
 - static member ( node : EtcdResult ) Member View on GitHub
 - set_config_value ( * args : Any , ** kwargs : Any ) Any View on GitHub
- 
           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 View on GitHub
- 
           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 View on GitHub
- 
           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 View on GitHub
- 
           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.
 
 - set_ttl ( ttl : int ) bool | None View on GitHub
- 
           Set the new ttl value for DCS keys. 
 - take_leader ( * args : Any , ** kwargs : Any ) Any View on GitHub
- 
           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 View on GitHub
- 
           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 : 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 :
- 
             - 
               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.etcd. EtcdClient ( config : Dict [ str , Any ] , dns_resolver : DnsCachingResolver , cache_ttl : int = 300 ) View on GitHub
- 
         Bases: AbstractEtcdClientWithFailover- ERROR_CLS View on GitHub
- 
           alias of EtcdError
 - __init__ ( config : Dict [ str , Any ] , dns_resolver : DnsCachingResolver , cache_ttl : int = 300 ) None View on GitHub
 - _abc_impl = <_abc._abc_data object>
 - _get_members ( base_uri : str , ** kwargs : Any ) List [ str ] View on GitHub
- 
           returns: list of clientURLs 
 - _handle_server_response ( response : HTTPResponse ) Any View on GitHub
- 
           Handles the server response 
 - _prepare_get_members ( etcd_nodes : int ) Dict [ str , Any ] View on GitHub
- 
           returns: request parameters 
 
- exception patroni.dcs.etcd. EtcdError ( value : Any ) View on GitHub
- 
         Bases: DCSError
- exception patroni.dcs.etcd. EtcdRaftInternal ( message = None , payload = None ) View on GitHub
- 
         Bases: EtcdExceptionRaft Internal Error 
- exception patroni.dcs.etcd. StaleEtcdNode View on GitHub
- 
         Bases: ExceptionNode is stale (raft term is older than previous known). 
- class patroni.dcs.etcd. StaleEtcdNodeGuard View on GitHub
- 
         Bases: object- __init__ ( ) None View on GitHub
 - _check_cluster_raft_term ( cluster_id : str | None , value : None | str | int ) None View on GitHub
- 
           Check that observed Raft Term in Etcd cluster is increasing. - Parameters :
- 
             - 
               cluster_id – last observed Etcd Cluster ID 
- 
               raft_term – last observed Raft Term 
 
- 
               
- Raises :
- 
             :exc:: StaleEtcdNodeif last observed raft_term is smaller than previously known raft_term .
 
 - _reset_cluster_raft_term ( ) None View on GitHub
 
- patroni.dcs.etcd. catch_etcd_errors ( func : Callable [ [ ... ] , Any ] ) Any View on GitHub