Skip to content

Commit

Permalink
more readable pgpooler status calls
Browse files Browse the repository at this point in the history
  • Loading branch information
munakoiso committed Nov 23, 2023
1 parent 97180ab commit cfef210
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ def startup_checks(self):
sys.exit(1)

if self.db.is_alive() and not self.zk.is_alive():
if self.db.role == 'primary' and self.db.pgpooler('status')[1]:
_, pooler_service_running = self.db.pgpooler('status')
if self.db.role == 'primary' and pooler_service_running:
self.db.pgpooler('stop')

if not self.db.is_alive() and self.zk.is_alive():
Expand Down Expand Up @@ -340,12 +341,12 @@ def single_node_primary_iter(self, db_state, zk_state):

self.zk.write(self.zk.TIMELINE_INFO_PATH, db_state['timeline'])

pooler_status, pooler_service_status = self.db.pgpooler('status')
if pooler_service_status and not pooler_status:
pooler_port_available, pooler_service_running = self.db.pgpooler('status')
if pooler_service_running and not pooler_port_available:
logging.warning('Service alive, but pooler not accepting connections, restarting.')
self.db.pgpooler('stop')
self.db.pgpooler('start')
elif not pooler_service_status:
elif not pooler_service_running:
logging.debug('Here we should open for load.')
self.db.pgpooler('start')

Expand Down Expand Up @@ -417,12 +418,12 @@ def primary_iter(self, db_state, zk_state):

self._drop_stale_switchover(db_state)

pooler_status, pooler_service_status = self.db.pgpooler('status')
if pooler_service_status and not pooler_status:
pooler_port_available, pooler_service_running = self.db.pgpooler('status')
if pooler_service_running and not pooler_port_available:
logging.warning('Service alive, but pooler not accepting connections, restarting.')
self.db.pgpooler('stop')
self.db.pgpooler('start')
elif not pooler_service_status:
elif not pooler_service_running:
logging.debug('Here we should open for load.')
self.db.pgpooler('start')

Expand Down Expand Up @@ -549,7 +550,8 @@ def remove_stale_operation(self, hostname):

def start_pooler(self):
start_pooler = self.config.getboolean('replica', 'start_pooler')
if not self.db.pgpooler('status')[1] and start_pooler:
_, pooler_service_running = self.db.pgpooler('status')
if not pooler_service_running and start_pooler:
self.db.pgpooler('start')

def get_replics_info(self, zk_state):
Expand Down

0 comments on commit cfef210

Please sign in to comment.