@@ -29,7 +29,7 @@ static void *launch_handler_thread(void* arg)
29
29
}
30
30
31
31
Delayed_initialization_thread::Delayed_initialization_thread ()
32
- : thread_running(false ), is_server_ready(false )
32
+ : thread_running(false ), is_server_ready(false ), is_super_read_only_set( false )
33
33
{
34
34
mysql_mutex_init (key_GR_LOCK_delayed_init_run, &run_lock, MY_MUTEX_INIT_FAST);
35
35
mysql_mutex_init (key_GR_LOCK_delayed_init_server_ready,
@@ -61,14 +61,14 @@ void Delayed_initialization_thread::signal_thread_ready()
61
61
DBUG_VOID_RETURN;
62
62
}
63
63
64
- void Delayed_initialization_thread::wait_for_initialization ()
64
+ void Delayed_initialization_thread::wait_for_thread_end ()
65
65
{
66
- DBUG_ENTER (" Delayed_initialization_thread::wait_for_initialization " );
66
+ DBUG_ENTER (" Delayed_initialization_thread::wait_for_thread_end " );
67
67
68
68
mysql_mutex_lock (&run_lock);
69
69
while (thread_running)
70
70
{
71
- DBUG_PRINT (" sleep" ,(" Waiting for the Delayed initialization thread to end " ));
71
+ DBUG_PRINT (" sleep" ,(" Waiting for the Delayed initialization thread to finish " ));
72
72
mysql_cond_wait (&run_cond, &run_lock);
73
73
}
74
74
mysql_mutex_unlock (&run_lock);
@@ -79,6 +79,33 @@ void Delayed_initialization_thread::wait_for_initialization()
79
79
DBUG_VOID_RETURN;
80
80
}
81
81
82
+ void Delayed_initialization_thread::signal_read_mode_ready ()
83
+ {
84
+ DBUG_ENTER (" Delayed_initialization_thread::signal_read_mode_ready" );
85
+
86
+ mysql_mutex_lock (&run_lock);
87
+ is_super_read_only_set= true ;
88
+ mysql_cond_broadcast (&run_cond);
89
+ mysql_mutex_unlock (&run_lock);
90
+
91
+ DBUG_VOID_RETURN;
92
+ }
93
+
94
+ void Delayed_initialization_thread::wait_for_read_mode ()
95
+ {
96
+ DBUG_ENTER (" Delayed_initialization_thread::wait_for_read_mode" );
97
+
98
+ mysql_mutex_lock (&run_lock);
99
+ while (!is_super_read_only_set)
100
+ {
101
+ DBUG_PRINT (" sleep" ,(" Waiting for the Delayed initialization thread to set super_read_only" ));
102
+ mysql_cond_wait (&run_cond, &run_lock);
103
+ }
104
+ mysql_mutex_unlock (&run_lock);
105
+
106
+ DBUG_VOID_RETURN;
107
+ }
108
+
82
109
int Delayed_initialization_thread::launch_initialization_thread ()
83
110
{
84
111
DBUG_ENTER (" Delayed_initialization_thread::launch_initialization_thread" );
@@ -128,158 +155,12 @@ int Delayed_initialization_thread::initialization_thread_handler()
128
155
}
129
156
mysql_mutex_unlock (&server_ready_lock);
130
157
131
- // delayed initialization code starts here
132
-
133
- int error= 0 ;
134
- Sql_service_command_interface *sql_command_interface= NULL ;
135
-
136
- // Just terminate it
137
- if (!wait_on_engine_initialization ||
138
- get_plugin_pointer () == NULL )
139
- {
140
- goto end;
141
- }
142
-
143
- /*
144
- The plugin was initialized on server start
145
- so only now we can start the applier
146
- */
147
- if (wait_on_engine_initialization)
148
- {
149
- DBUG_ASSERT (server_engine_initialized ());
150
- wait_on_engine_initialization= false ;
151
-
152
- // Avoid unnecessary operations
153
- bool enabled_super_read_only= false ;
154
- bool read_only_mode= false , super_read_only_mode=false ;
155
-
156
- char *hostname, *uuid;
157
- uint port;
158
- unsigned int server_version;
159
- st_server_ssl_variables server_ssl_variables=
160
- {false ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL };
161
-
162
- get_server_parameters (&hostname, &port, &uuid, &server_version,
163
- &server_ssl_variables);
164
-
165
- sql_command_interface= new Sql_service_command_interface ();
166
- if (sql_command_interface->
167
- establish_session_connection (PSESSION_INIT_THREAD,
168
- get_plugin_pointer ()) ||
169
- sql_command_interface->set_interface_user (GROUPREPL_USER))
170
- {
171
- /* purecov: begin inspected */
172
- log_message (MY_ERROR_LEVEL,
173
- " It was not possible to establish a connection to "
174
- " server SQL service" );
175
- error= 1 ;
176
- goto err;
177
- /* purecov: end */
178
- }
179
-
180
- /*
181
- At this point in the code, set the super_read_only mode here on the
182
- server to protect recovery and version module of the Group Replication.
183
-
184
- Save the current read mode state to restore it in case Group Replication
185
- fail to start.
186
- */
187
-
188
- get_read_mode_state (sql_command_interface, &read_only_mode,
189
- &super_read_only_mode);
190
-
191
- if (enable_super_read_only_mode (sql_command_interface))
192
- {
193
- error =1 ; /* purecov: inspected */
194
- log_message (MY_ERROR_LEVEL,
195
- " Could not enable the server read only mode and guarantee a "
196
- " safe recovery execution" ); /* purecov: inspected */
197
- goto err; /* purecov: inspected */
198
- }
199
-
200
- enabled_super_read_only= true ;
201
-
202
- if ((error= configure_group_communication (&server_ssl_variables)))
203
- goto err; /* purecov: inspected */
204
-
205
- if ((error= configure_group_member_manager (hostname, uuid, port,
206
- server_version)))
207
- goto err; /* purecov: inspected */
208
-
209
- if (check_async_channel_running_on_secondary ())
210
- {
211
- error= 1 ;
212
- log_message (MY_ERROR_LEVEL, " Can't start group replication on secondary"
213
- " member with single primary-mode while"
214
- " asynchronous replication channels are"
215
- " running." );
216
- goto err; /* purecov: inspected */
217
- }
218
-
219
- configure_compatibility_manager ();
220
-
221
- // need to be initialized before applier, is called on kill_pending_transactions
222
- blocked_transaction_handler= new Blocked_transaction_handler ();
223
-
224
- if ((error= initialize_recovery_module ()))
225
- goto err; /* purecov: inspected */
226
-
227
- if (configure_and_start_applier_module ())
228
- {
229
- error= GROUP_REPLICATION_REPLICATION_APPLIER_INIT_ERROR;
230
- goto err;
231
- }
232
-
233
- initialize_asynchronous_channels_observer ();
234
- initialize_group_partition_handler ();
235
-
236
- if ((error= start_group_communication ()))
237
- {
238
- // terminate the before created pipeline
239
- log_message (MY_ERROR_LEVEL,
240
- " Error on group communication initialization methods, "
241
- " killing the Group Replication applier" ); /* purecov: inspected */
242
- applier_module->terminate_applier_thread (); /* purecov: inspected */
243
- goto err; /* purecov: inspected */
244
- }
245
-
246
- if (view_change_notifier->wait_for_view_modification ())
247
- {
248
- /* purecov: begin inspected */
249
- if (!view_change_notifier->is_cancelled ())
250
- {
251
- // Only log a error when a view modification was not canceled.
252
- log_message (MY_ERROR_LEVEL,
253
- " Timeout on wait for view after joining group" );
254
- }
255
- error= view_change_notifier->get_error ();
256
- goto err;
257
- /* purecov: end */
258
- }
259
- declare_plugin_running (); // All is OK
260
-
261
- err:
262
- if (error)
263
- {
264
- leave_group ();
265
- terminate_plugin_modules ();
266
- if (!server_shutdown_status && server_engine_initialized ()
267
- && enabled_super_read_only)
268
- {
269
- set_read_mode_state (sql_command_interface, read_only_mode,
270
- super_read_only_mode);
271
- }
272
- if (certification_latch != NULL )
273
- {
274
- delete certification_latch; /* purecov: inspected */
275
- certification_latch= NULL ; /* purecov: inspected */
276
- }
277
- }
278
- }
158
+ DBUG_ASSERT (server_engine_initialized ());
279
159
280
- end:
160
+ // Protect this delayed start against other start/stop requests
161
+ Mutex_autolock auto_lock_mutex (get_plugin_running_lock ());
281
162
282
- delete sql_command_interface ;
163
+ int error= initialize_plugin_and_join (PSESSION_INIT_THREAD, this ) ;
283
164
284
165
mysql_mutex_lock (&run_lock);
285
166
thread_running= false ;
0 commit comments