patroni.postgresql.mpp.citus module

class patroni.postgresql.mpp.citus.Citus(config: Dict[str, Union[str, int]])

Bases: patroni.postgresql.mpp.AbstractMPP

_abc_impl = <_abc._abc_data object>
property coordinator_group_id: int

The group id of the Citus coordinator PostgreSQL cluster.

property group: int

The group of this Citus node.

group_re: Any = re.compile('^(0|[1-9][0-9]*)$')
static validate_config(config: Union[Any, Dict[str, Union[str, int]]]) bool

Check whether provided config is good for a given MPP.

Parameters

config – configuration of citus MPP section.

Returns

True is config passes validation, otherwise False.

class patroni.postgresql.mpp.citus.CitusHandler(postgresql: Postgresql, config: Dict[str, Union[str, int]])

Bases: patroni.postgresql.mpp.citus.Citus, patroni.postgresql.mpp.AbstractMPPHandler, threading.Thread

Define the interfaces for handling an underlying Citus cluster.

__init__(postgresql: Postgresql, config: Dict[str, Union[str, int]]) None

“Initialize a new instance of CitusHandler.

Parameters
  • postgresql – the Postgres node.

  • config – the citus MPP config section.

_abc_impl = <_abc._abc_data object>
_add_task(task: patroni.postgresql.mpp.citus.PgDistNode) bool
add_task(event: str, group: int, conn_url: str, timeout: Optional[float] = None, cooldown: Optional[float] = None) Optional[patroni.postgresql.mpp.citus.PgDistNode]
adjust_postgres_gucs(parameters: Dict[str, Any]) None

Adjust GUCs in the current PostgreSQL configuration.

Parameters

parameters – dictionary of GUCs, with key as GUC name and the corresponding value as current GUC value.

bootstrap() None

Bootstrap handler.

Is called when the new cluster is initialized (through initdb or a custom bootstrap method).

find_task_by_group(group: int) Optional[int]
handle_event(cluster: patroni.dcs.Cluster, event: Dict[str, Any]) None

Handle an event sent from a worker node.

Parameters
  • cluster – the currently known cluster state from DCS.

  • event – the event to be handled.

ignore_replication_slot(slot: Dict[str, str]) bool

Check whether provided replication slot existing in the database should not be removed.

Note

MPP database may create replication slots for its own use, for example to migrate data between workers using logical replication, and we don’t want to suddenly drop them.

Parameters

slot – dictionary containing the replication slot settings, like name, database, type, and plugin.

Returns

True if the replication slots should not be removed, otherwise False.

load_pg_dist_node() bool

Read from the pg_dist_node table and put it into the local cache

on_demote() None

On demote handler.

Is called when the primary was demoted.

pick_task() Tuple[Optional[int], Optional[patroni.postgresql.mpp.citus.PgDistNode]]

Returns the tuple(i, task), where i - is the task index in the self._tasks list

Tasks are picked by following priorities:

  1. If there is already a transaction in progress, pick a task that that will change already affected worker primary.

  2. If the coordinator address should be changed - pick a task with group=0 (coordinators are always in group 0).

  3. Pick a task that is the oldest (first from the self._tasks)

process_task(task: patroni.postgresql.mpp.citus.PgDistNode) bool

Updates a single row in pg_dist_node table, optionally in a transaction.

The transaction is started if we do a demote of the worker node or before promoting the other worker if there is no transaction in progress. And, the transaction is committed when the switchover/failover completed.

Parameters

task – reference to a PgDistNode object that represents a row to be updated/created.

Returns

True if the row was succesfully created/updated or transaction in progress was committed as an indicator that the self._pg_dist_node cache should be updated, or, if the new transaction was opened, this method returns False.

process_tasks() None
query(sql: str, *params: Any) List[Tuple[Any, ...]]
run() None

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

schedule_cache_rebuild() None

Cache rebuild handler.

Is called to notify handler that it has to refresh its metadata cache from the database.

sync_meta_data(cluster: patroni.dcs.Cluster) None

Maintain the pg_dist_node from the coordinator leader every heartbeat loop.

We can’t always rely on REST API calls from worker nodes in order to maintain pg_dist_node, therefore at least once per heartbeat loop we make sure that workes registered in self._pg_dist_node cache are matching the cluster view from DCS by creating tasks the same way as it is done from the REST API.

update_node(task: patroni.postgresql.mpp.citus.PgDistNode) None
class patroni.postgresql.mpp.citus.PgDistNode(group: int, host: str, port: int, event: str, nodeid: Optional[int] = None, timeout: Optional[float] = None, cooldown: Optional[float] = None)

Bases: object

Represents a single row in the pg_dist_node table

__init__(group: int, host: str, port: int, event: str, nodeid: Optional[int] = None, timeout: Optional[float] = None, cooldown: Optional[float] = None) None
wait() None
wakeup() None