MySQL 9.0.0
Source Code Documentation
group_action_coordinator.h
Go to the documentation of this file.
1/* Copyright (c) 2018, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef GROUP_ACTION_COORDINATOR_INCLUDED
25#define GROUP_ACTION_COORDINATOR_INCLUDED
26
32
34 public:
38 bool is_local, Group_action *current_proposed_action,
42 /**
43 Provides running group action details.
44
45 @retval string Pair: Initiator details and Group action description
46 */
47
48 const std::pair<std::string, std::string> get_action_name_and_description();
49
50 /* Was it proposed locally*/
52 /* The proposed action */
54 /* The diagnostics area associated to the action */
56 /* What is the action return value */
58 /* Initiator and action details */
60};
61
62/**
63 @class Group_action_coordinator
64 The coordinator class where group actions are submitted
65*/
67 public:
68 /** Enum for the flags used in the return field of the end message */
70 END_ACTION_MESSAGE_UNKNOWN_FLAG = 0, // This type should not be used
71 END_ACTION_MESSAGE_WARNING_FLAG = 1, // The message has a warning
72 END_ACTION_MESSAGE_FLAG_END = 2, // The enum end
73 };
74
75 /**
76 The group coordinator constructor
77 @param[in] components_stop_timeout the timeout when waiting on shutdown
78 */
79 Group_action_coordinator(ulong components_stop_timeout);
80
81 /** The group coordinator destructor */
83
84 /**
85 Register the coordinator observers
86 @note Calling this method in constructors/destructors can lead to errors
87 as virtual methods are called upon an "incomplete" object.
88 */
90
91 /**
92 Unregister the coordinator observers
93 @note Calling this method in constructors/destructors can lead to errors
94 as virtual methods are called upon an "incomplete" object.
95 */
97
98 /** Submit an action for execution in the coordinator
99 @param action The action instance to execute in the group
100 @param execution_info The result information for this action execution
101 @param initiator Details of initiator and action
102
103 @return !=0 if something wrong happened in the action
104 */
108
109 /**
110 Asks the coordinator to stop any ongoing action
111 @param coordinator_stop is the coordinator terminating
112 @param wait shall it wait for the process to terminate
113 */
114 int stop_coordinator_process(bool coordinator_stop, bool wait = true);
115
116 /**
117 Resets flags as the coordinator can live through multiple stops and starts
118 */
120
121 /**
122 * Handle incoming action message (start or stop)
123 * @param message The action message pointer
124 * @param message_origin the message origin
125 * @return true if something wrong happen, false otherwise
126 */
128 const std::string &message_origin);
129
130 /**
131 Returns if there is a group action running
132
133 @param[out] initiator action name and description if running
134
135 @return true if an action is being executed
136 */
137 bool is_group_action_running(std::pair<std::string, std::string> &initiator);
138
139 /**
140 The main thread process for the action execution process
141 */
143
144 /**
145 Sets the component stop timeout.
146
147 @param[in] timeout the timeout
148 */
149 void set_stop_wait_timeout(ulong timeout);
150
151#ifndef NDEBUG
152 /**
153 Flag for cases where we don't have debug execution tools
154 Can be an enum if other cases emerge
155 */
157#endif
158
159 private:
160 // The listeners for group events
161
162 int after_view_change(const std::vector<Gcs_member_identifier> &joining,
163 const std::vector<Gcs_member_identifier> &leaving,
164 const std::vector<Gcs_member_identifier> &group,
165 bool is_leaving, bool *skip_election,
166 enum_primary_election_mode *election_mode,
167 std::string &suggested_primary) override;
169 std::string primary_uuid,
171 enum_primary_election_mode election_mode, int error) override;
173 const std::string &message_origin,
174 bool *skip_message) override;
175
176 /**
177 Handle incoming start action message
178 @param message The action message pointer
179 @param message_origin the message origin
180 @return true if something wrong happen, false otherwise
181 */
183 const std::string &message_origin);
184
185 /**
186 Handle incoming end action message
187 @param message The action message pointer
188 @param message_origin the message origin
189 @return true if something wrong happen, false otherwise
190 */
192 const std::string &message_origin);
193
194 /**
195 This method checks if there is a member in recovery in the group
196 @param all_members_info the list of info objects for all members
197 @return true if yes, false if no member is in recovery
198 */
199 bool member_in_recovery(Group_member_info_list *all_members_info);
200
201 /**
202 This method checks if there is a member from a version that does not allow
203 actions
204 @param all_members_info the list of info objects for all members
205 @return true if yes, false if all members are valid
206 */
208
209 /**
210 Set an error message and awake the coordinator
211 @param execution_info The information for the executing action
212 @param error_message the message to send to the user if local
213 @param is_local_executor are we aborting something proposed on this member
214 @param is_action_running if the action was already running
215 */
217 const char *error_message,
218 bool is_local_executor,
219 bool is_action_running = false);
220
221 /**
222 Awake the coordinator and report the error
223 @param execution_info The information for the executing action
224 @param is_local_executor are we aborting something proposed on this member
225 @param is_action_running if the action was already running
226 */
228 bool is_local_executor,
229 bool is_action_running = false);
230
231 /**
232 Declare this action as terminated to other members
233 */
235
236 //
237 /** Handle the termination of current action */
238 void terminate_action();
239
240 /**
241 Declares the action as not running, wait or not for its finish
242 @param wait wait for the execution thread to finish or not
243 */
245
246 /**
247 This method returns if the current thread was killed
248 @return true if yes, false otherwise
249 */
250 bool thread_killed();
251
252 /** The list of members known for the current action */
253 std::list<std::string> known_members_addresses;
254 /** The number of received stop messages or dead members */
256 /** The number of received stop messages or dead members */
258
259 /** The lock too coordinate start and stop requests */
261
262 /** The condition to wake up on error or termination */
264
265 /** Is this member the sender and controller of this action*/
267
268 /** The flag to avoid concurrent action start requests */
270
271 /** The flag to avoid concurrent action running */
272 std::atomic<bool> action_running;
273
274 /** The currently proposed action owner*/
276 /** The currently proposed action owner*/
278
279 /** Is the local submitted action terminating */
281
282 /** Was the local action killed */
284
285 /** Is there an error on the message after receiving the action*/
287
288 /** The flag to avoid action starts post stop */
290
291 /** If we propose an action but the coordinator ends before it starts*/
293
294 /** Is this member leaving */
296
297 /** There were remote warnings reported */
299
300 /** The handler where actions can report progress through stages */
302
303 /** launch_group_action_handler_thread */
305
306 /** The action handler thread status */
308
309 /** If the group action execution method is being executed */
311
312 /* Component stop timeout on shutdown */
314
315 // run conditions and locks
316 /** The thread handle for the group action process */
318 /** The group action process thread lock */
320 /** The group action process thread condition */
322
323 /** The group action process thread end lock */
325 /** The group action process thread end condition */
327};
328
329#endif /* GROUP_ACTION_COORDINATOR_INCLUDED */
The coordinator class where group actions are submitted.
Definition: group_action_coordinator.h:66
bool action_execution_error
Is there an error on the message after receiving the action.
Definition: group_action_coordinator.h:286
Group_action_information * current_executing_action
The currently proposed action owner.
Definition: group_action_coordinator.h:277
bool local_action_killed
Was the local action killed.
Definition: group_action_coordinator.h:283
std::list< std::string > known_members_addresses
The list of members known for the current action.
Definition: group_action_coordinator.h:253
void terminate_action()
Handle the termination of current action.
Definition: group_action_coordinator.cc:702
bool handle_action_message(Group_action_message *message, const std::string &message_origin)
Handle incoming action message (start or stop)
Definition: group_action_coordinator.cc:460
std::atomic< bool > action_running
The flag to avoid concurrent action running.
Definition: group_action_coordinator.h:272
Plugin_stage_monitor_handler monitoring_stage_handler
The handler where actions can report progress through stages.
Definition: group_action_coordinator.h:301
ulong stop_wait_timeout
Definition: group_action_coordinator.h:313
void awake_coordinator_on_error(Group_action_information *execution_info, const char *error_message, bool is_local_executor, bool is_action_running=false)
Set an error message and awake the coordinator.
Definition: group_action_coordinator.cc:756
int execute_group_action_handler()
The main thread process for the action execution process.
Definition: group_action_coordinator.cc:870
bool thread_killed()
This method returns if the current thread was killed.
Definition: group_action_coordinator.cc:456
bool action_proposed
The flag to avoid concurrent action start requests.
Definition: group_action_coordinator.h:269
void signal_and_wait_action_termination(bool wait)
Declares the action as not running, wait or not for its finish.
Definition: group_action_coordinator.cc:736
bool remote_warnings_reported
There were remote warnings reported.
Definition: group_action_coordinator.h:298
void register_coordinator_observers()
Register the coordinator observers.
Definition: group_action_coordinator.cc:196
bool handle_action_start_message(Group_action_message *message, const std::string &message_origin)
Handle incoming start action message.
Definition: group_action_coordinator.cc:490
mysql_cond_t group_thread_run_cond
The group action process thread condition.
Definition: group_action_coordinator.h:321
bool member_leaving_group
Is this member leaving.
Definition: group_action_coordinator.h:295
int coordinate_action_execution(Group_action *action, Group_action_diagnostics *execution_info, Group_action_message::enum_action_initiator_and_action initiator)
Submit an action for execution in the coordinator.
Definition: group_action_coordinator.cc:295
int signal_action_terminated()
Declare this action as terminated to other members.
Definition: group_action_coordinator.cc:802
int number_of_terminated_members
The number of received stop messages or dead members.
Definition: group_action_coordinator.h:257
bool action_cancelled_on_termination
If we propose an action but the coordinator ends before it starts.
Definition: group_action_coordinator.h:292
enum_end_action_message_return_flags
Enum for the flags used in the return field of the end message.
Definition: group_action_coordinator.h:69
@ END_ACTION_MESSAGE_UNKNOWN_FLAG
Definition: group_action_coordinator.h:70
@ END_ACTION_MESSAGE_WARNING_FLAG
Definition: group_action_coordinator.h:71
@ END_ACTION_MESSAGE_FLAG_END
Definition: group_action_coordinator.h:72
int before_message_handling(const Plugin_gcs_message &message, const std::string &message_origin, bool *skip_message) override
Executed before the message is processed.
Definition: group_action_coordinator.cc:1060
bool local_action_terminating
Is the local submitted action terminating.
Definition: group_action_coordinator.h:280
mysql_cond_t coordinator_process_condition
The condition to wake up on error or termination.
Definition: group_action_coordinator.h:263
bool member_in_recovery(Group_member_info_list *all_members_info)
This method checks if there is a member in recovery in the group.
Definition: group_action_coordinator.cc:676
mysql_mutex_t coordinator_process_lock
The lock too coordinate start and stop requests.
Definition: group_action_coordinator.h:260
Group_action_coordinator(ulong components_stop_timeout)
The group coordinator constructor.
Definition: group_action_coordinator.cc:153
int stop_coordinator_process(bool coordinator_stop, bool wait=true)
Asks the coordinator to stop any ongoing action.
Definition: group_action_coordinator.cc:252
bool is_group_action_being_executed
If the group action execution method is being executed.
Definition: group_action_coordinator.h:310
int launch_group_action_handler_thread()
launch_group_action_handler_thread
Definition: group_action_coordinator.cc:839
void set_stop_wait_timeout(ulong timeout)
Sets the component stop timeout.
Definition: group_action_coordinator.cc:204
void reset_coordinator_process()
Resets flags as the coordinator can live through multiple stops and starts.
Definition: group_action_coordinator.cc:236
bool coordinator_terminating
The flag to avoid action starts post stop.
Definition: group_action_coordinator.h:289
my_thread_handle action_execution_pthd
The thread handle for the group action process.
Definition: group_action_coordinator.h:317
bool is_sender
Is this member the sender and controller of this action.
Definition: group_action_coordinator.h:266
bool handle_action_stop_message(Group_action_message *message, const std::string &message_origin)
Handle incoming end action message.
Definition: group_action_coordinator.cc:652
void unregister_coordinator_observers()
Unregister the coordinator observers.
Definition: group_action_coordinator.cc:200
mysql_mutex_t group_thread_run_lock
The group action process thread lock.
Definition: group_action_coordinator.h:319
bool member_from_invalid_version(Group_member_info_list *all_members_info)
This method checks if there is a member from a version that does not allow actions.
Definition: group_action_coordinator.cc:689
~Group_action_coordinator() override
The group coordinator destructor
Definition: group_action_coordinator.cc:187
int number_of_known_members
The number of received stop messages or dead members.
Definition: group_action_coordinator.h:255
bool failure_debug_flag
Flag for cases where we don't have debug execution tools Can be an enum if other cases emerge.
Definition: group_action_coordinator.h:156
mysql_mutex_t group_thread_end_lock
The group action process thread end lock.
Definition: group_action_coordinator.h:324
mysql_cond_t group_thread_end_cond
The group action process thread end condition.
Definition: group_action_coordinator.h:326
thread_state action_handler_thd_state
The action handler thread status.
Definition: group_action_coordinator.h:307
bool is_group_action_running(std::pair< std::string, std::string > &initiator)
Returns if there is a group action running.
Definition: group_action_coordinator.cc:214
Group_action_information * proposed_action
The currently proposed action owner.
Definition: group_action_coordinator.h:275
int after_primary_election(std::string primary_uuid, enum_primary_election_primary_change_status primary_change_status, enum_primary_election_mode election_mode, int error) override
Executed after primary election.
Definition: group_action_coordinator.cc:1054
int after_view_change(const std::vector< Gcs_member_identifier > &joining, const std::vector< Gcs_member_identifier > &leaving, const std::vector< Gcs_member_identifier > &group, bool is_leaving, bool *skip_election, enum_primary_election_mode *election_mode, std::string &suggested_primary) override
Executed after view install and before primary election.
Definition: group_action_coordinator.cc:1017
The parent class for group wide operations.
Definition: group_action.h:35
Definition: group_action_coordinator.h:33
const std::pair< std::string, std::string > get_action_name_and_description()
Provides running group action details.
Definition: group_action_coordinator.cc:61
Group_action_message::enum_action_initiator_and_action m_action_initiator
Definition: group_action_coordinator.h:59
Group_action_information(Group_action_message::enum_action_initiator_and_action initiator)
Definition: group_action_coordinator.cc:47
Group_action::enum_action_execution_result action_result
Definition: group_action_coordinator.h:57
Group_action_diagnostics * execution_message_area
Definition: group_action_coordinator.h:55
Group_action * executing_action
Definition: group_action_coordinator.h:53
bool is_local
Definition: group_action_coordinator.h:51
Definition: group_action_message.h:33
enum_action_initiator_and_action
Enum to identify initiator and action.
Definition: group_action_message.h:81
The parent class for group wide operations.
Definition: group_action.h:139
enum_action_execution_result
Enum for the end results of a action execution.
Definition: group_action.h:142
Class that others can extend to receive notifications about views and primary elections.
Definition: group_event_observer.h:40
This is the base GCS plugin message.
Definition: gcs_plugin_messages.h:64
Definition: stage_monitor_handler.h:30
std::vector< Group_member_info *, Malloc_allocator< Group_member_info * > > Group_member_info_list
Definition: member_info.h:771
static bool timeout(bool(*wait_condition)())
Timeout function.
Definition: log0meb.cc:498
static int wait(mysql_cond_t *that, mysql_mutex_t *mutex_arg, const char *, unsigned int)
Definition: mysql_cond_v1_native.cc:63
enum_primary_election_mode
Enum for election types.
Definition: primary_election_include.h:33
enum_primary_election_primary_change_status
Enum for primary change status.
Definition: primary_election_include.h:50
repeated Action action
Definition: replication_group_member_actions.proto:43
Definition: my_thread_bits.h:58
An instrumented cond structure.
Definition: mysql_cond_bits.h:50
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50
Definition: plugin_utils.h:48