MySQL  8.0.21
Source Code Documentation
gcs_event_handlers.h
Go to the documentation of this file.
1 /* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
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 also distributed 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 included with MySQL.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License, version 2.0, for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 #ifndef GCS_EVENT_HANDLERS_INCLUDE
24 #define GCS_EVENT_HANDLERS_INCLUDE
25 
26 #include <set>
27 #include <vector>
28 
42 
43 /**
44  Group_member_info_pointer_comparator to guarantee uniqueness
45  */
47  bool operator()(Group_member_info *one, Group_member_info *other) const {
48  return one->has_lower_uuid(other);
49  }
50 };
51 
52 /*
53  @class Plugin_gcs_events_handler
54 
55  Implementation of all GCS event handlers to the plugin
56  */
59  public:
60  /**
61  Plugin_gcs_events_handler constructor
62 
63  It receives, via the constructor, all the necessary dependencies to work.
64  */
67  Compatibility_module *compatibility_manager,
68  ulong components_stop_timeout);
69  virtual ~Plugin_gcs_events_handler();
70 
71  /*
72  Implementation of all callback methods
73  */
74  void on_message_received(const Gcs_message &message) const;
75  void on_view_changed(const Gcs_view &new_view,
76  const Exchanged_data &exchanged_data) const;
77  Gcs_message_data *get_exchangeable_data() const;
78  void on_suspicions(
79  const std::vector<Gcs_member_identifier> &members,
80  const std::vector<Gcs_member_identifier> &unreachable) const;
81 
82  /**
83  Sets the component stop timeout.
84 
85  @param[in] timeout the timeout
86  */
87  void set_stop_wait_timeout(ulong timeout) { stop_wait_timeout = timeout; }
88 
89  /**
90  This function disable read-only mode when member version is compatible with
91  group.
92 
93  @param[in] force_check Compatibility is mandatory re-checked
94  */
95  void disable_read_mode_for_compatible_members(bool force_check = false) const;
96 
97  private:
98  /*
99  Individual handling methods for all possible message types
100  received via on_message_received(...)
101  */
102  void handle_transactional_message(const Gcs_message &message) const;
103  void handle_transactional_with_guarantee_message(
104  const Gcs_message &message) const;
105  void handle_transaction_prepared_message(const Gcs_message &message) const;
106  void handle_sync_before_execution_message(const Gcs_message &message) const;
107  void handle_certifier_message(const Gcs_message &message) const;
108  void handle_recovery_message(Plugin_gcs_message *message) const;
109  void handle_stats_message(const Gcs_message &message) const;
110  void handle_single_primary_message(
111  Plugin_gcs_message *processed_message) const;
112  void handle_group_action_message(const Gcs_message &message) const;
113  /**
114  This method passes the message to message listeners
115  @param plugin_message A pointer to the processed plugin gcs message
116  @param message_origin A id of the message originating member
117  @return true if the message should be skipped, false otherwise
118  */
119  bool pre_process_message(Plugin_gcs_message *plugin_message,
120  const std::string &message_origin) const;
121  /*
122  Methods to act upon members after a on_view_change(...) is called
123  */
124  int update_group_info_manager(const Gcs_view &new_view,
125  const Exchanged_data &exchanged_data,
126  bool is_joining, bool is_leaving) const;
127  void handle_joining_members(const Gcs_view &new_view, bool is_joining,
128  bool is_leaving) const;
129  void handle_leaving_members(const Gcs_view &new_view, bool is_joining,
130  bool is_leaving) const;
131 
132  /**
133  This method updates the status of the members in the list according to the
134  given parameters.
135 
136  @param members the vector with members to change the status to
137  @param status the status to change to.
138  @param old_equal_to change if the old status is equal to
139  @param old_different_from change if the old status if different from
140 
141  @note When not using the old_equal_to and old_different_from parameters, you
142  can pass the Group_member_info::MEMBER_END value.
143  */
144  void update_member_status(
145  const std::vector<Gcs_member_identifier> &members,
148  Group_member_info::Group_member_status old_different_from) const;
149 
150  /**
151  This method handles the election of a new primary node when the plugin runs
152  in single primary mode.
153 
154  @param election_mode election type
155  @param suggested_primary what should be the next primary to elect
156 
157  @note This function unsets the super read only mode on primary node
158  and sets it on secondary nodes
159  */
160  void handle_leader_election_if_needed(
161  enum_primary_election_mode election_mode,
162  std::string &suggested_primary) const;
163 
164  int process_local_exchanged_data(const Exchanged_data &exchanged_data,
165  bool is_joining) const;
166 
167  /**
168  Verifies if a certain Vector of Member Ids contains a given member id.
169 
170  @param members the vector with members to verify
171  @param member_id the member to check if it contained.
172 
173  @return true if member_id occurs in members.
174  */
175  bool is_member_on_vector(const std::vector<Gcs_member_identifier> &members,
176  const Gcs_member_identifier &member_id) const;
177 
178  /**
179  Checks the compatibility of the member with the group.
180  It checks:
181  1) If the number of members was exceeded
182  2) If member version is compatible with the group
183  3) If the gtid_assignment_block_size is equal to the group
184  4) If the hash algorithm used is equal to the group
185  5) If the member has more known transactions than the group
186 
187  @param number_of_members the number of members in the new view
188 
189  @retval 0 compatible
190  @retval >0 not compatible with the group
191  */
192  int check_group_compatibility(size_t number_of_members) const;
193 
194  /**
195  When the member is joining, cycle through all members on group and see if it
196  is compatible with them.
197 
198  @return the compatibility with the group
199  @retval INCOMPATIBLE //Versions not compatible
200  @retval COMPATIBLE //Versions compatible
201  @retval READ_COMPATIBLE //Member can read but not write
202  */
203  st_compatibility_types check_version_compatibility_with_group() const;
204 
205  /**
206  Method that compares the group's aggregated GTID set against the joiner
207  GTID set. These sets contain executed and received GTIDs present
208  in the relay log files belonging to each member plugin applier channel.
209 
210  @return if the joiner has more GTIDs then the group.
211  @retval 0 Joiner has less GTIDs than the group
212  @retval >0 Joiner has more GTIDS than the group
213  @retval <0 Error when processing GTID information
214  */
215  int compare_member_transaction_sets() const;
216 
217  /**
218  This method takes all the group executed sets and adds those belonging to
219  non recovering member to the view change packet
220 
221  @param[in] view_packet the view change packet
222  */
223  void collect_members_executed_sets(View_change_packet *view_packet) const;
224 
225  /**
226  Method that compares the member options with
227  the value of the same option on all other members.
228  It compares:
229  1) GTID assignment block size
230  2) Write set hash algorithm
231 
232  @retval 0 Joiner has the same value as all other members
233  @retval !=0 Otherwise
234  */
235  int compare_member_option_compatibility() const;
236 
237  /**
238  Check if a member is not entering a group where an action is running
239 
240  @retval false no group action is running
241  @retval true a group action is running
242  */
243  bool is_group_running_a_configuration_change() const;
244 
245  /**
246  Check if the group is running a primary election
247 
248  @retval false no primary election is running
249  @retval true a primary election is running
250  */
251  bool is_group_running_a_primary_election() const;
252 
253  /**
254  This method checks if member was expelled from the group due
255  to network failures.
256 
257  @param[in] view the view delivered by the GCS
258 
259  @retval true the member was expelled
260  @retval false otherwise
261  */
262  bool was_member_expelled_from_group(const Gcs_view &view) const;
263 
264  /**
265  Logs member joining message to error logs from view.
266 
267  @param[in] new_view the view delivered by the GCS
268  */
269  void log_members_joining_message(const Gcs_view &new_view) const;
270 
271  /**
272  Logs member leaving message to error logs from view.
273 
274  @param[in] new_view the view delivered by the GCS
275  */
276  void log_members_leaving_message(const Gcs_view &new_view) const;
277 
278  /**
279  This function return all members present in vector of Gcs_member_identifier
280  in HOST:PORT format separated by comma.
281  Function also return PRIMARY member if any in HOST:PORT format.
282 
283  @param[in] members joining or leaving members for this view
284  @param[out] all_hosts host and port of all members from view
285  @param[out] primary_host primary member hosts and port of all members from
286  view
287  */
288  void get_hosts_from_view(const std::vector<Gcs_member_identifier> &members,
289  std::string &all_hosts,
290  std::string &primary_host) const;
291 
294 
295  /*
296  Holds, until view can be installed, all Member information received from
297  other members
298  */
299  std::set<Group_member_info *, Group_member_info_pointer_comparator>
301 
303 
304  /**The status of this member when it joins*/
306 
307  /* Component stop timeout on shutdown */
309 
310 #ifndef DBUG_OFF
312 #endif
313 
314  /** The notification context for the GCS delivery thread. */
316 };
317 
318 #endif /* GCS_EVENT_HANDLERS_INCLUDE */
st_compatibility_types
Definition: compatibility_module.h:31
st_compatibility_types * joiner_compatibility_status
The status of this member when it joins.
Definition: gcs_event_handlers.h:305
Group_member_status
Definition: member_info.h:154
Definition: recovery.h:44
Definition: compatibility_module.h:39
This is the base GCS plugin message.
Definition: gcs_plugin_messages.h:63
Recovery_module * recovery_module
Definition: gcs_event_handlers.h:293
Class that represents the data that is exchanged within a group.
Definition: gcs_message.h:338
Definition: member_info.h:78
This class serves as data container for information flowing in the GCS ecosystem. ...
Definition: gcs_message.h:46
This interface is implemented by those who wish to receive messages.
Definition: gcs_communication_event_listener.h:35
std::set< Group_member_info *, Group_member_info_pointer_comparator > * temporary_states
Definition: gcs_event_handlers.h:300
This interface is implemented by those who wish to receive Control Interface notifications.
Definition: gcs_control_event_listener.h:51
ulong stop_wait_timeout
Definition: gcs_event_handlers.h:308
bool set_number_of_members_on_view_changed_to_10
Definition: gcs_event_handlers.h:311
Applier_module_interface * applier_module
Definition: gcs_event_handlers.h:292
enum_primary_election_mode
Enum for election types.
Definition: primary_election_include.h:32
Notification_context m_notification_ctx
The notification context for the GCS delivery thread.
Definition: gcs_event_handlers.h:315
It represents the identity of a group member within a certain group.
Definition: gcs_member_identifier.h:39
This represents the membership view that a member has from a group.
Definition: gcs_view.h:54
Compatibility_module * compatibility_manager
Definition: gcs_event_handlers.h:302
Applier_module * applier_module
The plugin applier.
Definition: plugin.cc:78
A convenience context class used to share information between the event handlers and the notifier...
Definition: notification.h:34
bool operator()(Group_member_info *one, Group_member_info *other) const
Definition: gcs_event_handlers.h:47
Definition: applier.h:239
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:39
Group_member_info_pointer_comparator to guarantee uniqueness.
Definition: gcs_event_handlers.h:46
Definition: gcs_event_handlers.h:57
static STATUS status
Definition: mysql.cc:198
A packet to send view change related info to the applier.
Definition: applier.h:90
bool has_lower_uuid(Group_member_info *other)
Return true if server uuid is lower than other member server uuid.
Definition: member_info.cc:741
Recovery_module * recovery_module
The plugin recovery module.
Definition: plugin.cc:80
void set_stop_wait_timeout(ulong timeout)
Sets the component stop timeout.
Definition: gcs_event_handlers.h:87