patroni.postgresql.sync module
- class _patroni.postgresql.sync.SyncHandler(_postgresql: Postgresql) View on GitHub
-
Bases:
object
+ Class responsible for working with the synchronous_standby_names. + Sync standbys are chosen based on their state in pg_stat_replication. When synchronous_standby_names is changed we memorize the _primary_flush_lsn and the current_state() method will count newly added names as “sync” only when they reached memorized LSN and also reported as “sync” by pg_stat_replication +- __init\\__(postgresql: Postgresql) → None View on GitHub
-
+
- _handle_synchronous_standby_names_change() → None View on GitHub
-
Handles changes of “synchronous_standby_names” GUC.
If “synchronous_standby_names” was changed, we need to check that newly added replicas have reached self._primary_flush_lsn. Only after that they could be counted as synchronous. + - process_replica_readiness(_cluster: Cluster, replica_list: _ReplicaList) → None View on GitHub
-
Flags replicas as truly “synchronous” when they have caught up with
_primary_flush_lsn
. +- Parameters
-
+
- current_state(cluster: Cluster) → Tuple[CaseInsensitiveSet, CaseInsensitiveSet] View on GitHub
-
Find the best candidates to be the synchronous standbys. + Current synchronous standby is always preferred, unless it has disconnected or does not want to be a synchronous standby any longer. + Standbys are selected based on values from the global configuration: +
- Returns
-
tuple of candidates
CaseInsensitiveSet
and synchronous standbysCaseInsensitiveSet
. +
- set_synchronous_standby_names(sync: Collection[ str]) → None View on GitHub
-
Constructs and sets “synchronous_standby_names” GUC value. +
- Parameters
-
sync – set of nodes to sync to
- class _patroni.postgresql.sync._Replica(_pid: int, application_name: str, sync_state: str, lsn: int, nofailover: bool) View on GitHub
-
Bases:
NamedTuple
+ Class representing a single replica that is eligible to be synchronous. + Attributes are taken frompg_stat_replication
view and respectiveCluster.members
. +- Variables:
-
+
- _asdict() View on GitHub
-
Return a new dict which maps field names to their values. +
- field_defaults = \{}_
-
+
- fields = ('pid', 'application_name', 'sync_state', 'lsn', 'nofailover')_
-
+
- classmethod \\__make(_iterable) View on GitHub
-
Make a new _Replica object from a sequence or iterable +
- replace(**kwds_) View on GitHub
-
Return a new _Replica object replacing specified fields with new values +
- application_name_: str_
-
Alias for field number 1 +
- lsn_: int_
-
Alias for field number 3 +
- nofailover_: bool_
-
Alias for field number 4 +
- pid_: int_
-
Alias for field number 0 +
- sync_state_: str_
-
Alias for field number 2
- class _patroni.postgresql.sync._ReplicaList(_postgresql: Postgresql, cluster: Cluster) View on GitHub
-
Bases:
List
[_Replica
] + A collection of :class:`_Replica` objects. + Values are reverse ordered by_Replica.sync_state
and_Replica.lsn
. That is, first there will be replicas that havesync_state
==sync
, even if they are not the most up-to-date in term of write/flush/replay LSN. It helps to keep the result of chosing new synchronous nodes consistent in case if a synchronous standby member is slowed down OR async node is receiving changes faster than the sync member. Such cases would trigger sync standby member swapping, but only if lag on this member is exceeding a threshold (maximum_lag_on_syncnode
). +- Variables:
-
max_lsn – maximum value of
_Replica.lsn
among all values. In case if there is just one element in the list we take value ofpg_current_wal_flush_lsn()
. + - __init\\__(postgresql: Postgresql, cluster: Cluster) → None View on GitHub
-
Create :class:`_ReplicaList` object. +
- Parameters
- class _patroni.postgresql.sync._SSN(_sync_type: str, has_star: bool, num: int, members: CaseInsensitiveSet) View on GitHub
-
Bases:
NamedTuple
+ class representing “synchronous_standby_names” value after parsing. +- Variables:
-
+
- _asdict() View on GitHub
-
Return a new dict which maps field names to their values. +
- field_defaults = \{}_
-
+
- fields = ('sync_type', 'has_star', 'num', 'members')_
-
+
- classmethod \\__make(_iterable) View on GitHub
-
Make a new _SSN object from a sequence or iterable +
- replace(**kwds_) View on GitHub
-
Return a new _SSN object replacing specified fields with new values +
- has_star_: bool_
-
Alias for field number 1 +
- members_: CaseInsensitiveSet_
-
Alias for field number 3 +
- num_: int_
-
Alias for field number 2 +
- sync_type_: str_
-
Alias for field number 0
- patroni.postgresql.sync.parse_sync_standby_names(value: str) → _SSN View on GitHub
-
Parse postgresql synchronous_standby_names to constituent parts. +
- Parameters:
-
value – the value of synchronous_standby_names
- Returns:
-
_SSN
object - Raises:
-
ValueError – if the configuration value can not be parsed +
>>> parse_sync_standby_names('').sync_type 'off'
+
>>> parse_sync_standby_names('FiRsT').sync_type 'priority'
+
>>> 'first' in parse_sync_standby_names('FiRsT').members True
+
>>> set(parse_sync_standby_names('"1"').members) {'1'}
+
>>> parse_sync_standby_names(' a , b ').members == {'a', 'b'} True
+
>>> parse_sync_standby_names(' a , b ').num 1
+
>>> parse_sync_standby_names('ANY 4("a",*,b)').has_star True
+
>>> parse_sync_standby_names('ANY 4("a",*,b)').num 4
+
>>> parse_sync_standby_names('1') Traceback (most recent call last): ... ValueError: Unparseable synchronous_standby_names value
+
>>> parse_sync_standby_names('a,') Traceback (most recent call last): ... ValueError: Unparseable synchronous_standby_names value
+
>>> parse_sync_standby_names('ANY 4("a" b,"c c")') Traceback (most recent call last): ... ValueError: Unparseable synchronous_standby_names value
+
>>> parse_sync_standby_names('FIRST 4("a",)') Traceback (most recent call last): ... ValueError: Unparseable synchronous_standby_names value
+
>>> parse_sync_standby_names('2 (,)') Traceback (most recent call last): ... ValueError: Unparseable synchronous_standby_names value
- patroni.postgresql.sync.quote_ident(value: str) → str View on GitHub
-
Very simplified version of psycopg
quote_ident()
function.
© Copyright 2015 Compose, Zalando SE. Revision 9d231aee
.
Built with Sphinx using a theme provided by Read the Docs.
Read the Docs v: latest
+ Builds