Demote immediately if failed to update leader lock (#316)

If the Etcd node partitioned from rest of the cluster it is still
possible to read from it (though it returns some stale information),
but it is not possible to write into it.
Previously Patroni was trying to fetch the new cluster view from DCS in
order to figure out is it still the leader or not and Etcd is always
returning stale info where the node still owns the leader key, but with
negative TTL.
This weird bug clearly shows how dangerous premature optimization is.
This commit is contained in:
Alexander Kukushkin
2016-09-20 15:45:21 +02:00
committed by GitHub
parent 1100136d8d
commit 7ca55359de
2 changed files with 3 additions and 2 deletions
+2 -1
View File
@@ -434,7 +434,8 @@ class Ha(object):
else:
# Either there is no connection to DCS or someone else acquired the lock
logger.error('failed to update leader lock')
self.load_cluster_from_dcs()
self.demote(delete_leader=False)
return 'demoted self because failed to update leader lock in DCS'
else:
logger.info('does not have lock')
return self.follow('demoting self because i do not have the lock and i was a leader',
+1 -1
View File
@@ -231,7 +231,7 @@ class TestHa(unittest.TestCase):
self.ha.cluster.is_unlocked = false
self.ha.has_lock = true
self.ha.update_lock = false
self.assertEquals(self.ha.run_cycle(), 'demoting self because i do not have the lock and i was a leader')
self.assertEquals(self.ha.run_cycle(), 'demoted self because failed to update leader lock in DCS')
def test_follow(self):
self.ha.cluster.is_unlocked = false