mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
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:
committed by
GitHub
parent
1100136d8d
commit
7ca55359de
+2
-1
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user