Do not add former leader to hosts

After a cold boot, the leader has likely changed. Do not add this node
as a former leader to the hosts list. This may cause changes to
mysqld.cnf and an unwanted attempted restart of mysql.

Change-Id: I5fc4b7822a4550e53e97655771938a903f92fcb1
Close-Bug: #1838648
This commit is contained in:
David Ames 2019-08-01 07:55:06 -07:00
parent 9391662e19
commit 475b889020
2 changed files with 23 additions and 1 deletions

View File

@ -560,7 +560,10 @@ def config_changed():
# Skip if cluster_series_upgrading
# Speed up cluster process by bootstrapping when the leader has
# bootstrapped if we have expected number of peers
if leader_ip not in hosts:
# However, in a cold boot scenario do not add the "old" leader
# when it matches this host.
if (leader_ip not in hosts and
leader_ip != get_cluster_host_ip()):
# Fix Bug #1738896
hosts = [leader_ip] + hosts
log("Leader is bootstrapped - configuring mysql on this node",

View File

@ -399,6 +399,7 @@ class TestConfigChanged(CharmTestCase):
'set_ready_on_peers',
'is_unit_paused_set',
'is_unit_upgrading_set',
'get_cluster_host_ip',
]
def setUp(self):
@ -545,6 +546,24 @@ class TestConfigChanged(CharmTestCase):
['10.10.10.20', '10.10.10.30', '10.10.10.10'])
self.update_bootstrap_uuid.assert_called_once()
# Bug #1838648
# Do not add *this* host as a former leader
self.get_cluster_host_ip.return_value = '10.10.10.30'
self.render_config_restart_on_changed.reset_mock()
self.update_bootstrap_uuid.reset_mock()
self.get_cluster_hosts.return_value = ['10.10.10.10', '10.10.10.20']
def _leader_get(key):
settings = {'leader-ip': '10.10.10.30',
'cluster_series_upgrading': False}
return settings.get(key)
self.leader_get.side_effect = _leader_get
hooks.config_changed()
self.render_config_restart_on_changed.assert_called_once_with(
['10.10.10.10', '10.10.10.20'])
self.update_bootstrap_uuid.assert_called_once()
# In none of the prior scenarios should update_root_password have been
# called. is_bootstrapped was defaulted to False
self.update_root_password.assert_not_called()