@@ -240,11 +240,8 @@ def _on_config_changed(self, event: EventBase) -> None:
240240 # the upgrade already restart the daemon
241241 return
242242
243- if not self ._mysql .is_mysqld_running ():
244- # defer config-changed event until MySQL is running
245- logger .debug ("Deferring config-changed event until MySQL is running" )
246- event .defer ()
247- return
243+ # restart not required if mysqld is not running
244+ restart = self ._mysql .is_mysqld_running ()
248245
249246 previous_config = self .mysql_config .custom_config
250247 if not previous_config :
@@ -263,14 +260,15 @@ def _on_config_changed(self, event: EventBase) -> None:
263260
264261 if self .mysql_config .keys_requires_restart (changed_config ):
265262 # there are static configurations in changed keys
266- logger .info ("Configuration change requires restart" )
267-
263+ logger .info ("Persisting configuration changes to file" )
268264 # persist config to file
269265 self ._mysql .write_content_to_file (
270266 path = MYSQLD_CUSTOM_CONFIG_FILE , content = new_config_content
271267 )
272- self .on [f"{ self .restart .name } " ].acquire_lock .emit ()
273- return
268+ if restart :
269+ logger .info ("Configuration change requires restart" )
270+ self .on [f"{ self .restart .name } " ].acquire_lock .emit ()
271+ return
274272
275273 if dynamic_config := self .mysql_config .filter_static_keys (changed_config ):
276274 # if only dynamic config changed, apply it
@@ -796,6 +794,11 @@ def join_unit_to_cluster(self) -> None:
796794
797795 def _restart (self , event : EventBase ) -> None :
798796 """Restart the MySQL service."""
797+ if self .peers .units != self .restart_peers .units :
798+ # defer restart until all units are in the relation
799+ logger .debug ("Deferring restart until all units are in the relation" )
800+ event .defer ()
801+ return
799802 if self ._mysql .is_unit_primary (self .unit_label ):
800803 restart_states = {
801804 self .restart_peers .data [unit ].get ("state" , "unset" ) for unit in self .peers .units
0 commit comments