MySQL 8.0.40
Source Code Documentation
|
The coordinator class where group actions are submitted. More...
#include <group_action_coordinator.h>
Public Types | |
enum | enum_end_action_message_return_flags { END_ACTION_MESSAGE_UNKNOWN_FLAG = 0 , END_ACTION_MESSAGE_WARNING_FLAG = 1 , END_ACTION_MESSAGE_FLAG_END = 2 } |
Enum for the flags used in the return field of the end message. More... | |
Public Member Functions | |
Group_action_coordinator (ulong components_stop_timeout) | |
The group coordinator constructor. More... | |
~Group_action_coordinator () override | |
The group coordinator destructor More... | |
void | register_coordinator_observers () |
Register the coordinator observers. More... | |
void | unregister_coordinator_observers () |
Unregister the coordinator observers. More... | |
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. More... | |
int | stop_coordinator_process (bool coordinator_stop, bool wait=true) |
Asks the coordinator to stop any ongoing action. More... | |
void | reset_coordinator_process () |
Resets flags as the coordinator can live through multiple stops and starts. More... | |
bool | handle_action_message (Group_action_message *message, const std::string &message_origin) |
Handle incoming action message (start or stop) More... | |
bool | is_group_action_running (std::pair< std::string, std::string > &initiator) |
Returns if there is a group action running. More... | |
int | execute_group_action_handler () |
The main thread process for the action execution process. More... | |
void | set_stop_wait_timeout (ulong timeout) |
Sets the component stop timeout. More... | |
Public Member Functions inherited from Group_event_observer | |
virtual | ~Group_event_observer ()=0 |
Public Attributes | |
bool | failure_debug_flag |
Flag for cases where we don't have debug execution tools Can be an enum if other cases emerge. More... | |
Private Member Functions | |
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. More... | |
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. More... | |
int | before_message_handling (const Plugin_gcs_message &message, const std::string &message_origin, bool *skip_message) override |
Executed before the message is processed. More... | |
bool | handle_action_start_message (Group_action_message *message, const std::string &message_origin) |
Handle incoming start action message. More... | |
bool | handle_action_stop_message (Group_action_message *message, const std::string &message_origin) |
Handle incoming end action message. More... | |
bool | member_in_recovery (Group_member_info_list *all_members_info) |
This method checks if there is a member in recovery in the group. More... | |
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. More... | |
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. More... | |
void | awake_coordinator_on_error (Group_action_information *execution_info, bool is_local_executor, bool is_action_running=false) |
Awake the coordinator and report the error. More... | |
int | signal_action_terminated () |
Declare this action as terminated to other members. More... | |
void | terminate_action () |
Handle the termination of current action. More... | |
void | signal_and_wait_action_termination (bool wait) |
Declares the action as not running, wait or not for its finish. More... | |
bool | thread_killed () |
This method returns if the current thread was killed. More... | |
int | launch_group_action_handler_thread () |
launch_group_action_handler_thread More... | |
Private Attributes | |
std::list< std::string > | known_members_addresses |
The list of members known for the current action. More... | |
int | number_of_known_members |
The number of received stop messages or dead members. More... | |
int | number_of_terminated_members |
The number of received stop messages or dead members. More... | |
mysql_mutex_t | coordinator_process_lock |
The lock too coordinate start and stop requests. More... | |
mysql_cond_t | coordinator_process_condition |
The condition to wake up on error or termination. More... | |
bool | is_sender |
Is this member the sender and controller of this action. More... | |
bool | action_proposed |
The flag to avoid concurrent action start requests. More... | |
std::atomic< bool > | action_running |
The flag to avoid concurrent action running. More... | |
Group_action_information * | proposed_action |
The currently proposed action owner. More... | |
Group_action_information * | current_executing_action |
The currently proposed action owner. More... | |
bool | local_action_terminating |
Is the local submitted action terminating. More... | |
bool | local_action_killed |
Was the local action killed. More... | |
bool | action_execution_error |
Is there an error on the message after receiving the action. More... | |
bool | coordinator_terminating |
The flag to avoid action starts post stop. More... | |
bool | action_cancelled_on_termination |
If we propose an action but the coordinator ends before it starts. More... | |
bool | member_leaving_group |
Is this member leaving. More... | |
bool | remote_warnings_reported |
There were remote warnings reported. More... | |
Plugin_stage_monitor_handler | monitoring_stage_handler |
The handler where actions can report progress through stages. More... | |
thread_state | action_handler_thd_state |
The action handler thread status. More... | |
bool | is_group_action_being_executed |
If the group action execution method is being executed. More... | |
ulong | stop_wait_timeout |
my_thread_handle | action_execution_pthd |
The thread handle for the group action process. More... | |
mysql_mutex_t | group_thread_run_lock |
The group action process thread lock. More... | |
mysql_cond_t | group_thread_run_cond |
The group action process thread condition. More... | |
mysql_mutex_t | group_thread_end_lock |
The group action process thread end lock. More... | |
mysql_cond_t | group_thread_end_cond |
The group action process thread end condition. More... | |
The coordinator class where group actions are submitted.
Group_action_coordinator::Group_action_coordinator | ( | ulong | components_stop_timeout | ) |
The group coordinator constructor.
The 'action' / 'action information' object life cycle:
[in] | components_stop_timeout | the timeout when waiting on shutdown |
The action comes from the coordinate_action_execution. It is set as current_proposed_action and only when the start message is received we decide if it is accepted or not.
If accepted, the current_executing_action is set to the proposed action.
Some notes on current_executing_action. 1) It is set on the handle_action_start_message. There is no lock, we just ensure it is set before the action_running is set to true. 2) It is deleted under the coordinator_process_lock on terminate_action or awake_coordinator_on_error If it was proposed locally the code proposing the action will delete the object on coordinate_action_execution. 3) All accesses are under the execution of the said action on the thread, or on the coordination or stop methods, were we use the coordinator_process_lock
Action_running the flag:
Since it is accessed in multiple places and contexts we use an atomic value
The base of the flag is that in GCS invoked methods it is set to true on handle_action_start_message (Gcs logical moment) set to false on terminate_action (Gcs logical moment)
On critical action errors it can be set to false on awake_coordinator_on_error. This usually means the member will leave the group or the coordinator is stopping, meaning new actions won't be accepted or processed since the member left.
There is a wait based on this variable in the execute_group_action_handler but for that reason we have the group_thread_end_lock.
current_executing_action checks the variable in a optimistic to ensure a fail fast code path. It is also used to check if we should stop an action when the query is killed. For this we first set local_action_killed to ensure that start will fail when receives the action, and then we try to stop the action if it is already running.
The stop_coordinator_process works on the same approach, it checks if the an action is running the but coordinator_terminating flag is set first, so if we miss the action start, it will fail due to the flag.
|
override |
The group coordinator destructor
|
overrideprivatevirtual |
Executed after primary election.
primary_uuid | the elected primary |
primary_change_status | if the primary changed after the election |
election_mode | what was the election mode |
error | if there was and error on the process |
Implements Group_event_observer.
|
overrideprivatevirtual |
Executed after view install and before primary election.
joining | members joining the group | |
leaving | members leaving the group | |
group | members in the group | |
is_leaving | is the member leaving | |
[out] | skip_election | skip primary election on view |
[out] | election_mode | election mode |
[out] | suggested_primary | what should be the next primary to elect |
Implements Group_event_observer.
|
private |
Awake the coordinator and report the error.
execution_info | The information for the executing action |
is_local_executor | are we aborting something proposed on this member |
is_action_running | if the action was already running |
|
private |
Set an error message and awake the coordinator.
execution_info | The information for the executing action |
error_message | the message to send to the user if local |
is_local_executor | are we aborting something proposed on this member |
is_action_running | if the action was already running |
|
overrideprivatevirtual |
Executed before the message is processed.
message | The GCS message | |
message_origin | The member that sent this message (address) | |
[out] | skip_message | skip message handling if true |
Implements Group_event_observer.
int Group_action_coordinator::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.
action | The action instance to execute in the group |
execution_info | The result information for this action execution |
initiator | Details of initiator and action |
int Group_action_coordinator::execute_group_action_handler | ( | ) |
The main thread process for the action execution process.
Did the action terminate locally but not remotely? Just add a warning and return.
bool Group_action_coordinator::handle_action_message | ( | Group_action_message * | message, |
const std::string & | message_origin | ||
) |
Handle incoming action message (start or stop)
message | The action message pointer |
message_origin | the message origin |
|
private |
Handle incoming start action message.
message | The action message pointer |
message_origin | the message origin |
Double check for termination /killing request in case the code sees action_running as being false
|
private |
Handle incoming end action message.
message | The action message pointer |
message_origin | the message origin |
bool Group_action_coordinator::is_group_action_running | ( | std::pair< std::string, std::string > & | initiator | ) |
Returns if there is a group action running.
[out] | initiator | action name and description if running |
|
private |
launch_group_action_handler_thread
|
private |
This method checks if there is a member from a version that does not allow actions.
all_members_info | the list of info objects for all members |
|
private |
This method checks if there is a member in recovery in the group.
all_members_info | the list of info objects for all members |
void Group_action_coordinator::register_coordinator_observers | ( | ) |
Register the coordinator observers.
void Group_action_coordinator::reset_coordinator_process | ( | ) |
Resets flags as the coordinator can live through multiple stops and starts.
void Group_action_coordinator::set_stop_wait_timeout | ( | ulong | timeout | ) |
Sets the component stop timeout.
[in] | timeout | the timeout |
|
private |
Declare this action as terminated to other members.
|
private |
Declares the action as not running, wait or not for its finish.
wait | wait for the execution thread to finish or not |
int Group_action_coordinator::stop_coordinator_process | ( | bool | coordinator_stop, |
bool | wait = true |
||
) |
Asks the coordinator to stop any ongoing action.
coordinator_stop | is the coordinator terminating |
wait | shall it wait for the process to terminate |
If we sent a start message but then left the group, the action might be waiting
Either the action will end and will see the coordinator stop flag, or we wake it up in here
|
private |
Handle the termination of current action.
|
private |
This method returns if the current thread was killed.
void Group_action_coordinator::unregister_coordinator_observers | ( | ) |
Unregister the coordinator observers.
|
private |
If we propose an action but the coordinator ends before it starts.
|
private |
Is there an error on the message after receiving the action.
|
private |
The thread handle for the group action process.
|
private |
The action handler thread status.
|
private |
The flag to avoid concurrent action start requests.
|
private |
The flag to avoid concurrent action running.
|
private |
The condition to wake up on error or termination.
|
private |
The lock too coordinate start and stop requests.
|
private |
The flag to avoid action starts post stop.
|
private |
The currently proposed action owner.
bool Group_action_coordinator::failure_debug_flag |
Flag for cases where we don't have debug execution tools Can be an enum if other cases emerge.
|
private |
The group action process thread end condition.
|
private |
The group action process thread end lock.
|
private |
The group action process thread condition.
|
private |
The group action process thread lock.
|
private |
If the group action execution method is being executed.
|
private |
Is this member the sender and controller of this action.
|
private |
The list of members known for the current action.
|
private |
Was the local action killed.
|
private |
Is the local submitted action terminating.
|
private |
Is this member leaving.
|
private |
The handler where actions can report progress through stages.
|
private |
The number of received stop messages or dead members.
|
private |
The number of received stop messages or dead members.
|
private |
The currently proposed action owner.
|
private |
There were remote warnings reported.
|
private |