# patroni.postgresql.citus module

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

  Bases: `Thread`

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

    This constructor should always be called with keyword arguments. Arguments are:

    group should be None; reserved for future extension when a ThreadGroup class is implemented.

    target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.

    name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.

    args is a list or tuple of arguments for the target invocation. Defaults to ().

    kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.

    If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.

  _add_task(task: PgDistNode) → bool
  add_task(event: str, group: int, conn_url: str, timeout: float | None = None, cooldown: float | None = None) → PgDistNode | None
  adjust_postgres_gucs(parameters: Dict[str, Any]) → None
  bootstrap() → None
  find_task_by_group(group: int) → int | None
  group() → int | None
  handle_event(cluster: Cluster, event: Dict[str, Any]) → None
  ignore_replication_slot(slot: Dict[str, str]) → bool
  is_coordinator() → bool
  is_enabled() → bool
  is_worker() → bool
  load_pg_dist_node() → bool

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

  on_demote() → None
  pick_task() → Tuple[int | None, PgDistNode | None]

    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: 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
  sync_pg_dist_node(cluster: 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: PgDistNode) → None

class patroni.postgresql.citus.PgDistNode(group: int, host: str, port: int, event: str, nodeid: int | None = None, timeout: float | None = None, cooldown: float | None = None)

  Bases: `object`

  Represents a single row in the pg_dist_node table

  __init__(group: int, host: str, port: int, event: str, nodeid: int | None = None, timeout: float | None = None, cooldown: float | None = None) → None
  wait() → None
  wakeup() → None