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