Skip to content

Commit

Permalink
defer on restart and bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
paulomach committed Oct 11, 2023
1 parent 79829e3 commit 740b58e
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def _on_config_changed(self, event: EventBase) -> None:
# the upgrade already restart the daemon
return

if not self._mysql.is_mysqld_running:
if not self._mysql.is_mysqld_running():
# defer config-changed event until MySQL is running
logger.debug("Deferring config-changed event until MySQL is running")
event.defer()
Expand All @@ -247,17 +247,6 @@ def _on_config_changed(self, event: EventBase) -> None:
# there are static configurations in changed keys
logger.info("Configuration change requires restart")

if self._mysql.is_unit_primary(self.unit_label):
restart_states = {
self.restart_peers.data[unit].get("state", "unset")
for unit in self.peers.units
}
if restart_states != {"release"}:
# Wait other units restart first to minimize primary switchover
logger.debug("Primary is waiting for other units to restart")
event.defer()
return

# persist config to file
self._mysql.write_content_to_file(
path=MYSQLD_CUSTOM_CONFIG_FILE, content=new_config_content
Expand Down Expand Up @@ -773,8 +762,18 @@ def _join_unit_to_cluster(self) -> None:
self.unit.status = WaitingStatus("waiting to join the cluster")
logger.debug("Waiting to joing the cluster, failed to acquire lock.")

def _restart(self, _: EventBase) -> None:
def _restart(self, event: EventBase) -> None:
"""Restart the MySQL service."""
if self._mysql.is_unit_primary(self.unit_label):
restart_states = {
self.restart_peers.data[unit].get("state", "unset") for unit in self.peers.units
}
if restart_states != {"release"}:
# Wait other units restart first to minimize primary switchover
logger.debug("Primary is waiting for other units to restart")
event.defer()
return

self.unit.status = MaintenanceStatus("restarting MySQL")
self._mysql.restart_mysqld()
self.unit.status = ActiveStatus(self.active_status_message)
Expand Down

0 comments on commit 740b58e

Please sign in to comment.