mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
Format code according to pep8.
replace get_client_path("/members?recursive=true") with members()
replace do-plpgsq block by simple sql
This commit is contained in:
+12
-5
@@ -1,6 +1,10 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys, os, yaml, time, urllib2, atexit
|
||||
import sys
|
||||
import yaml
|
||||
import time
|
||||
import urllib2
|
||||
import atexit
|
||||
import logging
|
||||
|
||||
from helpers.etcd import Etcd
|
||||
@@ -19,6 +23,8 @@ postgresql = Postgresql(config["postgresql"])
|
||||
ha = Ha(postgresql, etcd)
|
||||
|
||||
# stop postgresql on script exit
|
||||
|
||||
|
||||
def stop_postgresql():
|
||||
postgresql.stop()
|
||||
atexit.register(stop_postgresql)
|
||||
@@ -63,9 +69,10 @@ while True:
|
||||
|
||||
# create replication slots
|
||||
if postgresql.is_leader():
|
||||
for node in etcd.get_client_path("/members?recursive=true")["node"]["nodes"]:
|
||||
member = node["key"].split('/')[-1]
|
||||
if member != postgresql.name:
|
||||
postgresql.query("DO LANGUAGE plpgsql $$DECLARE somevar VARCHAR; BEGIN SELECT slot_name INTO somevar FROM pg_replication_slots WHERE slot_name = '%(slot)s' LIMIT 1; IF NOT FOUND THEN PERFORM pg_create_physical_replication_slot('%(slot)s'); END IF; END$$;" % {"slot": member})
|
||||
for member in etcd.members():
|
||||
if member['hostname'] != postgresql.name:
|
||||
postgresql.query("""SELECT pg_create_physical_replication_slot(%s)
|
||||
WHERE NOT EXISTS (SELECT 1 FROM pg_replication_slots
|
||||
WHERE slot_name = %s)""", member['hostname'], member['hostname'])
|
||||
|
||||
time.sleep(config["loop_wait"])
|
||||
|
||||
Reference in New Issue
Block a user