patroni.dcs.consul module¶
- class patroni.dcs.consul.Consul(config: Dict[str, Any])¶
Bases:
AbstractDCS- 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(**kwargs: Any) Any¶
Removes the
initializekey for a cluster.- Returns:
Trueif successfully committed to DCS.
- delete_cluster(**kwargs: Any) Any¶
Delete cluster from DCS.
- Returns:
Trueif successfully committed to DCS.
- delete_sync_state(**kwargs: Any) Any¶
Delete the synchronous state from DCS.
- Parameters:
version – for conditional deletion of the key/object.
- Returns:
Trueif delete successful.
- initialize(**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.
- reload_config(config: Union[Config, Dict[str, Any]]) None¶
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_config_value(**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(**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(**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(**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() bool¶
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(**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: Optional[int], 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.consul.ConsulClient(*args: Any, **kwargs: Any)¶
Bases:
Consul- connect(*args: Any, **kwargs: Any) HTTPClient¶
- http_connect(*args: Any, **kwargs: Any) HTTPClient¶
- exception patroni.dcs.consul.ConsulInternalError¶
Bases:
ConsulExceptionAn internal Consul server error occurred
- class patroni.dcs.consul.HTTPClient(host: str = '127.0.0.1', port: int = 8500, token: Optional[str] = None, scheme: str = 'http', verify: bool = True, cert: Optional[str] = None, ca_cert: Optional[str] = None)¶
Bases:
object
- exception patroni.dcs.consul.InvalidSession¶
Bases:
ConsulExceptioninvalid session
- exception patroni.dcs.consul.InvalidSessionTTL¶
Bases:
ConsulExceptionSession TTL is too small or too big
- class patroni.dcs.consul.Response(code, headers, body, content)¶
Bases:
NamedTuple