patroni.postgresql.validator module

class _patroni.postgresql.validator.Bool(_version_from: int, version_till: int | None = None) View on GitHub

Bases: _Transformable +

abc_impl = <_abc._abc_data object>_

+

transform(name: str, value: Any) → Any | None View on GitHub

Verify that provided value is valid. +

Parameters
Returns

the value (sometimes clamped) or None if the value isn’t valid

class _patroni.postgresql.validator.Enum(*, _version_from: int, version_till: int | None = None, possible_values: Tuple[ str, …​]) View on GitHub

Bases: _Transformable +

__init\\__(*, version_from: int, version_till: int | None = None, possible_values: Tuple[ str, …​]) → None View on GitHub

+

abc_impl = <_abc._abc_data object>_

+

property _possible_values: Tuple[ str, …​]_

+

transform(name: str, value: Any | None) → Any | None View on GitHub

Verify that provided value is valid. +

Parameters
Returns

the value (sometimes clamped) or None if the value isn’t valid

class _patroni.postgresql.validator.EnumBool(*, _version_from: int, version_till: int | None = None, possible_values: Tuple[ str, …​]) View on GitHub

Bases: Enum +

abc_impl = <_abc._abc_data object>_

+

transform(name: str, value: Any | None) → Any | None View on GitHub

Verify that provided value is valid. +

Parameters
Returns

the value (sometimes clamped) or None if the value isn’t valid

class _patroni.postgresql.validator.Integer(*, _version_from: int, version_till: int | None = None, min_val: int | float, max_val: int | float, unit: str | None = None) View on GitHub

Bases: Number +

abc_impl = <_abc._abc_data object>_

+

static _parse(_value: Any, unit: str | None) → int | None View on GitHub

Convert provided value to unit.

exception _patroni.postgresql.validator.InvalidGucValidatorsFile(_value: Any) View on GitHub

Bases: PatroniException + Raised when reading or parsing of a YAML file faces an issue.

class _patroni.postgresql.validator.Number(*, _version_from: int, version_till: int | None = None, min_val: int | float, max_val: int | float, unit: str | None = None) View on GitHub

Bases: _Transformable +

__init\\__(*, version_from: int, version_till: int | None = None, min_val: int | float, max_val: int | float, unit: str | None = None) → None View on GitHub

+

abc_impl = <_abc._abc_data object>_

+

property _max_val: int | float_

+

property _min_val: int | float_

+

abstract static _parse(_value: Any, unit: str | None) → Any | None View on GitHub

Convert provided value to unit. +

transform(name: str, value: Any) → int | float | None View on GitHub

Verify that provided value is valid. +

Parameters
Returns

the value (sometimes clamped) or None if the value isn’t valid +

property _unit: str | None_
class _patroni.postgresql.validator.Real(*, _version_from: int, version_till: int | None = None, min_val: int | float, max_val: int | float, unit: str | None = None) View on GitHub

Bases: Number +

abc_impl = <_abc._abc_data object>_

+

static _parse(_value: Any, unit: str | None) → float | None View on GitHub

Convert provided value to unit.

class _patroni.postgresql.validator.String(_version_from: int, version_till: int | None = None) View on GitHub

Bases: _Transformable +

abc_impl = <_abc._abc_data object>_

+

transform(name: str, value: Any | None) → Any | None View on GitHub

Verify that provided value is valid. +

Parameters
Returns

the value (sometimes clamped) or None if the value isn’t valid

class _patroni.postgresql.validator.ValidatorFactory(_validator: Dict[ str, Any]) View on GitHub

Bases: object + Factory class used to build Patroni validator objects based on the given specs. +

TYPES_: Dict[ str, Type[_Transformable]] = \{'Bool': <class 'patroni.postgresql.validator.Bool'>, 'Enum': <class 'patroni.postgresql.validator.Enum'>, 'EnumBool': <class 'patroni.postgresql.validator.EnumBool'>, 'Integer': <class 'patroni.postgresql.validator.Integer'>, 'Number': <class 'patroni.postgresql.validator.Number'>, 'Real': <class 'patroni.postgresql.validator.Real'>, 'String': <class 'patroni.postgresql.validator.String'>}_
exception _patroni.postgresql.validator.ValidatorFactoryInvalidSpec(_value: Any) View on GitHub

Bases: PatroniException + Raised when a validator spec contains an invalid set of attributes.

exception _patroni.postgresql.validator.ValidatorFactoryInvalidType(_value: Any) View on GitHub

Bases: PatroniException + Raised when a validator spec contains an invalid type.

exception _patroni.postgresql.validator.ValidatorFactoryNoType(_value: Any) View on GitHub

Bases: PatroniException + Raised when a validator spec misses a type.

class _patroni.postgresql.validator._Transformable(_version_from: int, version_till: int | None = None) View on GitHub

Bases: ABC +

__init\\__(version_from: int, version_till: int | None = None) → None View on GitHub

+

abc_impl = <_abc._abc_data object>_

+

_classmethod _get_subclasses() → Iterator[ Type[_Transformable]] View on GitHub

Recursively get all subclasses of _Transformable. +

Yields

each subclass of _Transformable. +

abstract _transform(_name: str, value: Any) → Any | None View on GitHub

Verify that provided value is valid. +

Parameters
Returns

the value (sometimes clamped) or None if the value isn’t valid +

property _version_from: int_

+

property _version_till: int | None_
patroni.postgresql.validator.get_postgres_guc_validators(_config: Dict[ str, Any], parameter: str) → Tuple[_Transformable, …​] View on GitHub

Get all validators of parameter from config. + Loop over all validators specs of parameter and return them parsed as Patroni validators. +

Parameters:
Return type:

yields any exception that is faced while parsing a validator spec into a Patroni validator object.

patroni.postgresql.validator._load_postgres_gucs_validators() → None View on GitHub

Load all Postgres GUC validators from YAML files. + Recursively walk through available_parameters directory and load validators of each found YAML file into parameters and/or recovery_parameters variables. +

Walk through directories in top-down fashion and for each of them:

+ Any problem faced while reading or parsing files will be logged as a WARNING by the child function, and the corresponding file or validator will be ignored. + By default, Patroni only ships the file 0_postgres.yml, which contains Community Postgres GUCs validators, but that behavior can be extended. For example: if a vendor wants to add GUC validators to Patroni for covering a custom Postgres build, then they can create their custom YAML files under available_parameters directory. +

Each YAML file may contain either or both of these root attributes, here called sections:

+ Then, each of these sections, if specified, may contain one or more attributes with the following structure: + __\\__

  • key: the name of a GUC;

  • value: a list of validators. Each item in the list must contain a type attribute, which must be one among: + __\\__ Besides the type attribute, it should also contain all the required attributes as per the corresponding class in this module. __\\__ __\\__ + See also +

Example:

This is a sample content for an YAML file based on Postgres GUCs, showing each of the supported types and sections: + __\\__

parameters:
  archive_command:
  - type: String
    version_from: 90300
    version_till: null
  archive_mode:
  - type: Bool
    version_from: 90300
    version_till: 90500
  - type: EnumBool
    version_from: 90500
    version_till: null
    possible_values:
    - always
  archive_timeout:
  - type: Integer
    version_from: 90300
    version_till: null
    min_val: 0
    max_val: 1073741823
    unit: s
  autovacuum_vacuum_cost_delay:
  - type: Integer
    version_from: 90300
    version_till: 120000
    min_val: -1
    max_val: 100
    unit: ms
  - type: Real
    version_from: 120000
    version_till: null
    min_val: -1
    max_val: 100
    unit: ms
  client_min_messages:
  - type: Enum
    version_from: 90300
    version_till: null
    possible_values:
    - debug5
    - debug4
    - debug3
    - debug2
    - debug1
    - log
    - notice
    - warning
    - error
recovery_parameters:
  archive_cleanup_command:
  - type: String
    version_from: 90300
    version_till: null
\\__\\__
patroni.postgresql.validator.read_postgres_gucs_validators_file(_file: Traversable) → Dict[ str, Any] View on GitHub

Read an YAML file and return the corresponding Python object. +

Parameters:

file – path-like object to read from. It is expected to be encoded with UTF-8, and to be a YAML document.

Returns:

the YAML content parsed into a Python object. If any issue is faced while reading/parsing the file, then return None.

Raises:

InvalidGucValidatorsFile: if faces an issue while reading or parsing file.

patroni.postgresql.validator.transform_parameter_value(_validators: MutableMapping[ str, Tuple[_Transformable, …​]], version: int, name: str, value: Any, available_gucs: CaseInsensitiveSet) → Any | None View on GitHub

Validate value of GUC name for Postgres version using defined validators and available_gucs. +

Parameters:
Returns:

the return value may be one among:

patroni.postgresql.validator.transform_postgresql_parameter_value(version: int, name: str, value: Any, available_gucs: CaseInsensitiveSet) → Any | None View on GitHub

Validate value of GUC name for Postgres version using parameters and available_gucs. +

Parameters:
Returns:

The return value may be one among:

patroni.postgresql.validator.transform_recovery_parameter_value(version: int, name: str, value: Any, available_gucs: CaseInsensitiveSet) → Any | None View on GitHub

Validate value of GUC name for Postgres version using recovery_parameters and available_gucs. +

Parameters:
Returns:

value transformed to the expected format for recovery GUC name in Postgres version using validators defined in recovery_parameters. It can also return None. See _transform_parameter_value().


© Copyright 2015 Compose, Zalando SE. Revision 9d231aee.

Built with Sphinx using a theme provided by Read the Docs.

Read the Docs v: latest

+ Builds