patroni.config module

Facilities related to Patroni configuration.

class _patroni.config.Config(_configfile: str, validator: typing.Callable[[typing.Dict[str, ~typing.Any]], ~typing.List[str]] | None = <function default_validator>) View on GitHub

Bases: object + Handle Patroni configuration. + This class is responsible for: + __\\__

  1. Building and giving access to effective_configuration from:

  2. Saving and loading dynamic_configuration into ‘patroni.dynamic.json’ file located in local_configuration[‘postgresql’][‘data_dir’] directory. This is necessary to be able to restore dynamic_configuration if DCS was accidentally wiped.

  3. Loading of configuration file in the old format and converting it into new format.

  4. Mimicking some dict interfaces to make it possible to work with it as with the old config object. __\\__ +

    Variables:

    +

    PATRONI_CONFIG_VARIABLE_ = 'PATRONI_CONFIGURATION'_

    +

    __CACHE_FILENAME_ = 'patroni.dynamic.json'_

    +

    __DEFAULT_CONFIG_: Dict[ str, Any] = \{'loop_wait': 10, 'postgresql': \{'parameters': <CaseInsensitiveDict\{'wal_level': 'hot_standby', 'hot_standby': 'on', 'max_connections': 100, 'max_wal_senders': 10, 'max_prepared_transactions': 0, 'max_locks_per_transaction': 64, 'track_commit_timestamp': 'off', 'max_replication_slots': 10, 'max_worker_processes': 8, 'wal_log_hints': 'on'} at 7f8bcc185710>, 'use_slots': True}, 'retry_timeout': 10, 'standby_cluster': \{'archive_cleanup_command': '', 'create_replica_methods': '', 'host': '', 'port': '', 'primary_slot_name': '', 'recovery_min_apply_delay': '', 'restore_command': ''}, 'ttl': 30}_

    +

    __get_and_maybe_adjust_int_value(_config: Dict[ str, Any]_, param: str, min_value: int) → int

    Get, validate and maybe adjust a param integer value from the config dict. +

    Parameters
    Returns

    an integer value which corresponds to a provided param. +

    __init\\__(configfile: str, validator: typing.Callable[[typing.Dict[str, ~typing.Any]], ~typing.List[str]] | None = <function default_validator>) → None View on GitHub

    Create a new instance of Config and validate the loaded configuration using validator. + Note

    Patroni will read configuration from these locations in this order:
      \\__\\__
      \\__\\__
      +
      Parameters:::
      Raises:::
        `+ConfigParseError+`: if any issue is reported by _validator_.
    +
    build_effective_configuration(_dynamic_configuration: Dict[ str, Any], local_configuration: Dict[ str, Dict[ str, Any] | Any]) → Dict[ str, Any] View on GitHub

    Build effective configuration by merging dynamic_configuration and local_configuration. + Note

      _local_configuration_ takes precedence over _dynamic_configuration_ if a setting is defined in both.
      +
      Parameters:::
      Returns:::
        _description_
    +
    _static \\__build_environment_configuration() → Dict[ str, Any] View on GitHub

    Get local configuration settings that were specified through environment variables. +

    Returns

    dictionary containing the found environment variables and their values, respecting the expected structure of Patroni configuration. +

    _load_cache() → None View on GitHub

    Load dynamic configuration from patroni.dynamic.json. +

    _load_config_file() → Dict[ str, Any] View on GitHub

    Load configuration file(s) from filesystem and apply values which were set via environment variables. +

    Returns

    final configuration after merging configuration file(s) and environment variables. +

    load_config_path(_path: str) → Dict[ str, Any] View on GitHub

    Load Patroni configuration file(s) from path. + If path is a file, load the yml file pointed to by path. If path is a directory, load all yml files in that directory in alphabetical order. +

    Parameters

    path – path to either an YAML configuration file, or to a folder containing YAML configuration files.

    Returns

    configuration after reading the configuration file(s) from path.

    Raises

    ConfigParseError: if path is invalid. +

    static \\__process_postgresql_parameters(_parameters: Dict[ str, Any], is_local: bool = False) → Dict[ str, Any] View on GitHub

    Process Postgres parameters. + Note

    If _is_local_ configuration discard any setting from _parameters_ that is listed under link:patroni.postgresql.config.html#patroni.postgresql.config.ConfigHandler.CMDLINE_OPTIONS[`+CMDLINE_OPTIONS+`] as those are supposed to be set only through dynamic configuration.
    When setting parameters from link:patroni.postgresql.config.html#patroni.postgresql.config.ConfigHandler.CMDLINE_OPTIONS[`+CMDLINE_OPTIONS+`] through dynamic configuration their value will be validated as per the validator defined in that very same attribute entry. If the given value cannot be validated, a warning will be logged and the default value of the GUC will be used instead.
    Some parameters from link:patroni.postgresql.config.html#patroni.postgresql.config.ConfigHandler.CMDLINE_OPTIONS[`+CMDLINE_OPTIONS+`] cannot be set even if not _is_local_ configuration:
      \\__\\__
      \\__\\__
      +
      Parameters:::
      Returns:::
        new value for `+postgresql.parameters+` after processing and validating _parameters_.
    +
    safe_copy_dynamic_configuration(_dynamic_configuration: Dict[ str, Any]) → Dict[ str, Any] View on GitHub

    Create a copy of dynamic_configuration. + Merge dynamic_configuration with \\__DEFAULT_CONFIG (_dynamic_configuration_ takes precedence), and process postgresql.parameters from dynamic_configuration through _process_postgresql_parameters(), if present. + Note

    The following settings are not allowed in `+postgresql+` section as they are intended to be local configuration, and are removed if present:
    \\__\\__
    \\__\\__
      Besides that any setting present in _dynamic_configuration_ but absent from link:#patroni.config.Config.\\__DEFAULT_CONFIG[`+\\__DEFAULT_CONFIG+`] is discarded.
      +
      Parameters:::
        *dynamic_configuration* – Patroni dynamic configuration.
      Returns:::
        copy of _dynamic_configuration_, merged with default dynamic configuration and with some sanity checks performed over it.
    +
    validate_and_adjust_timeouts(_config: Dict[ str, Any]) → None View on GitHub

    Validate and adjust loop_wait, retry_timeout, and ttl values if necessary. + Minimum values: + __\\__ __\\__ + Maximum values: In case if values don’t fulfill the following rule, retry_timeout and loop_wait are reduced so that the rule is fulfilled: + __\\__

    loop_wait + 2 * retry_timeout <= ttl
    \\__\\__
    +
    Parameters

    configdict object with new global configuration. +

    _validate_failover_tags() → None View on GitHub

    Check nofailover/failover_priority config and warn user if it’s contradictory. + Note

      To preserve sanity (and backwards compatibility) the `+nofailover+` tag will still exist. A contradictory configuration is one where `+nofailover+` is `+True+` but `+failover_priority+``+ +``+>+``+ +``+0+`, or where `+nofailover+` is `+False+`, but `+failover_priority+``+ +``+<=+``+ +``+0+`. Essentially, `+nofailover+` and `+failover_priority+` are communicating different things. This checks for this edge case (which is a misconfiguration on the part of the user) and warns them. The behaviour is as if `+failover_priority+` were not provided (i.e `+nofailover+` is the bedrock source of truth)
    +
    property _config_file: str | None_

    Path to Patroni configuration file, if any, else None. +

    copy() → Dict[ str, Any] View on GitHub

    Get a deep copy of effective Patroni configuration. +

    Returns

    a deep copy of the Patroni configuration. +

    property _dynamic_configuration: Dict[ str, Any]_

    Deep copy of cached Patroni dynamic configuration. +

    get(key: str, default: Any | None = None) → Any View on GitHub

    Get effective value of key setting from Patroni configuration root. + Designed to work the same way as dict.get(). +

    Parameters
    Returns

    value of key, if present in the effective configuration, otherwise default. +

    _classmethod _get_default_config() → Dict[ str, Any] View on GitHub

    Deep copy default configuration. +

    Returns

    copy of \\__DEFAULT_CONFIG +

    property _local_configuration: Dict[ str, Any]_

    Deep copy of cached Patroni local configuration. +

    Returns

    copy of _local_configuration +

    reload_local_configuration() → bool | None View on GitHub

    Reload configuration values from the configuration file(s). + Note

    Designed to be used when user applies changes to configuration file(s), so Patroni can use the new values with a reload instead of a restart.
    +
    Returns

    True if changes have been detected between current local configuration +

    save_cache() → None View on GitHub

    Save dynamic configuration to patroni.dynamic.json under Postgres data directory. + Note

      `+patroni.dynamic.jsonXXXXXX+` is created as a temporary file and than renamed to `+patroni.dynamic.json+`, where `+XXXXXX+` is a random suffix.
    +
    set_dynamic_configuration(configuration: ClusterConfig | Dict[ str, Any]) → bool View on GitHub

    Set dynamic configuration values with given configuration. +

    Parameters

    configuration – new dynamic configuration values. Supports dict for backward compatibility.

    Returns

    True if changes have been detected between current dynamic configuration and the new dynamic configuration, False otherwise.

patroni.config.default_validator(conf: Dict[ str, Any]) → List[ str] View on GitHub

Ensure conf is not empty. + Designed to be used as default validator for Config objects, if no specific validator is provided. +

Parameters:

conf – configuration to be validated.

Returns:

an empty list – Config expects the validator to return a list of 0 or more issues found while validating the configuration.

Raises:

ConfigParseError: if conf is empty.


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

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

Read the Docs v: latest

+ Builds