patroni.postgresql.citus module¶
- class patroni.postgresql.citus.CitusHandler(postgresql: Postgresql, config: Optional[Dict[str, Union[str, int]]])¶
Bases:
threading.Thread
- add_task(event: str, group: int, conn_url: str, timeout: Optional[float] = None, cooldown: Optional[float] = None) Optional[patroni.postgresql.citus.PgDistNode] ¶
- handle_event(cluster: patroni.dcs.Cluster, event: Dict[str, Any]) None ¶
- pick_task() Tuple[Optional[int], Optional[patroni.postgresql.citus.PgDistNode]] ¶
Returns the tuple(i, task), where i - is the task index in the self._tasks list
Tasks are picked by following priorities:
If there is already a transaction in progress, pick a task that that will change already affected worker primary.
If the coordinator address should be changed - pick a task with group=0 (coordinators are always in group 0).
Pick a task that is the oldest (first from the self._tasks)
- process_task(task: patroni.postgresql.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.
- 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.
- sync_pg_dist_node(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.citus.PgDistNode) None ¶