MySQL 8.0.39
Source Code Documentation
primary_election_action.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 PRIMARY_ELECTION_INCLUDED
25#define PRIMARY_ELECTION_INCLUDED
26
32
33/**
34 @class Primary_election_action
35 The group action class to do migration to primary mode or elect a primary
36*/
38 public:
39 /** Enum for type of primary election executed */
41 PRIMARY_ELECTION_ACTION_PRIMARY_SWITCH = 0, // Change to a new primary
42 PRIMARY_ELECTION_ACTION_MODE_SWITCH = 1, // Change to single primary mode
43 PRIMARY_ELECTION_ACTION_END = 2 // Enum end
44 };
45
46 /** Enum for the phases on the primary action */
48 PRIMARY_NO_PHASE = 0, // No phase yet
49 PRIMARY_VALIDATION_PHASE = 1, // Check if primary is valid
50 PRIMARY_SAFETY_CHECK_PHASE = 2, // Make the change safe
51 PRIMARY_ELECTION_PHASE = 3, // Invoke primary election
52 PRIMARY_ELECTED_PHASE = 4 // Primary was elected/group in read mode
53 };
54
55 /** Enum for the phases on the primary action */
57 PRIMARY_ELECTION_INIT = 0, // Initiated
58 PRIMARY_ELECTION_END_ELECTION = 1, // End the election
59 PRIMARY_ELECTION_END_ERROR = 2, // Error in election
60 };
61
62 /**
63 Create a new primary election action
64 */
66
67 /**
68 Create a new primary election action with a given uuid
69 @param primary_uuid the primary uuid to elect, can be empty
70 @param thread_id the local thread id that is invoking this action
71 @param transaction_wait_timeout The number of seconds to wait before setting
72 the THD::KILL_CONNECTION flag for the transactions that did not reach commit
73 stage.
74 */
75 Primary_election_action(std::string primary_uuid, my_thread_id thread_id,
76 int32 transaction_wait_timeout = -1);
77
78 ~Primary_election_action() override;
79
80 /*
81 Get the message with parameters to this action
82 @param message [out] the message to start the action
83 */
84 void get_action_message(Group_action_message **message) override;
85
86 /*
87 Get the message with parameters to this action
88 @param message the message to start the action
89 @param message_origin the invoker address
90 */
92 const std::string &message_origin) override;
93
94 /**
95 Execute the action
96 @param invoking_member is the member that invoked it
97 @param stage_handler the stage handler to report progress
98
99 @returns the execution result
100 */
102 bool invoking_member, Plugin_stage_monitor_handler *stage_handler,
103 Notification_context *) override;
104
105 /*
106 Terminate the executing configuration operation
107 @param killed are we killing the action.
108
109 @return true if a problem was found when stopping the action.
110 */
111 bool stop_action_execution(bool killed) override;
112
113 /**
114 Gets the info about execution, be it success or failure
115 @return the execution diagnostics object that was the message and its level
116 */
118
119 /**
120 For this action, what is the PSI key for the last stage when the action is
121 terminating.
122 @return The stage key for this class
123 */
125
126 private:
127 /**
128 Persist the value of the variables changed in the action
129 @return true if a problem was found, false otherwise
130 */
132
133 /**
134 Log the result of the execution
135 @param error Did an error occurred
136 @param aborted was the action aborted?
137 @param mode_changed was the mode changed to single primary?
138 @param error_message details of error
139 */
140 void log_result_execution(bool error, bool aborted, bool mode_changed,
141 std::string &error_message);
142
143 // The listeners for group events
144
145 int after_view_change(const std::vector<Gcs_member_identifier> &joining,
146 const std::vector<Gcs_member_identifier> &leaving,
147 const std::vector<Gcs_member_identifier> &group,
148 bool is_leaving, bool *skip_election,
149 enum_primary_election_mode *election_mode,
150 std::string &suggested_primary) override;
152 std::string primary_uuid,
154 enum_primary_election_mode election_mode, int error) override;
156 const std::string &message_origin,
157 bool *skip_message) override;
158
159 /**
160 Stop the transaction_monitor_thread if running.
161
162 @return status
163 @retval true failed to stop the thread
164 @retval false thread stopped successfully.
165 */
167
168 /** Is this an primary change or mode change*/
170
171 /**
172 Changes the phase where the action is currently
173 @param phase the new election primary execution phase
174 */
176 /** The current phase */
178 /** Lock for the phase change */
180 /** Is this action aborted */
182 /** Was there an error in the election */
184 /** Was this action order to terminate by a kill signal*/
186
187 /** The primary to elect*/
189 /** The id of the primary to elect*/
191 /** The id of the invoking primary*/
193 /** The uuid of the original master at action invocation */
194 std::string old_primary_uuid;
195 /** If this member is old primary*/
197 /** The thread that invoked this action - if applicable, 0 otherwise */
199
200 /** Is the primary election invoked*/
202 /** primary election status*/
204 /** Is the transaction back log consumed*/
206
207 /**The lock for notifications*/
209 /**The condition for notifications*/
211
212 /** The handler for primary election validations */
214
215 /**Place to store result messages*/
217
218 /**
219 The number of seconds to wait before setting the THD::KILL_CONNECTION flag
220 for the transactions that did not reach commit stage. Client connection is
221 dropped.
222 */
224 /**
225 Used to monitor transactions, this stops the new transactions and sets the
226 THD::KILL_CONNECTION flag for the transactions that did not reach commit
227 stage post timeout expire. Client connection is dropped.
228 */
230};
231
232#endif /* PRIMARY_ELECTION_INCLUDED */
The parent class for group wide operations.
Definition: group_action.h:35
Definition: group_action_message.h:33
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
A convenience context class used to share information between the event handlers and the notifier.
Definition: notification.h:35
This is the base GCS plugin message.
Definition: gcs_plugin_messages.h:64
Definition: stage_monitor_handler.h:30
The group action class to do migration to primary mode or elect a primary.
Definition: primary_election_action.h:37
void get_action_message(Group_action_message **message) override
Get the message with parameters to this action.
Definition: primary_election_action.cc:98
bool action_killed
Was this action order to terminate by a kill signal.
Definition: primary_election_action.h:185
int32 m_transaction_wait_timeout
The number of seconds to wait before setting the THD::KILL_CONNECTION flag for the transactions that ...
Definition: primary_election_action.h:223
Primary_election_action()
Create a new primary election action.
Definition: primary_election_action.cc:31
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: primary_election_action.cc:699
~Primary_election_action() override
Definition: primary_election_action.cc:70
bool is_primary_election_invoked
Is the primary election invoked.
Definition: primary_election_action.h:201
Transaction_monitor_thread * transaction_monitor_thread
Used to monitor transactions, this stops the new transactions and sets the THD::KILL_CONNECTION flag ...
Definition: primary_election_action.h:229
std::string appointed_primary_uuid
The primary to elect.
Definition: primary_election_action.h:188
std::string invoking_member_gcs_id
The id of the invoking primary.
Definition: primary_election_action.h:192
enum_primary_election_phase current_action_phase
The current phase.
Definition: primary_election_action.h:177
bool stop_action_execution(bool killed) override
Definition: primary_election_action.cc:428
enum_primary_election_status
Enum for the phases on the primary action.
Definition: primary_election_action.h:56
@ PRIMARY_ELECTION_END_ELECTION
Definition: primary_election_action.h:58
@ PRIMARY_ELECTION_END_ERROR
Definition: primary_election_action.h:59
@ PRIMARY_ELECTION_INIT
Definition: primary_election_action.h:57
mysql_mutex_t notification_lock
The lock for notifications.
Definition: primary_election_action.h:208
std::string old_primary_uuid
The uuid of the original master at action invocation.
Definition: primary_election_action.h:194
mysql_mutex_t phase_lock
Lock for the phase change.
Definition: primary_election_action.h:179
Primary_election_validation_handler validation_handler
The handler for primary election validations.
Definition: primary_election_action.h:213
Group_action_diagnostics * get_execution_info() override
Gets the info about execution, be it success or failure.
Definition: primary_election_action.cc:459
my_thread_id invoking_thread_id
The thread that invoked this action - if applicable, 0 otherwise.
Definition: primary_election_action.h:198
void change_action_phase(enum_primary_election_phase phase)
Changes the phase where the action is currently.
Definition: primary_election_action.cc:443
bool stop_transaction_monitor_thread()
Stop the transaction_monitor_thread if running.
Definition: primary_election_action.cc:88
enum_action_execution_mode
Enum for type of primary election executed.
Definition: primary_election_action.h:40
@ PRIMARY_ELECTION_ACTION_END
Definition: primary_election_action.h:43
@ PRIMARY_ELECTION_ACTION_PRIMARY_SWITCH
Definition: primary_election_action.h:41
@ PRIMARY_ELECTION_ACTION_MODE_SWITCH
Definition: primary_election_action.h:42
bool error_on_primary_election
Was there an error in the election.
Definition: primary_election_action.h:183
mysql_cond_t notification_cond
The condition for notifications.
Definition: primary_election_action.h:210
Group_action::enum_action_execution_result execute_action(bool invoking_member, Plugin_stage_monitor_handler *stage_handler, Notification_context *) override
Execute the action.
Definition: primary_election_action.cc:231
std::string appointed_primary_gcs_id
The id of the primary to elect.
Definition: primary_election_action.h:190
enum_primary_election_status m_execution_status
primary election status
Definition: primary_election_action.h:203
void log_result_execution(bool error, bool aborted, bool mode_changed, std::string &error_message)
Log the result of the execution.
Definition: primary_election_action.cc:759
bool is_transaction_queue_applied
Is the transaction back log consumed.
Definition: primary_election_action.h:205
bool single_election_action_aborted
Is this action aborted.
Definition: primary_election_action.h:181
enum_action_execution_mode action_execution_mode
Is this an primary change or mode change.
Definition: primary_election_action.h:169
int process_action_message(Group_action_message &message, const std::string &message_origin) override
Definition: primary_election_action.cc:104
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: primary_election_action.cc:654
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: primary_election_action.cc:465
bool persist_variable_values()
Persist the value of the variables changed in the action.
Definition: primary_election_action.cc:732
bool is_primary
If this member is old primary.
Definition: primary_election_action.h:196
enum_primary_election_phase
Enum for the phases on the primary action.
Definition: primary_election_action.h:47
@ PRIMARY_NO_PHASE
Definition: primary_election_action.h:48
@ PRIMARY_ELECTION_PHASE
Definition: primary_election_action.h:51
@ PRIMARY_ELECTED_PHASE
Definition: primary_election_action.h:52
@ PRIMARY_VALIDATION_PHASE
Definition: primary_election_action.h:49
@ PRIMARY_SAFETY_CHECK_PHASE
Definition: primary_election_action.h:50
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.
Definition: primary_election_action.cc:451
Group_action_diagnostics execution_message_area
Place to store result messages.
Definition: primary_election_action.h:216
Definition: primary_election_validation_handler.h:32
Class for creating a new thread that allows to stop the new transactions allowing some management que...
Definition: group_actions_transaction_controller.h:38
unsigned int PSI_stage_key
Instrumented stage key.
Definition: psi_stage_bits.h:43
int32_t int32
Definition: my_inttypes.h:66
static my_thread_id thread_id
Definition: my_thr_init.cc:63
uint32 my_thread_id
Definition: my_thread_local.h:34
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
An instrumented cond structure.
Definition: mysql_cond_bits.h:50
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50