Bugfix: do not create replication slot for master

This commit is contained in:
Alexander Kukushkin
2015-06-01 09:20:24 +02:00
parent aa486194ae
commit b85262637d
4 changed files with 14 additions and 6 deletions
+1 -1
View File
@@ -20,7 +20,7 @@ class RestApiHandler(BaseHTTPRequestHandler):
try:
response = self.get_postgresql_status()
except (psycopg2.OperationalError, psycopg2.InterfaceError):
logging.exception('get_postgresql_status')
logger.exception('get_postgresql_status')
response = {'running': False}
path = '/master' if self.path == '/' else self.path
+1 -1
View File
@@ -78,7 +78,7 @@ class Ha:
return 'no action. i am the leader with the lock'
finally:
# create replication slots
self.state_handler.create_replication_slots([m.hostname for m in self.cluster.members])
self.state_handler.create_replication_slots(self.cluster)
else:
logger.info('does not have lock')
if self.state_handler.is_leader():
+2 -1
View File
@@ -247,7 +247,8 @@ primary_conninfo = '{}'
cursor = self.query("SELECT slot_name FROM pg_replication_slots WHERE slot_type='physical'")
self.members = [r[0] for r in cursor]
def create_replication_slots(self, members):
def create_replication_slots(self, cluster):
members = [m.hostname for m in cluster.members if m.hostname != self.name]
# drop unused slots
for slot in set(self.members) - set(members):
self.query("""SELECT pg_drop_replication_slot(%s)
+10 -3
View File
@@ -91,8 +91,12 @@ class TestPostgresql(unittest.TestCase):
def set_up(self):
subprocess.call = subprocess_call
self.p = Postgresql({'name': 'test0', 'data_dir': 'data/test0', 'listen': '127.0.0.1, 127.0.0.2:5432', 'connect_address': '127.0.0.2:5432', 'replication': {
'username': 'replicator', 'password': 'rep-pass', 'network': '127.0.0.1/32'}, 'parameters': {'foo': 'bar'}, 'recovery_conf': {'foo': 'bar'}})
self.p = Postgresql({'name': 'test0', 'data_dir': 'data/test0', 'listen': '127.0.0.1, 127.0.0.2:5432',
'connect_address': '127.0.0.2:5432',
'replication': {'username': 'replicator',
'password': 'rep-pass',
'network': '127.0.0.1/32'},
'parameters': {'foo': 'bar'}, 'recovery_conf': {'foo': 'bar'}})
psycopg2.connect = psycopg2_connect
if not os.path.exists(self.p.data_dir):
os.makedirs(self.p.data_dir)
@@ -127,7 +131,10 @@ class TestPostgresql(unittest.TestCase):
def test_create_replication_slots(self):
self.p.start()
self.p.create_replication_slots('qaz')
me = Member('test0', 'postgres://replicator:[email protected]:5434/postgres', 28)
other = Member('test1', 'postgres://replicator:[email protected]:5433/postgres', 28)
cluster = Cluster(True, self.leader, 0, [me, other, self.leader])
self.p.create_replication_slots(cluster)
def test_query(self):
self.p.query('select 1')