mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
Fix bug with priority failover (#3297)
We should ignor the former leader with higher priority when it reports the same LSN as the current node. This bug could be a contributing factor to issues described in #3295 In addition to that mock socket.getaddrinfo() call in test_api.py to avoid hitting DNS servers.
This commit is contained in:
@@ -18,6 +18,7 @@ from patroni.psycopg import OperationalError
|
||||
from patroni.utils import RetryFailedError, tzutc
|
||||
|
||||
from . import MockConnect, psycopg_connect
|
||||
from .test_etcd import socket_getaddrinfo
|
||||
from .test_ha import get_cluster_initialized_without_leader
|
||||
|
||||
future_restart_time = datetime.datetime.now(tzutc) + datetime.timedelta(days=5)
|
||||
@@ -711,6 +712,7 @@ class TestRestApiServer(unittest.TestCase):
|
||||
patch.object(MockRestApiServer, 'server_close', Mock()):
|
||||
self.srv.reload_config({'listen': ':8008'})
|
||||
|
||||
@patch('socket.getaddrinfo', socket_getaddrinfo)
|
||||
@patch.object(MockPatroni, 'dcs')
|
||||
def test_check_access(self, mock_dcs):
|
||||
mock_dcs.cluster = get_cluster_initialized_without_leader()
|
||||
|
||||
@@ -1076,6 +1076,9 @@ class TestHa(PostgresInit):
|
||||
# if there is a higher-priority node but it has a lower WAL position then this node should race
|
||||
self.ha.fetch_node_status = get_node_status(failover_priority=6, wal_position=9)
|
||||
self.assertTrue(self.ha._is_healthiest_node(self.ha.old_cluster.members))
|
||||
# if the old leader is a higher-priority node on the same WAL position then this node should race
|
||||
self.ha.fetch_node_status = get_node_status(failover_priority=6)
|
||||
self.assertTrue(self.ha._is_healthiest_node(self.ha.old_cluster.members, leader=self.ha.old_cluster.leader))
|
||||
self.ha.fetch_node_status = get_node_status(wal_position=11) # accessible, in_recovery, wal position ahead
|
||||
self.assertFalse(self.ha._is_healthiest_node(self.ha.old_cluster.members))
|
||||
# in synchronous_mode consider itself healthy if the former leader is accessible in read-only and ahead of us
|
||||
|
||||
Reference in New Issue
Block a user