@@ -104,6 +104,7 @@ def unit_peer_data(self) -> Dict:
104
104
def _database_config (self ):
105
105
"""Returns the database config to use to connect to the MySQL cluster."""
106
106
data = list (self .database .fetch_relation_data ().values ())[0 ]
107
+
107
108
username , password , endpoints = (
108
109
data .get ("username" ),
109
110
data .get ("password" ),
@@ -119,7 +120,6 @@ def _database_config(self):
119
120
}
120
121
if endpoints .startswith ("file://" ):
121
122
config ["unix_socket" ] = endpoints [7 :]
122
- config ["port" ] = "socket"
123
123
else :
124
124
host , port = endpoints .split (":" )
125
125
config ["host" ] = host
@@ -138,20 +138,24 @@ def _start_continuous_writes(self, starting_number: int) -> None:
138
138
139
139
self ._stop_continuous_writes ()
140
140
141
+ command = [
142
+ "/usr/bin/python3" ,
143
+ "src/continuous_writes.py" ,
144
+ self ._database_config ["user" ],
145
+ self ._database_config ["password" ],
146
+ self ._database_config ["database" ],
147
+ CONTINUOUS_WRITE_TABLE_NAME ,
148
+ str (starting_number ),
149
+ ]
150
+
151
+ if "unix_socket" in self ._database_config :
152
+ command .append (self ._database_config ["unix_socket" ])
153
+ else :
154
+ command .append (self ._database_config ["host" ])
155
+ command .append (self ._database_config ["port" ])
156
+
141
157
# Run continuous writes in the background
142
- proc = subprocess .Popen (
143
- [
144
- "/usr/bin/python3" ,
145
- "src/continuous_writes.py" ,
146
- self ._database_config ["user" ],
147
- self ._database_config ["password" ],
148
- self ._database_config .get ("host" , self ._database_config ["unix_socket" ]),
149
- self ._database_config ["port" ],
150
- self ._database_config ["database" ],
151
- CONTINUOUS_WRITE_TABLE_NAME ,
152
- str (starting_number ),
153
- ]
154
- )
158
+ proc = subprocess .Popen (command )
155
159
156
160
# Store the continuous writes process id in stored state to be able to stop it later
157
161
self .unit_peer_data [PROC_PID_KEY ] = str (proc .pid )
@@ -270,6 +274,9 @@ def _on_stop_continuous_writes_action(self, event: ActionEvent) -> None:
270
274
271
275
def _on_database_created (self , _ ) -> None :
272
276
"""Handle the database created event."""
277
+ if not self ._database_config :
278
+ return
279
+
273
280
self ._start_continuous_writes (1 )
274
281
value = self ._write_random_value ()
275
282
if self .unit .is_leader ():
0 commit comments