Skip to content

Commit

Permalink
Do not raise an exception on last_leader_operation.
Browse files Browse the repository at this point in the history
If patroni is attached to an already running instance,
the load_cluster during its initial run_cycle will return
Nones for DCS key values, but those values will actually
be examined in the function that checks for the healthiest node.

Fix the issue by making that function handle None values correctly,
and by making sure that even on the first we load some meaningful
values from DCS by touching the member key there first (which would
also create the whole /service/cluster_name directory if it's not there).
  • Loading branch information
alexeyklyukin committed Oct 14, 2015
1 parent 7b07906 commit d2794fa
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
3 changes: 1 addition & 2 deletions patroni/ha.py
Expand Up @@ -352,10 +352,9 @@ def handle_long_action_in_progress(self):

def _run_cycle(self):
try:
self.touch_member() # also creates /service/cluster key if necessary, preventing exception on the next line
self.load_cluster_from_dcs()

self.touch_member()

# cluster has leader key but not initialize key
if not self.cluster.is_unlocked() and not self.cluster.initialize:
self.dcs.initialize() # fix it
Expand Down
3 changes: 2 additions & 1 deletion patroni/postgresql.py
Expand Up @@ -316,7 +316,8 @@ def is_healthy(self):
return True

def check_replication_lag(self, last_leader_operation):
return last_leader_operation - self.xlog_position() <= self.config.get('maximum_lag_on_failover', 0)
return (last_leader_operation if last_leader_operation else 0) -\
self.xlog_position() <= self.config.get('maximum_lag_on_failover', 0)

def write_pg_hba(self):
with open(os.path.join(self.data_dir, 'pg_hba.conf'), 'a') as f:
Expand Down

0 comments on commit d2794fa

Please sign in to comment.