patroni.tags module

Tags handling.

class patroni.tags.TagsView on GitHub

Bases: ABC

An abstract class that encapsulates all the tags logic.

Child classes that want to use provided facilities must implement tags abstract property.

Note

Due to backward-compatibility reasons, old tags may have a less strict type conversion than new ones.

_abc_impl = <_abc._abc_data object>
_bool_tag(bool_name: str, priority_name: str) boolView on GitHub

Common logic for obtaining the value of a boolean tag from tags if defined.

If boolean tag is not defined, this methods returns True if priority tag is non-positive, False otherwise.

Parameters:
  • bool_name – name of the boolean tag (nofailover. nosync).

  • priority_name – name of the priority tag (failover_priority, sync_priority).

Returns:

boolean value based on the defined tags.

static _filter_tags(tags: Dict[str, Any]) Dict[str, Any]View on GitHub

Get tags configured for this node, if any.

Handle both predefined Patroni tags and custom defined tags.

Note

A custom tag is any tag added to the configuration tags section that is not one of clonefrom, nofailover, noloadbalance,``nosync`` or nostream.

For most of the Patroni predefined tags, the returning object will only contain them if they are enabled as they all are boolean values that default to disabled. However nofailover tag is always returned if failover_priority tag is defined. In this case, we need both values to see if they are contradictory and the nofailover value should be used. The same rule applies for nosync and sync_priority tags.

Returns:

a dictionary of tags set for this node. The key is the tag name, and the value is the corresponding tag value.

_priority_tag(bool_name: str, priority_name: str) intView on GitHub

Common logic for obtaining the value of a priority tag from tags if defined.

If boolean tag is defined as True, this will return 0. Otherwise, it will return the value of the respective priority tag, defaulting to 1 if it’s not defined or invalid.

Parameters:
  • bool_name – name of the boolean tag (nofailover. nosync).

  • priority_name – name of the priority tag (failover_priority, sync_priority).

Returns:

integer value based on the defined tags.

property clonefrom: boolView on GitHub

True if clonefrom tag is True, else False.

property failover_priority: intView on GitHub

Value of failover_priority from tags if defined, otherwise derived from nofailover.

property nofailover: boolView on GitHub

True if node configuration doesn’t allow it to become primary, False otherwise.

property noloadbalance: boolView on GitHub

True if noloadbalance is True, else False.

property nostream: boolView on GitHub

True if nostream is True, else False.

property nosync: boolView on GitHub

True if node configuration doesn’t allow it to become synchronous, False otherwise.

property replicatefrom: str | NoneView on GitHub

Value of replicatefrom tag, if any.

property sync_priority: intView on GitHub

Value of sync_priority from tags if defined, otherwise derived from nosync.

abstract property tags: Dict[str, Any]View on GitHub

Configured tags.

Must be implemented in a child class.