MySQL 8.0.39
Source Code Documentation
|
The group action class to do migration to primary mode or elect a primary. More...
#include <primary_election_action.h>
Public Types | |
enum | enum_action_execution_mode { PRIMARY_ELECTION_ACTION_PRIMARY_SWITCH = 0 , PRIMARY_ELECTION_ACTION_MODE_SWITCH = 1 , PRIMARY_ELECTION_ACTION_END = 2 } |
Enum for type of primary election executed. More... | |
enum | enum_primary_election_phase { PRIMARY_NO_PHASE = 0 , PRIMARY_VALIDATION_PHASE = 1 , PRIMARY_SAFETY_CHECK_PHASE = 2 , PRIMARY_ELECTION_PHASE = 3 , PRIMARY_ELECTED_PHASE = 4 } |
Enum for the phases on the primary action. More... | |
enum | enum_primary_election_status { PRIMARY_ELECTION_INIT = 0 , PRIMARY_ELECTION_END_ELECTION = 1 , PRIMARY_ELECTION_END_ERROR = 2 } |
Enum for the phases on the primary action. More... | |
Public Types inherited from Group_action | |
enum | enum_action_execution_result { GROUP_ACTION_RESULT_TERMINATED = 0 , GROUP_ACTION_RESULT_ERROR = 1 , GROUP_ACTION_RESULT_RESTART = 2 , GROUP_ACTION_RESULT_ABORTED = 3 , GROUP_ACTION_RESULT_KILLED = 4 , GROUP_ACTION_RESULT_END = 5 } |
Enum for the end results of a action execution. More... | |
Public Member Functions | |
Primary_election_action () | |
Create a new primary election action. More... | |
Primary_election_action (std::string primary_uuid, my_thread_id thread_id, int32 transaction_wait_timeout=-1) | |
Create a new primary election action with a given uuid. More... | |
~Primary_election_action () override | |
void | get_action_message (Group_action_message **message) override |
Get the message with parameters to this action. More... | |
int | process_action_message (Group_action_message &message, const std::string &message_origin) override |
Group_action::enum_action_execution_result | execute_action (bool invoking_member, Plugin_stage_monitor_handler *stage_handler, Notification_context *) override |
Execute the action. More... | |
bool | stop_action_execution (bool killed) override |
Group_action_diagnostics * | get_execution_info () override |
Gets the info about execution, be it success or failure. More... | |
PSI_stage_key | get_action_stage_termination_key () override |
For this action, what is the PSI key for the last stage when the action is terminating. More... | |
Public Member Functions inherited from Group_action | |
virtual | ~Group_action ()=0 |
Private Member Functions | |
bool | persist_variable_values () |
Persist the value of the variables changed in the action. More... | |
void | log_result_execution (bool error, bool aborted, bool mode_changed, std::string &error_message) |
Log the result of the execution. More... | |
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 | stop_transaction_monitor_thread () |
Stop the transaction_monitor_thread if running. More... | |
void | change_action_phase (enum_primary_election_phase phase) |
Changes the phase where the action is currently. More... | |
Private Member Functions inherited from Group_event_observer | |
virtual | ~Group_event_observer ()=0 |
Private Attributes | |
enum_action_execution_mode | action_execution_mode |
Is this an primary change or mode change. More... | |
enum_primary_election_phase | current_action_phase |
The current phase. More... | |
mysql_mutex_t | phase_lock |
Lock for the phase change. More... | |
bool | single_election_action_aborted |
Is this action aborted. More... | |
bool | error_on_primary_election |
Was there an error in the election. More... | |
bool | action_killed |
Was this action order to terminate by a kill signal. More... | |
std::string | appointed_primary_uuid |
The primary to elect. More... | |
std::string | appointed_primary_gcs_id |
The id of the primary to elect. More... | |
std::string | invoking_member_gcs_id |
The id of the invoking primary. More... | |
std::string | old_primary_uuid |
The uuid of the original master at action invocation. More... | |
bool | is_primary |
If this member is old primary. More... | |
my_thread_id | invoking_thread_id |
The thread that invoked this action - if applicable, 0 otherwise. More... | |
bool | is_primary_election_invoked |
Is the primary election invoked. More... | |
enum_primary_election_status | m_execution_status {PRIMARY_ELECTION_INIT} |
primary election status More... | |
bool | is_transaction_queue_applied |
Is the transaction back log consumed. More... | |
mysql_mutex_t | notification_lock |
The lock for notifications. More... | |
mysql_cond_t | notification_cond |
The condition for notifications. More... | |
Primary_election_validation_handler | validation_handler |
The handler for primary election validations. More... | |
Group_action_diagnostics | execution_message_area |
Place to store result messages. More... | |
int32 | m_transaction_wait_timeout = {-1} |
The number of seconds to wait before setting the THD::KILL_CONNECTION flag for the transactions that did not reach commit stage. More... | |
Transaction_monitor_thread * | transaction_monitor_thread {nullptr} |
Used to monitor transactions, this stops the new transactions and sets the THD::KILL_CONNECTION flag for the transactions that did not reach commit stage post timeout expire. More... | |
The group action class to do migration to primary mode or elect a primary.
Primary_election_action::Primary_election_action | ( | ) |
Create a new primary election action.
Primary_election_action::Primary_election_action | ( | std::string | primary_uuid, |
my_thread_id | thread_id, | ||
int32 | transaction_wait_timeout = -1 |
||
) |
Create a new primary election action with a given uuid.
primary_uuid | the primary uuid to elect, can be empty |
thread_id | the local thread id that is invoking this action |
transaction_wait_timeout | The number of seconds to wait before setting the THD::KILL_CONNECTION flag for the transactions that did not reach commit stage. |
|
override |
Assert has been used since object has not been destroyed at the exit point code. If this ever occurs, the scenario needs to be analyzed to understand why object was not deleted on the exit points of the primary election.
delete transaction_monitor_thread is present at exit points when a change of primary is finishing. However if delete is not triggered at those exit points then object should be destroyed here. This code is added for safety.
|
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 |
Either: -This is a change from SP and the the old primary died, so there is no invoking member, nor a member that is waiting on local transactions. -On changes from multi primary, and the invoking member left
For all the old secondaries that remain this means:
Note that this state change from validation to the next state is not in a group logical moment so different members can be at different stages. Still all that members care is the moment the election is called, so the result will be the same at all members. If the primary is not valid, the stage never changed from validation so member will invoke the election here. If valid, members will either update the invoking member or invoke the election according to the stage (hence the phase lock)
We also make the failover primary election process to be skipped, because we want a specific primary to be elected.
There is an election and the primary being elected dies.
Case 1: We are moving to another primary, and it failed. The process will fail abort but we still try to invoke an election to go back to the old primary.
Case 2: We are moving to single primary mode and the appointed primary died, then we move to another primary and emit a warning
Note 1: We pass election params instead of invoking them because of the hook mechanism that is invoking this method and is also used in the invoked election methods.
Check if we can change to the old primary. If this variable is empty, it is not present.
Implements Group_event_observer.
|
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.
|
private |
Changes the phase where the action is currently.
phase | the new election primary execution phase |
|
overridevirtual |
Execute the action.
invoking_member | is the member that invoked it |
stage_handler | the stage handler to report progress |
Observers have been de-registered so transaction_monitor_thread should have been destroyed by now in after_view_change or after_primary_election. If not, then destroy the object now(during UDF failure it has been observed intermittently object was not destroyed in after_view_change or after_primary_election).
Implements Group_action.
|
overridevirtual |
Get the message with parameters to this action.
[out] | message | the message to start the action |
Implements Group_action.
|
overridevirtual |
For this action, what is the PSI key for the last stage when the action is terminating.
Reimplemented from Group_action.
|
overridevirtual |
Gets the info about execution, be it success or failure.
Implements Group_action.
|
private |
Log the result of the execution.
error | Did an error occurred |
aborted | was the action aborted? |
mode_changed | was the mode changed to single primary? |
error_message | details of error |
|
private |
Persist the value of the variables changed in the action.
|
overridevirtual |
Implements Group_action.
|
overridevirtual |
When a UDF group_replication_set_as_primary is killed using 'KILL connection_id' code reaches here.
Implements Group_action.
|
private |
Stop the transaction_monitor_thread if running.
true | failed to stop the thread |
false | thread stopped successfully. |
|
private |
Is this an primary change or mode change.
|
private |
Was this action order to terminate by a kill signal.
|
private |
The id of the primary to elect.
|
private |
The primary to elect.
|
private |
The current phase.
|
private |
Was there an error in the election.
|
private |
Place to store result messages.
|
private |
The id of the invoking primary.
|
private |
The thread that invoked this action - if applicable, 0 otherwise.
|
private |
If this member is old primary.
|
private |
Is the primary election invoked.
|
private |
Is the transaction back log consumed.
|
private |
primary election status
|
private |
The number of seconds to wait before setting the THD::KILL_CONNECTION flag for the transactions that did not reach commit stage.
Client connection is dropped.
|
private |
The condition for notifications.
|
private |
The lock for notifications.
|
private |
The uuid of the original master at action invocation.
|
private |
Lock for the phase change.
|
private |
Is this action aborted.
|
private |
Used to monitor transactions, this stops the new transactions and sets the THD::KILL_CONNECTION flag for the transactions that did not reach commit stage post timeout expire.
Client connection is dropped.
|
private |
The handler for primary election validations.