MySQL  8.0.22
Source Code Documentation
gcs_xcom_interface.h
Go to the documentation of this file.
1 /* Copyright (c) 2015, 2020, 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 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_XCOM_INTERFACE_INCLUDED
24 #define GCS_XCOM_INTERFACE_INCLUDED
25 
26 /*
27  This file is the main entry point for the gcs_interface implementation for
28  the XCom Group communication library.
29 */
30 
31 #include <cstdlib>
32 #include <ctime>
33 #include <map>
34 #include <string>
35 
49 
50 /**
51  * Keep track of the most recent XCom configuration the node will deliver
52  * upwards.
53  */
55  public:
57  /**
58  * Resets the object to its initial state.
59  */
60  void reset();
61  /**
62  * Updates this configuration's information.
63  *
64  * @param config_id the synod of the configuration
65  * @param xcom_nodes the XCom configuration's membership
66  * @param event_horizon the XCom configuration's event horizon
67  */
68  void update(synode_no config_id, Gcs_xcom_nodes const &xcom_nodes,
69  xcom_event_horizon event_horizon);
70  /**
71  * Checks whether this configuration pertains to a received XCom view, i.e.
72  * the configuration object is not in its initial state.
73  *
74  * @returns true if the configuration pertains to a received XCom view, false
75  * otherwise
76  */
77  bool has_view() const;
78  /**
79  * Checks whether this configuration's synod matches the the given synod.
80  *
81  * @param config_id the synod to compare against
82  * @returns true if the synods are the same, false otherwise
83  */
84  bool same_view(synode_no config_id) const;
85  /**
86  * Checks whether this configuration's membership matches the given
87  * membership.
88  *
89  * @param xcom_nodes the membership to compare against
90  * @returns true if the memberships are the same, false otherwise
91  */
92  bool same_xcom_nodes(Gcs_xcom_nodes const &xcom_nodes) const;
93  /**
94  * Checks whether this configuration's event horizon matches the given event
95  * horizon.
96  *
97  * @param event_horizon the event horizon to compare against
98  * @returns true if the event horizons are the same, false otherwise
99  */
100  bool same_event_horizon(xcom_event_horizon const &event_horizon) const;
101  /*
102  * This class will have a singleton object, so we delete the {copy,move}
103  * {constructor,assignment}. This way the compiler slaps us on the wrist if we
104  * attempt to copy or move the singleton.
105  */
106  Gcs_xcom_config(Gcs_xcom_config const &) = delete;
107  Gcs_xcom_config(Gcs_xcom_config &&) = delete;
108  Gcs_xcom_config &operator=(Gcs_xcom_config const &) = delete;
110 
111  private:
112  synode_no config_id_;
114  xcom_event_horizon event_horizon_;
115 };
116 
118 
119 /**
120  Struct that holds instances of this binding interface implementations.
121 */
122 typedef struct xcom_group_interfaces {
127 
128  /*
129  Additional storage of group interface auxiliary structures for later
130  deletion.
131  */
134 
136 
137 /**
138  Implementation of the Gcs_interface for the XCom binding.
139 */
141  private:
142  // XCom single instance
144 
145  /**
146  XCom binding private constructor.
147  */
148  explicit Gcs_xcom_interface();
149 
150  public:
151  /**
152  Since one wants that a single instance exists, the interface implementation
153  shall be retrieved via a Singleton pattern.
154 
155  This is the public method that allows the retrieving of the single
156  instance.
157 
158  @return a reference to the Singleton instance
159  */
160 
161  static Gcs_interface *get_interface();
162 
163  /**
164  Public method that finalizes and cleans the singleton.
165  */
166 
167  static void cleanup();
168 
169  /**
170  Public method that cleans thread-local resources related to communication.
171  Required when SSL is provided by OpenSSL.
172  */
173 
174  static void cleanup_thread_ssl_resources();
175 
176  ~Gcs_xcom_interface() override;
177 
178  /**
179  This block implements the virtual methods defined in Gcs_interface.
180  */
181 
183  const Gcs_interface_parameters &interface_params) override;
184 
185  enum_gcs_error configure(
186  const Gcs_interface_parameters &interface_params) override;
187 
188  bool is_initialized() override;
189 
190  enum_gcs_error finalize() override;
191 
192  Gcs_control_interface *get_control_session(
193  const Gcs_group_identifier &group_identifier) override;
194 
195  Gcs_communication_interface *get_communication_session(
196  const Gcs_group_identifier &group_identifier) override;
197 
198  Gcs_statistics_interface *get_statistics(
199  const Gcs_group_identifier &group_identifier) override;
200 
201  Gcs_group_management_interface *get_management_session(
202  const Gcs_group_identifier &group_identifier) override;
203 
204  enum_gcs_error configure_message_stages(const Gcs_group_identifier &gid);
205 
206  enum_gcs_error configure_suspicions_mgr(Gcs_interface_parameters &p,
208 
209  enum_gcs_error set_logger(Logger_interface *logger) override;
210 
211  void set_xcom_group_information(const std::string &group_id);
212 
213  Gcs_group_identifier *get_xcom_group_information(const u_long group_id);
214 
215  Gcs_xcom_node_address *get_node_address();
216 
217  void set_node_address(std::string const &address);
218 
219  /**
220  This member function shall return the set of parameters that configure
221  the interface at the time its initialization was done. The parameters
222  returned already contain default values set as well as values that may
223  have been fixed.
224 
225  @return The parameters configured at the time the interface was initialized.
226  */
228  return m_initialization_parameters;
229  }
230 
231  /**
232  Must return the allowlist.
233 
234  @return the list of allowlisted IP addresses and subnet masks.
235  */
237 
238  /*
239  Notify all controllers that XCOM's thread has finished.
240  */
241 
242  void process_xcom_exit();
243 
244  /**
245  Contains all the code needed to stop the xcom daemon if it was not
246  already stopped as it should have been done.
247  */
248 
249  void finalize_xcom();
250 
251  /**
252  Makes GCS leave the group when an error has caused XCom to terminate
253  unexpectedly.
254  */
255  void make_gcs_leave_group_on_error();
256 
257  /**
258  Used to initialize SSL assuming that the necessary parameters have already
259  been read.
260  */
261  void initialize_ssl();
262 
263  /**
264  Used to initialize the unique identifier of the XCom instance.
265 
266  @param node_information Information about the XCom node
267  @param xcom_proxy XCom proxy
268  @retval true if there was an error initialising the XCom identity
269  @retval false if operation was successful
270  */
271  bool set_xcom_identity(Gcs_xcom_node_information const &node_information,
272  Gcs_xcom_proxy &xcom_proxy);
273 
274  private:
275  /**
276  Method to initialize the logging and debugging systems. If something
277  bad happens, an error is returned.
278 
279 
280  @param[in] debug_file File where the debug information on GCS will
281  be stored to
282  @param[in] debug_path Default path where the debug information on GCS
283  will be stored to
284  */
285 
286  enum_gcs_error initialize_logging(const std::string *debug_file,
287  const std::string *debug_path);
288 
289  /**
290  Method to finalize the logging and debugging systems. If something
291  bad happens, an error is returned.
292  */
293 
294  enum_gcs_error finalize_logging();
295 
296  /**
297  Internal helper method that retrieves all group interfaces for a certain
298  group.
299 
300  @note Since the group interfaces work as a singleton, meaning that a group
301  has a single set of interfaces built, this method will also implement the
302  behavior to build and initialize the interfaces implementation.
303 
304  @param[in] group_identifier the group in which one wants to instantiate the
305  interface implementation
306 
307  @return a reference to a struct gcs_xcom_group_interfaces
308  */
309 
310  gcs_xcom_group_interfaces *get_group_interfaces(
311  const Gcs_group_identifier &group_identifier);
312 
313  /**
314  Contains all the code needed to initialize a connection to the xcom
315  daemon.
316 
317  @return true in case of error
318  */
319 
320  bool initialize_xcom(const Gcs_interface_parameters &interface_params);
321 
322  /**
323  Internal helper method to delete all previously created group interfaces.
324  */
325 
326  void clean_group_interfaces();
327 
328  /**
329  Internal helper method to delete all previously created group references.
330  */
331 
332  void clean_group_references();
333 
334  /**
335  Helper used to parse the peer_nodes parameter and to initialize XCom peer
336  nodes.
337 
338  @param[in] peer_nodes received parameter with the addresses of all peer
339  nodes
340  */
341 
342  void initialize_peer_nodes(const std::string *peer_nodes);
343 
344  /**
345  Helper used to delete the existing XCom peer nodes in m_xcom_peers and to
346  clear that vector.
347  */
348 
349  void clear_peer_nodes();
350 
351  // Holder to the created group interfaces, in which the key is the group
352  std::map<std::string, gcs_xcom_group_interfaces *> m_group_interfaces;
353 
354  std::map<u_long, Gcs_group_identifier *> m_xcom_configured_groups;
355 
356  /*
357  The address associated with the current node.
358  */
360 
361  /*
362  The addresses associated with current node's peers.
363  */
364  std::vector<Gcs_xcom_node_address *> m_xcom_peers;
365 
366  // States if this interface is initialized
368 
369  bool m_boot;
370 
372 
373  /**
374  The C++ interface to setup and configure xcom properties
375  from GCS. Under the hood, this changes the C structure that
376  holds the configuration for XCom.
377 
378  (As XCom moves into C++, we can replace XCom's internal
379  structure with a similar object and remove it from this
380  place.)
381  */
383 
384  /**
385  The initialization parameters provided through the initialize member
386  function.
387  */
389 
390  // Store pointer to default sink
392 
393  // Store pointer to default logger
395 
396  // Store pointer to default debugger
398 
399  /**
400  The IP allowlist.
401  */
403 
404  /**
405  Indicates whether SSL has been initialized and if that initialization was
406  successful.
407  */
409 
410  /// protects the m_ssl_init_state thread shared variable
413 
414  private:
415  /*
416  Disabling the copy constructor and assignment operator.
417  */
420 };
421 
422 int cb_xcom_match_port(xcom_port if_port);
423 
424 #endif /* GCS_XCOM_INTERFACE_INCLUDED */
Gcs_ip_allowlist m_ip_allowlist
The IP allowlist.
Definition: gcs_xcom_interface.h:402
This interface represents all statistics that a binding implementation should provide.
Definition: gcs_statistics_interface.h:32
This interface must be implemented by all specific binding implementations as its entry point...
Definition: gcs_interface.h:81
Implementation of the Gcs_interface for the XCom binding.
Definition: gcs_xcom_interface.h:140
This class is to be used to provide parameters to bindings in a transparent and generic way...
Definition: gcs_types.h:58
struct xcom_group_interfaces gcs_xcom_group_interfaces
Struct that holds instances of this binding interface implementations.
It represents a node within a group and is identified by the member identifier, unique identifier and...
Definition: gcs_xcom_group_member_information.h:192
Keep track of the most recent XCom configuration the node will deliver upwards.
Definition: gcs_xcom_interface.h:54
Gcs_async_buffer * m_default_sink
Definition: gcs_xcom_interface.h:391
Definition: my_xp_cond.h:133
bool same_event_horizon(xcom_event_horizon const &event_horizon) const
Checks whether this configuration&#39;s event horizon matches the given event horizon.
Definition: gcs_xcom_interface.cc:93
std::map< u_long, Gcs_group_identifier * > m_xcom_configured_groups
Definition: gcs_xcom_interface.h:354
static Gcs_interface * interface_reference_singleton
Definition: gcs_xcom_interface.h:143
enum_gcs_error
This enumeration describes errors which can occur during group communication operations.
Definition: gcs_types.h:40
Gcs_xcom_app_cfg m_gcs_xcom_app_cfg
The C++ interface to setup and configure xcom properties from GCS.
Definition: gcs_xcom_interface.h:382
Gcs_default_debugger * m_default_debugger
Definition: gcs_xcom_interface.h:397
My_xp_mutex_impl m_wait_for_ssl_init_mutex
Definition: gcs_xcom_interface.h:412
bool initialize(THD *thd)
Initialize the dictionary while starting the server for the first time.
Definition: bootstrapper.cc:877
bool m_is_initialized
Definition: gcs_xcom_interface.h:367
xcom_event_horizon event_horizon_
Definition: gcs_xcom_interface.h:114
unsigned short xcom_port
Definition: xcom_common.h:45
This class stores all node suspicions, as well as the timeout and period parameters used by the threa...
Definition: gcs_xcom_control_interface.h:67
Struct that holds instances of this binding interface implementations.
Definition: gcs_xcom_interface.h:122
Gcs_xcom_state_exchange_interface * se
Definition: gcs_xcom_interface.h:133
const Gcs_interface_parameters & get_initialization_parameters()
This member function shall return the set of parameters that configure the interface at the time its ...
Definition: gcs_xcom_interface.h:227
Gcs_xcom_node_address * m_node_address
Definition: gcs_xcom_interface.h:359
Interface for socket utility methods.
Definition: my_xp_util.h:153
bool same_xcom_nodes(Gcs_xcom_nodes const &xcom_nodes) const
Checks whether this configuration&#39;s membership matches the given membership.
Definition: gcs_xcom_interface.cc:79
synode_no config_id_
Definition: gcs_xcom_interface.h:112
Definition: gcs_xcom_proxy.h:49
This interface represents all the communication facilities that a binding implementation should provi...
Definition: gcs_communication_interface.h:87
My_xp_socket_util * m_socket_util
Definition: gcs_xcom_interface.h:371
Gcs_statistics_interface * statistics_interface
Definition: gcs_xcom_interface.h:125
std::map< std::string, gcs_xcom_group_interfaces * > m_group_interfaces
Definition: gcs_xcom_interface.h:352
void update(synode_no config_id, Gcs_xcom_nodes const &xcom_nodes, xcom_event_horizon event_horizon)
Updates this configuration&#39;s information.
Definition: gcs_xcom_interface.cc:65
Logger interface that must be used to define a logger object.
Definition: gcs_logging.h:123
Gcs_control_interface * control_interface
Definition: gcs_xcom_interface.h:123
static const char * get_ip_allowlist()
Definition: plugin.cc:194
Gcs_xcom_view_change_control_interface * vce
Definition: gcs_xcom_interface.h:132
Circular buffer that can be used to asynchronously feed a sink.
Definition: gcs_logging_system.h:190
bool m_boot
Definition: gcs_xcom_interface.h:369
int cb_xcom_match_port(xcom_port if_port)
Definition: gcs_xcom_interface.cc:1531
bool same_view(synode_no config_id) const
Checks whether this configuration&#39;s synod matches the the given synod.
Definition: gcs_xcom_interface.cc:75
My_xp_cond_impl m_wait_for_ssl_init_cond
protects the m_ssl_init_state thread shared variable
Definition: gcs_xcom_interface.h:411
Gcs_group_management_interface * management_interface
Definition: gcs_xcom_interface.h:126
Stores connection information associated with a node.
Definition: gcs_xcom_group_member_information.h:50
This class contains information on the configuration, i.e set of nodes or simply site definition...
Definition: gcs_xcom_group_member_information.h:390
std::atomic< bool > is_initialized(false)
Default debugger which is used only by GCS and XCOM.
Definition: gcs_logging_system.h:509
static struct ifaddrs * get_interface(sock_probe *s, int count)
Definition: sock_probe_ix.cc:118
Definition: gcs_xcom_networking.h:254
bool has_view() const
Checks whether this configuration pertains to a received XCom view, i.e.
Definition: gcs_xcom_interface.cc:73
Gcs_xcom_nodes xcom_nodes_
Definition: gcs_xcom_interface.h:113
static Logger logger
The "top-level" logger used when no connection context is given.
Definition: test_trace_plugin.cc:293
std::vector< Gcs_xcom_node_address * > m_xcom_peers
Definition: gcs_xcom_interface.h:364
void reset()
Resets the object to its initial state.
Definition: gcs_xcom_interface.cc:59
int m_ssl_init_state
Indicates whether SSL has been initialized and if that initialization was successful.
Definition: gcs_xcom_interface.h:408
Logger_interface * m_default_logger
Definition: gcs_xcom_interface.h:394
Definition: gcs_xcom_state_exchange.h:715
Gcs_interface_parameters m_initialization_parameters
The initialization parameters provided through the initialize member function.
Definition: gcs_xcom_interface.h:388
Definition: my_xp_mutex.h:120
const char * p
Definition: ctype-mb.cc:1235
__u_long u_long
Definition: types.h:73
Definition: gcs_xcom_state_exchange.h:369
This represents the unique identification of a group.
Definition: gcs_group_identifier.h:34
Definition: gcs_group_management_interface.h:28
A Gcs_xcom_interface needs to have an instance of this class initialized before engaging XCom...
Definition: gcs_xcom_proxy.h:1000
This interface represents all the control functionalities that a binding implementation must provide...
Definition: gcs_control_interface.h:110
Gcs_xcom_config & operator=(Gcs_xcom_config const &)=delete
Gcs_xcom_config()
Definition: gcs_xcom_interface.cc:56
Gcs_communication_interface * communication_interface
Definition: gcs_xcom_interface.h:124