@@ -240,11 +240,8 @@ def _on_config_changed(self, event: EventBase) -> None:
240
240
# the upgrade already restart the daemon
241
241
return
242
242
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 ()
248
245
249
246
previous_config = self .mysql_config .custom_config
250
247
if not previous_config :
@@ -263,14 +260,15 @@ def _on_config_changed(self, event: EventBase) -> None:
263
260
264
261
if self .mysql_config .keys_requires_restart (changed_config ):
265
262
# there are static configurations in changed keys
266
- logger .info ("Configuration change requires restart" )
267
-
263
+ logger .info ("Persisting configuration changes to file" )
268
264
# persist config to file
269
265
self ._mysql .write_content_to_file (
270
266
path = MYSQLD_CUSTOM_CONFIG_FILE , content = new_config_content
271
267
)
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
274
272
275
273
if dynamic_config := self .mysql_config .filter_static_keys (changed_config ):
276
274
# if only dynamic config changed, apply it
@@ -796,6 +794,11 @@ def join_unit_to_cluster(self) -> None:
796
794
797
795
def _restart (self , event : EventBase ) -> None :
798
796
"""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
799
802
if self ._mysql .is_unit_primary (self .unit_label ):
800
803
restart_states = {
801
804
self .restart_peers .data [unit ].get ("state" , "unset" ) for unit in self .peers .units
0 commit comments