MySQL 8.4.0
Source Code Documentation
gcs_event_handlers.h
Go to the documentation of this file.
1/* Copyright (c) 2014, 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 GCS_EVENT_HANDLERS_INCLUDE
25#define GCS_EVENT_HANDLERS_INCLUDE
26
27#include <set>
28#include <vector>
29
43
44/**
45 Group_member_info_pointer_comparator to guarantee uniqueness
46 */
49 return one->has_lower_uuid(other);
50 }
51};
52
53/*
54 @class Plugin_gcs_events_handler
55
56 Implementation of all GCS event handlers to the plugin
57 */
60 public:
61 /**
62 Plugin_gcs_events_handler constructor
63
64 It receives, via the constructor, all the necessary dependencies to work.
65 */
69 ulong components_stop_timeout);
71
72 /*
73 Implementation of all callback methods
74 */
75 void on_message_received(const Gcs_message &message) const override;
76 void on_view_changed(const Gcs_view &new_view,
77 const Exchanged_data &exchanged_data) const override;
79 void on_suspicions(
80 const std::vector<Gcs_member_identifier> &members,
81 const std::vector<Gcs_member_identifier> &unreachable) const override;
82
83 /**
84 Sets the component stop timeout.
85
86 @param[in] timeout the timeout
87 */
89
90 /**
91 This function disable read-only mode when member version is compatible with
92 group.
93
94 @param[in] force_check Compatibility is mandatory re-checked
95 */
96 void disable_read_mode_for_compatible_members(bool force_check = false) const;
97
98 private:
99 /*
100 Individual handling methods for all possible message types
101 received via on_message_received(...)
102 */
103 void handle_transactional_message(const Gcs_message &message) const;
104 void handle_recovery_metadata(const Gcs_message &message) const;
106 const Gcs_message &message) const;
107 void handle_transaction_prepared_message(const Gcs_message &message) const;
108 void handle_sync_before_execution_message(const Gcs_message &message) const;
109 void handle_certifier_message(const Gcs_message &message) const;
110 void handle_recovery_message(Plugin_gcs_message *message) const;
111 void handle_stats_message(const Gcs_message &message) const;
113 Plugin_gcs_message *processed_message) const;
114 void handle_group_action_message(const Gcs_message &message) const;
115 /**
116 This method passes the message to message listeners
117 @param plugin_message A pointer to the processed plugin gcs message
118 @param message_origin A id of the message originating member
119 @return true if the message should be skipped, false otherwise
120 */
121 bool pre_process_message(Plugin_gcs_message *plugin_message,
122 const std::string &message_origin) const;
123 /*
124 Methods to act upon members after a on_view_change(...) is called
125 */
126 int update_group_info_manager(const Gcs_view &new_view,
127 const Exchanged_data &exchanged_data,
128 bool is_joining, bool is_leaving) const;
129 void handle_joining_members(const Gcs_view &new_view, bool is_joining,
130 bool is_leaving) const;
131 void handle_leaving_members(const Gcs_view &new_view, bool is_joining,
132 bool is_leaving) const;
133
134 /**
135 This method updates the status of the members in the list according to the
136 given parameters.
137
138 @param members the vector with members to change the status to
139 @param status the status to change to.
140 @param old_equal_to change if the old status is equal to
141 @param old_different_from change if the old status if different from
142
143 @note When not using the old_equal_to and old_different_from parameters, you
144 can pass the Group_member_info::MEMBER_END value.
145 */
147 const std::vector<Gcs_member_identifier> &members,
150 Group_member_info::Group_member_status old_different_from) const;
151
152 /**
153 This method handles the election of a new primary node when the plugin runs
154 in single primary mode.
155
156 @param election_mode election type
157 @param suggested_primary what should be the next primary to elect
158
159 @note This function unsets the super read only mode on primary node
160 and sets it on secondary nodes
161 */
163 enum_primary_election_mode election_mode,
164 std::string &suggested_primary) const;
165
166 int process_local_exchanged_data(const Exchanged_data &exchanged_data,
167 bool is_joining) const;
168
169 /**
170 Verifies if a certain Vector of Member Ids contains a given member id.
171
172 @param members the vector with members to verify
173 @param member_id the member to check if it contained.
174
175 @return true if member_id occurs in members.
176 */
177 bool is_member_on_vector(const std::vector<Gcs_member_identifier> &members,
178 const Gcs_member_identifier &member_id) const;
179
180 /**
181 Checks the compatibility of the member with the group.
182 It checks:
183 1) If the number of members was exceeded
184 2) If member version is compatible with the group
185 3) If the gtid_assignment_block_size is equal to the group
186 4) If the hash algorithm used is equal to the group
187 5) If the member has more known transactions than the group
188
189 @param number_of_members the number of members in the new view
190
191 @retval 0 compatible
192 @retval >0 not compatible with the group
193 */
194 int check_group_compatibility(size_t number_of_members) const;
195
196 /**
197 When the member is joining, cycle through all members on group and see if it
198 is compatible with them.
199
200 @return the compatibility with the group
201 @retval INCOMPATIBLE //Versions not compatible
202 @retval COMPATIBLE //Versions compatible
203 @retval READ_COMPATIBLE //Member can read but not write
204 */
206
207 /**
208 Method that compares the group's aggregated GTID set against the joiner
209 GTID set. These sets contain executed and received GTIDs present
210 in the relay log files belonging to each member plugin applier channel.
211
212 @return if the joiner has more GTIDs then the group.
213 @retval 0 Joiner has less GTIDs than the group
214 @retval >0 Joiner has more GTIDS than the group
215 @retval <0 Error when processing GTID information
216 */
218
219 /**
220 This method takes all the group executed sets and adds those belonging to
221 non recovering member to the view change packet
222
223 @param[in] view_packet the view change packet
224 */
225 void collect_members_executed_sets(View_change_packet *view_packet) const;
226
227 /**
228 Method that compares the member options with
229 the value of the same option on all other members.
230 It compares:
231 1) GTID assignment block size
232 2) Write set hash algorithm
233
234 @retval 0 Joiner has the same value as all other members
235 @retval !=0 Otherwise
236 */
238
239 /**
240 Check if a member is not entering a group where an action is running.
241 If action is running provide details of action.
242
243 @param[out] group_action_running_initiator Group action configuration
244 initiator details
245 @param[out] group_action_running_description Group action configuration
246 description
247
248 @retval false no group action is running
249 @retval true a group action is running
250 */
252 std::string &group_action_running_initiator,
253 std::string &group_action_running_description) const;
254
255 /**
256 Check if the group is running a primary election
257
258 @retval false no primary election is running
259 @retval true a primary election is running
260 */
262
263 /**
264 This method checks if member was expelled from the group due
265 to network failures.
266
267 @param[in] view the view delivered by the GCS
268
269 @retval true the member was expelled
270 @retval false otherwise
271 */
272 bool was_member_expelled_from_group(const Gcs_view &view) const;
273
274 /**
275 Logs member joining message to error logs from view.
276
277 @param[in] new_view the view delivered by the GCS
278 */
279 void log_members_joining_message(const Gcs_view &new_view) const;
280
281 /**
282 Logs member leaving message to error logs from view.
283
284 @param[in] new_view the view delivered by the GCS
285 */
286 void log_messages_during_member_leave(const Gcs_view &new_view) const;
287
288 /**
289 This function return all members present in vector of Gcs_member_identifier
290 in HOST:PORT format separated by comma.
291 Function also return PRIMARY member if any in HOST:PORT format.
292
293 @param[in] members joining or leaving members for this view
294 @param[out] all_hosts host and port of all members from view
295 @param[out] primary_host primary member hosts and port of all members from
296 view
297 */
298 void get_hosts_from_view(const std::vector<Gcs_member_identifier> &members,
299 std::string &all_hosts,
300 std::string &primary_host) const;
301
302 /**
303 Leave group on recovering metadata error.
304
305 @param[in] error_message Log error message on member leave.
306 */
307 void leave_group_on_recovery_metadata_error(std::string error_message) const;
308
311
312 /*
313 Holds, until view can be installed, all Member information received from
314 other members
315 */
316 std::set<Group_member_info *, Group_member_info_pointer_comparator>
318
320
321 /**The status of this member when it joins*/
323
324 /* Component stop timeout on shutdown */
326
327#ifndef NDEBUG
329#endif
330
331 /** The notification context for the GCS delivery thread. */
333};
334
335#endif /* GCS_EVENT_HANDLERS_INCLUDE */
Definition: applier.h:276
Definition: compatibility_module.h:41
This interface is implemented by those who wish to receive messages.
Definition: gcs_communication_event_listener.h:36
This interface is implemented by those who wish to receive Control Interface notifications.
Definition: gcs_control_event_listener.h:52
It represents the identity of a group member within a certain group.
Definition: gcs_member_identifier.h:40
This class serves as data container for information flowing in the GCS ecosystem.
Definition: gcs_message.h:48
Class that represents the data that is exchanged within a group.
Definition: gcs_message.h:357
This represents the membership view that a member has from a group.
Definition: gcs_view.h:55
Definition: member_info.h:82
Group_member_status
Definition: member_info.h:173
bool has_lower_uuid(Group_member_info *other)
Return true if server uuid is lower than other member server uuid.
Definition: member_info.cc:928
A convenience context class used to share information between the event handlers and the notifier.
Definition: notification.h:35
Definition: gcs_event_handlers.h:59
bool was_member_expelled_from_group(const Gcs_view &view) const
This method checks if member was expelled from the group due to network failures.
Definition: gcs_event_handlers.cc:967
void handle_single_primary_message(Plugin_gcs_message *processed_message) const
Definition: gcs_event_handlers.cc:432
void handle_transaction_prepared_message(const Gcs_message &message) const
Definition: gcs_event_handlers.cc:248
void handle_transactional_message(const Gcs_message &message) const
Definition: gcs_event_handlers.cc:184
void handle_leader_election_if_needed(enum_primary_election_mode election_mode, std::string &suggested_primary) const
This method handles the election of a new primary node when the plugin runs in single primary mode.
Definition: gcs_event_handlers.cc:990
int update_group_info_manager(const Gcs_view &new_view, const Exchanged_data &exchanged_data, bool is_joining, bool is_leaving) const
Definition: gcs_event_handlers.cc:1006
Gcs_message_data * get_exchangeable_data() const override
This method is called when the Data Exchange is about to happen in order for the client to provide wh...
Definition: gcs_event_handlers.cc:1573
void handle_sync_before_execution_message(const Gcs_message &message) const
Definition: gcs_event_handlers.cc:282
int process_local_exchanged_data(const Exchanged_data &exchanged_data, bool is_joining) const
Definition: gcs_event_handlers.cc:1419
void get_hosts_from_view(const std::vector< Gcs_member_identifier > &members, std::string &all_hosts, std::string &primary_host) const
This function return all members present in vector of Gcs_member_identifier in HOST:PORT format separ...
Definition: gcs_event_handlers.cc:786
void handle_joining_members(const Gcs_view &new_view, bool is_joining, bool is_leaving) const
Definition: gcs_event_handlers.cc:1093
void handle_leaving_members(const Gcs_view &new_view, bool is_joining, bool is_leaving) const
Definition: gcs_event_handlers.cc:1373
void handle_recovery_metadata(const Gcs_message &message) const
Definition: gcs_event_handlers.cc:493
void on_suspicions(const std::vector< Gcs_member_identifier > &members, const std::vector< Gcs_member_identifier > &unreachable) const override
This member function is called when the set of suspicions has changed in the underlying communication...
Definition: gcs_event_handlers.cc:648
void disable_read_mode_for_compatible_members(bool force_check=false) const
This function disable read-only mode when member version is compatible with group.
Definition: gcs_event_handlers.cc:2134
void handle_group_action_message(const Gcs_message &message) const
Definition: gcs_event_handlers.cc:459
Compatibility_module * compatibility_manager
Definition: gcs_event_handlers.h:319
bool set_number_of_members_on_view_changed_to_10
Definition: gcs_event_handlers.h:328
Plugin_gcs_events_handler(Applier_module_interface *applier_module, Recovery_module *recovery_module, Compatibility_module *compatibility_manager, ulong components_stop_timeout)
Plugin_gcs_events_handler constructor.
Definition: gcs_event_handlers.cc:55
ulong stop_wait_timeout
Definition: gcs_event_handlers.h:325
bool pre_process_message(Plugin_gcs_message *plugin_message, const std::string &message_origin) const
This method passes the message to message listeners.
Definition: gcs_event_handlers.cc:175
void on_message_received(const Gcs_message &message) const override
This method is called whenever a message is to be delivered.
Definition: gcs_event_handlers.cc:79
void handle_recovery_message(Plugin_gcs_message *message) const
Definition: gcs_event_handlers.cc:327
st_compatibility_types check_version_compatibility_with_group() const
When the member is joining, cycle through all members on group and see if it is compatible with them.
Definition: gcs_event_handlers.cc:1806
Recovery_module * recovery_module
Definition: gcs_event_handlers.h:310
int check_group_compatibility(size_t number_of_members) const
Checks the compatibility of the member with the group.
Definition: gcs_event_handlers.cc:1732
void handle_certifier_message(const Gcs_message &message) const
Definition: gcs_event_handlers.cc:302
bool is_member_on_vector(const std::vector< Gcs_member_identifier > &members, const Gcs_member_identifier &member_id) const
Verifies if a certain Vector of Member Ids contains a given member id.
Definition: gcs_event_handlers.cc:1409
bool is_group_running_a_primary_election() const
Check if the group is running a primary election.
Definition: gcs_event_handlers.cc:2119
Applier_module_interface * applier_module
Definition: gcs_event_handlers.h:309
void leave_group_on_recovery_metadata_error(std::string error_message) const
Leave group on recovering metadata error.
Definition: gcs_event_handlers.cc:638
void log_members_joining_message(const Gcs_view &new_view) const
Logs member joining message to error logs from view.
Definition: gcs_event_handlers.cc:774
void on_view_changed(const Gcs_view &new_view, const Exchanged_data &exchanged_data) const override
This method is called when the view is ready to be installed.
Definition: gcs_event_handlers.cc:824
bool is_group_running_a_configuration_change(std::string &group_action_running_initiator, std::string &group_action_running_description) const
Check if a member is not entering a group where an action is running.
Definition: gcs_event_handlers.cc:2099
void collect_members_executed_sets(View_change_packet *view_packet) const
This method takes all the group executed sets and adds those belonging to non recovering member to th...
Definition: gcs_event_handlers.cc:1955
void log_messages_during_member_leave(const Gcs_view &new_view) const
Logs member leaving message to error logs from view.
Definition: gcs_event_handlers.cc:732
Notification_context m_notification_ctx
The notification context for the GCS delivery thread.
Definition: gcs_event_handlers.h:332
~Plugin_gcs_events_handler() override
Definition: gcs_event_handlers.cc:74
void handle_transactional_with_guarantee_message(const Gcs_message &message) const
Definition: gcs_event_handlers.cc:211
void update_member_status(const std::vector< Gcs_member_identifier > &members, Group_member_info::Group_member_status status, Group_member_info::Group_member_status old_equal_to, Group_member_info::Group_member_status old_different_from) const
This method updates the status of the members in the list according to the given parameters.
Definition: gcs_event_handlers.cc:1689
void handle_stats_message(const Gcs_message &message) const
Definition: gcs_event_handlers.cc:418
int compare_member_transaction_sets() const
Method that compares the group's aggregated GTID set against the joiner GTID set.
Definition: gcs_event_handlers.cc:1881
st_compatibility_types * joiner_compatibility_status
The status of this member when it joins.
Definition: gcs_event_handlers.h:322
std::set< Group_member_info *, Group_member_info_pointer_comparator > * temporary_states
Definition: gcs_event_handlers.h:317
int compare_member_option_compatibility() const
Method that compares the member options with the value of the same option on all other members.
Definition: gcs_event_handlers.cc:1979
void set_stop_wait_timeout(ulong timeout)
Sets the component stop timeout.
Definition: gcs_event_handlers.h:88
This is the base GCS plugin message.
Definition: gcs_plugin_messages.h:64
Definition: recovery.h:39
A packet to send view change related info to the applier.
Definition: pipeline_interfaces.h:116
st_compatibility_types
Definition: compatibility_module.h:33
std::vector< std::pair< Gcs_member_identifier *, Gcs_message_data * > > Exchanged_data
Alias for the Data exchanged and delivered from all nodes.
Definition: gcs_control_event_listener.h:40
static bool timeout(bool(*wait_condition)())
Timeout function.
Definition: log0meb.cc:498
enum_primary_election_mode
Enum for election types.
Definition: primary_election_include.h:33
required uint32 status
Definition: replication_asynchronous_connection_failover.proto:61
Group_member_info_pointer_comparator to guarantee uniqueness.
Definition: gcs_event_handlers.h:47
bool operator()(Group_member_info *one, Group_member_info *other) const
Definition: gcs_event_handlers.h:48