MySQL  8.0.19
Source Code Documentation
Group_action_coordinator Class Reference

#include <group_action_coordinator.h>

Inheritance diagram for Group_action_coordinator:
Group_event_observer

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 ()
 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)
 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 trough 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 ()
 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

virtual 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)
 Executed after view install and before primary election. More...
 
virtual int after_primary_election (std::string primary_uuid, bool primary_changed, enum_primary_election_mode election_mode, int error)
 Executed after primary election. More...
 
virtual int before_message_handling (const Plugin_gcs_message &message, const std::string &message_origin, bool *skip_message)
 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 (std::vector< Group_member_info * > *all_members_info)
 This method checks if there is a member in recovery in the group. More...
 
bool member_from_invalid_version (std::vector< Group_member_info * > *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< boolaction_running
 The flag to avoid concurrent action running. More...
 
Group_action_informationproposed_action
 The currently proposed action owner. More...
 
Group_action_informationcurrent_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...
 

Detailed Description

The coordinator class where group actions are submitted

Member Enumeration Documentation

◆ enum_end_action_message_return_flags

Enum for the flags used in the return field of the end message.

Enumerator
END_ACTION_MESSAGE_UNKNOWN_FLAG 
END_ACTION_MESSAGE_WARNING_FLAG 
END_ACTION_MESSAGE_FLAG_END 

Constructor & Destructor Documentation

◆ Group_action_coordinator()

Group_action_coordinator::Group_action_coordinator ( ulong  components_stop_timeout)

The group coordinator constructor.

The 'action' / 'action information' object life cycle:

Parameters
[in]components_stop_timeoutthe 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 wont 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.

◆ ~Group_action_coordinator()

Group_action_coordinator::~Group_action_coordinator ( )

The group coordinator destructor

Member Function Documentation

◆ after_primary_election()

int Group_action_coordinator::after_primary_election ( std::string  primary_uuid,
bool  primary_changed,
enum_primary_election_mode  election_mode,
int  error 
)
privatevirtual

Executed after primary election.

Parameters
primary_uuidthe elected primary
primary_changedif the primary changed after the election
election_modewhat was the election mode
errorif there was and error on the process

Implements Group_event_observer.

◆ after_view_change()

int Group_action_coordinator::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 
)
privatevirtual

Executed after view install and before primary election.

Parameters
joiningmembers joining the group
leavingmembers leaving the group
groupmembers in the group
is_leavingis the member leaving
[out]skip_electionskip primary election on view
[out]election_modeelection mode
[out]suggested_primarywhat should be the next primary to elect

Implements Group_event_observer.

◆ awake_coordinator_on_error() [1/2]

void Group_action_coordinator::awake_coordinator_on_error ( Group_action_information execution_info,
bool  is_local_executor,
bool  is_action_running = false 
)
private

Awake the coordinator and report the error.

Parameters
execution_infoThe information for the executing action
is_local_executorare we aborting something proposed on this member
is_action_runningif the action was already running

◆ awake_coordinator_on_error() [2/2]

void Group_action_coordinator::awake_coordinator_on_error ( Group_action_information execution_info,
const char *  error_message,
bool  is_local_executor,
bool  is_action_running = false 
)
private

Set an error message and awake the coordinator.

Parameters
execution_infoThe information for the executing action
error_messagethe message to send to the user if local
is_local_executorare we aborting something proposed on this member
is_action_runningif the action was already running

◆ before_message_handling()

int Group_action_coordinator::before_message_handling ( const Plugin_gcs_message message,
const std::string &  message_origin,
bool skip_message 
)
privatevirtual

Executed before the message is processed.

Parameters
messageThe GCS message
message_originThe member that sent this message (address)
[out]skip_messageskip message handling if true

Implements Group_event_observer.

◆ coordinate_action_execution()

int Group_action_coordinator::coordinate_action_execution ( Group_action action,
Group_action_diagnostics execution_info 
)

Submit an action for execution in the coordinator.

Parameters
actionThe action instance to execute in the group
execution_infoThe result information for this action execution
Returns
!=0 if something wrong happened in the action

◆ execute_group_action_handler()

int Group_action_coordinator::execute_group_action_handler ( )

The main thread process for the action execution process.

Returns

Did the action terminate locally but not remotely? Just add a warning and return.

◆ handle_action_message()

bool Group_action_coordinator::handle_action_message ( Group_action_message message,
const std::string &  message_origin 
)

Handle incoming action message (start or stop)

Parameters
messageThe action message pointer
message_originthe message origin
Returns
true if something wrong happen, false otherwise

◆ handle_action_start_message()

bool Group_action_coordinator::handle_action_start_message ( Group_action_message message,
const std::string &  message_origin 
)
private

Handle incoming start action message.

Parameters
messageThe action message pointer
message_originthe message origin
Returns
true if something wrong happen, false otherwise

Double check for termination /killing request in case the code sees action_running as being false

◆ handle_action_stop_message()

bool Group_action_coordinator::handle_action_stop_message ( Group_action_message message,
const std::string &  message_origin 
)
private

Handle incoming end action message.

Parameters
messageThe action message pointer
message_originthe message origin
Returns
true if something wrong happen, false otherwise

◆ is_group_action_running()

bool Group_action_coordinator::is_group_action_running ( )

Returns if there is a group action running.

Returns
true if an action is being executed

◆ launch_group_action_handler_thread()

int Group_action_coordinator::launch_group_action_handler_thread ( )
private

launch_group_action_handler_thread

◆ member_from_invalid_version()

bool Group_action_coordinator::member_from_invalid_version ( std::vector< Group_member_info * > *  all_members_info)
private

This method checks if there is a member from a version that does not allow actions.

Parameters
all_members_infothe list of info objects for all members
Returns
true if yes, false if all members are valid

◆ member_in_recovery()

bool Group_action_coordinator::member_in_recovery ( std::vector< Group_member_info * > *  all_members_info)
private

This method checks if there is a member in recovery in the group.

Parameters
all_members_infothe list of info objects for all members
Returns
true if yes, false if no member is in recovery

◆ register_coordinator_observers()

void Group_action_coordinator::register_coordinator_observers ( )

Register the coordinator observers.

Note
Calling this method in constructors/destructors can lead to errors as virtual methods are called upon an "incomplete" object.

◆ reset_coordinator_process()

void Group_action_coordinator::reset_coordinator_process ( )

Resets flags as the coordinator can live trough multiple stops and starts.

◆ set_stop_wait_timeout()

void Group_action_coordinator::set_stop_wait_timeout ( ulong  timeout)

Sets the component stop timeout.

Parameters
[in]timeoutthe timeout

◆ signal_action_terminated()

int Group_action_coordinator::signal_action_terminated ( )
private

Declare this action as terminated to other members.

◆ signal_and_wait_action_termination()

void Group_action_coordinator::signal_and_wait_action_termination ( bool  wait)
private

Declares the action as not running, wait or not for its finish.

Parameters
waitwait for the execution thread to finish or not

◆ stop_coordinator_process()

int Group_action_coordinator::stop_coordinator_process ( bool  coordinator_stop,
bool  wait = true 
)

Asks the coordinator to stop any ongoing action.

Parameters
coordinator_stopis the coordinator terminating
waitshall 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

◆ terminate_action()

void Group_action_coordinator::terminate_action ( )
private

Handle the termination of current action.

◆ thread_killed()

bool Group_action_coordinator::thread_killed ( )
private

This method returns if the current thread was killed.

Returns
true if yes, false otherwise

◆ unregister_coordinator_observers()

void Group_action_coordinator::unregister_coordinator_observers ( )

Unregister the coordinator observers.

Note
Calling this method in constructors/destructors can lead to errors as virtual methods are called upon an "incomplete" object.

Member Data Documentation

◆ action_cancelled_on_termination

bool Group_action_coordinator::action_cancelled_on_termination
private

If we propose an action but the coordinator ends before it starts.

◆ action_execution_error

bool Group_action_coordinator::action_execution_error
private

Is there an error on the message after receiving the action.

◆ action_execution_pthd

my_thread_handle Group_action_coordinator::action_execution_pthd
private

The thread handle for the group action process.

◆ action_handler_thd_state

thread_state Group_action_coordinator::action_handler_thd_state
private

The action handler thread status.

◆ action_proposed

bool Group_action_coordinator::action_proposed
private

The flag to avoid concurrent action start requests.

◆ action_running

std::atomic<bool> Group_action_coordinator::action_running
private

The flag to avoid concurrent action running.

◆ coordinator_process_condition

mysql_cond_t Group_action_coordinator::coordinator_process_condition
private

The condition to wake up on error or termination.

◆ coordinator_process_lock

mysql_mutex_t Group_action_coordinator::coordinator_process_lock
private

The lock too coordinate start and stop requests.

◆ coordinator_terminating

bool Group_action_coordinator::coordinator_terminating
private

The flag to avoid action starts post stop.

◆ current_executing_action

Group_action_information* Group_action_coordinator::current_executing_action
private

The currently proposed action owner.

◆ failure_debug_flag

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.

◆ group_thread_end_cond

mysql_cond_t Group_action_coordinator::group_thread_end_cond
private

The group action process thread end condition.

◆ group_thread_end_lock

mysql_mutex_t Group_action_coordinator::group_thread_end_lock
private

The group action process thread end lock.

◆ group_thread_run_cond

mysql_cond_t Group_action_coordinator::group_thread_run_cond
private

The group action process thread condition.

◆ group_thread_run_lock

mysql_mutex_t Group_action_coordinator::group_thread_run_lock
private

The group action process thread lock.

◆ is_group_action_being_executed

bool Group_action_coordinator::is_group_action_being_executed
private

If the group action execution method is being executed.

◆ is_sender

bool Group_action_coordinator::is_sender
private

Is this member the sender and controller of this action.

◆ known_members_addresses

std::list<std::string> Group_action_coordinator::known_members_addresses
private

The list of members known for the current action.

◆ local_action_killed

bool Group_action_coordinator::local_action_killed
private

Was the local action killed.

◆ local_action_terminating

bool Group_action_coordinator::local_action_terminating
private

Is the local submitted action terminating.

◆ member_leaving_group

bool Group_action_coordinator::member_leaving_group
private

Is this member leaving.

◆ monitoring_stage_handler

Plugin_stage_monitor_handler Group_action_coordinator::monitoring_stage_handler
private

The handler where actions can report progress through stages.

◆ number_of_known_members

int Group_action_coordinator::number_of_known_members
private

The number of received stop messages or dead members.

◆ number_of_terminated_members

int Group_action_coordinator::number_of_terminated_members
private

The number of received stop messages or dead members.

◆ proposed_action

Group_action_information* Group_action_coordinator::proposed_action
private

The currently proposed action owner.

◆ remote_warnings_reported

bool Group_action_coordinator::remote_warnings_reported
private

There were remote warnings reported.

◆ stop_wait_timeout

ulong Group_action_coordinator::stop_wait_timeout
private

The documentation for this class was generated from the following files: