MySQL 8.4.0
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
52
53/**
54 * Keep track of the most recent XCom configuration the node will deliver
55 * upwards.
56 */
58 public:
60 /**
61 * Resets the object to its initial state.
62 */
63 void reset();
64 /**
65 * Updates this configuration's information.
66 *
67 * @param config_id the synod of the configuration
68 * @param xcom_nodes the XCom configuration's membership
69 * @param event_horizon the XCom configuration's event horizon
70 */
71 void update(synode_no config_id, Gcs_xcom_nodes const &xcom_nodes,
72 xcom_event_horizon event_horizon);
73 /**
74 * Checks whether this configuration pertains to a received XCom view, i.e.
75 * the configuration object is not in its initial state.
76 *
77 * @returns true if the configuration pertains to a received XCom view, false
78 * otherwise
79 */
80 bool has_view() const;
81 /**
82 * Checks whether this configuration's synod matches the the given synod.
83 *
84 * @param config_id the synod to compare against
85 * @returns true if the synods are the same, false otherwise
86 */
87 bool same_view(synode_no config_id) const;
88 /**
89 * Checks whether this configuration's membership matches the given
90 * membership.
91 *
92 * @param xcom_nodes the membership to compare against
93 * @returns true if the memberships are the same, false otherwise
94 */
95 bool same_xcom_nodes(Gcs_xcom_nodes const &xcom_nodes) const;
96 /**
97 * Checks whether this configuration's event horizon matches the given event
98 * horizon.
99 *
100 * @param event_horizon the event horizon to compare against
101 * @returns true if the event horizons are the same, false otherwise
102 */
103 bool same_event_horizon(xcom_event_horizon const &event_horizon) const;
104 /**
105 * Checks whether this configuration's membership matches the given
106 * membership.
107 *
108 * @param xcom_nodes the membership to compare against
109 * @returns true if the memberships are the same, false otherwise
110 */
111 bool same_xcom_nodes_v3(Gcs_xcom_nodes const &xcom_nodes) const;
112 /*
113 * This class will have a singleton object, so we delete the {copy,move}
114 * {constructor,assignment}. This way the compiler slaps us on the wrist if we
115 * attempt to copy or move the singleton.
116 */
121
122 private:
123 synode_no config_id_;
125 xcom_event_horizon event_horizon_;
126};
127
129
130/**
131 Struct that holds instances of this binding interface implementations.
132*/
133typedef struct xcom_group_interfaces {
138
139 /*
140 Additional storage of group interface auxiliary structures for later
141 deletion.
142 */
145
147
148/**
149 Implementation of the Gcs_interface for the XCom binding.
150*/
152 private:
153 // XCom single instance
155
156 /**
157 XCom binding private constructor.
158 */
159 explicit Gcs_xcom_interface();
160
161 public:
162 /**
163 Since one wants that a single instance exists, the interface implementation
164 shall be retrieved via a Singleton pattern.
165
166 This is the public method that allows the retrieving of the single
167 instance.
168
169 @return a reference to the Singleton instance
170 */
171
173
174 /**
175 Public method that finalizes and cleans the singleton.
176 */
177
178 static void cleanup();
179
180 /**
181 Public method that cleans thread-local resources related to communication.
182 Required when SSL is provided by OpenSSL.
183 */
184
185 static void cleanup_thread_ssl_resources();
186
188
189 /**
190 This block implements the virtual methods defined in Gcs_interface.
191 */
192
194 const Gcs_interface_parameters &interface_params) override;
195
197 const Gcs_interface_parameters &interface_params) override;
198
199 bool is_initialized() override;
200
201 enum_gcs_error finalize() override;
202
204 const Gcs_group_identifier &group_identifier) override;
205
207 const Gcs_group_identifier &group_identifier) override;
208
210 const Gcs_group_identifier &group_identifier) override;
211
213 const Gcs_group_identifier &group_identifier) override;
214
216
219
221
222 void set_xcom_group_information(const std::string &group_id);
223
225
227
228 void set_node_address(std::string const &address);
229
230 /**
231 * @see Gcs_interface#setup_runtime_resources
232 */
235
236 /**
237 * @see Gcs_interface#cleanup_runtime_resources
238 */
241
242 /**
243 This member function shall return the set of parameters that configure
244 the interface at the time its initialization was done. The parameters
245 returned already contain default values set as well as values that may
246 have been fixed.
247
248 @return The parameters configured at the time the interface was initialized.
249 */
252 }
253
254 /**
255 Must return the allowlist.
256
257 @return the list of allowlisted IP addresses and subnet masks.
258 */
260
261 /*
262 Notify all controllers that XCOM's thread has finished.
263 */
264
266
267 /**
268 Contains all the code needed to stop the xcom daemon if it was not
269 already stopped as it should have been done.
270 */
271
272 void finalize_xcom();
273
274 /**
275 Makes GCS leave the group when an error has caused XCom to terminate
276 unexpectedly.
277 */
279
280 /**
281 Used to initialize SSL assuming that the necessary parameters have already
282 been read.
283 */
284 void initialize_ssl();
285
286 /**
287 Used to initialize the unique identifier of the XCom instance.
288
289 @param node_information Information about the XCom node
290 @param xcom_proxy XCom proxy
291 @retval true if there was an error initialising the XCom identity
292 @retval false if operation was successful
293 */
294 bool set_xcom_identity(Gcs_xcom_node_information const &node_information,
295 Gcs_xcom_proxy &xcom_proxy);
296
297 private:
298 /**
299 Method to initialize the logging and debugging systems. If something
300 bad happens, an error is returned.
301
302
303 @param[in] debug_file File where the debug information on GCS will
304 be stored to
305 @param[in] debug_path Default path where the debug information on GCS
306 will be stored to
307 */
308
309 enum_gcs_error initialize_logging(const std::string *debug_file,
310 const std::string *debug_path);
311
312 /**
313 Method to finalize the logging and debugging systems. If something
314 bad happens, an error is returned.
315 */
316
318
319 /**
320 Internal helper method that retrieves all group interfaces for a certain
321 group.
322
323 @note Since the group interfaces work as a singleton, meaning that a group
324 has a single set of interfaces built, this method will also implement the
325 behavior to build and initialize the interfaces implementation.
326
327 @param[in] group_identifier the group in which one wants to instantiate the
328 interface implementation
329
330 @return a reference to a struct gcs_xcom_group_interfaces
331 */
332
334 const Gcs_group_identifier &group_identifier);
335
336 /**
337 Contains all the code needed to initialize a connection to the xcom
338 daemon.
339
340 @return true in case of error
341 */
342
343 bool initialize_xcom(const Gcs_interface_parameters &interface_params);
344
345 /**
346 Internal helper method to delete all previously created group interfaces.
347 */
348
350
351 /**
352 Internal helper method to delete all previously created group references.
353 */
354
356
357 /**
358 Helper used to parse the peer_nodes parameter and to initialize XCom peer
359 nodes.
360
361 @param[in] peer_nodes received parameter with the addresses of all peer
362 nodes
363 */
364
365 void initialize_peer_nodes(const std::string *peer_nodes);
366
367 /**
368 Helper used to delete the existing XCom peer nodes in m_xcom_peers and to
369 clear that vector.
370 */
371
372 void clear_peer_nodes();
373
374 /**
375 * @brief Announces that a finalize was called to all group instances that
376 * use a Gcs_xcom_view_change_control_interface. The purpose of this
377 * is to end any ongoing tasks, like pending joins.
378 */
380
381 // Holder to the created group interfaces, in which the key is the group
382 std::map<std::string, gcs_xcom_group_interfaces *> m_group_interfaces;
383
384 std::map<u_long, Gcs_group_identifier *> m_xcom_configured_groups;
385
386 /*
387 The address associated with the current node.
388 */
390
391 /*
392 The addresses associated with current node's peers.
393 */
394 std::vector<Gcs_xcom_node_address *> m_xcom_peers;
395
396 // States if this interface is initialized
398
399 bool m_boot;
400
402
403 /**
404 The C++ interface to setup and configure xcom properties
405 from GCS. Under the hood, this changes the C structure that
406 holds the configuration for XCom.
407
408 (As XCom moves into C++, we can replace XCom's internal
409 structure with a similar object and remove it from this
410 place.)
411 */
413
414 /**
415 The initialization parameters provided through the initialize member
416 function.
417 */
419
420 // Store pointer to default sink
422
423 // Store pointer to default logger
425
426 // Store pointer to default debugger
428
429 /**
430 The IP allowlist.
431 */
433
434 /**
435 Indicates whether SSL has been initialized and if that initialization was
436 successful.
437 */
439
440 /// protects the m_ssl_init_state thread shared variable
443
444 /**
445 Network namespace service provider
446 */
448
449 /**
450 Interface for statistic storage
451 */
453
454 /**
455 Interface for XCom statistic storage
456 */
458
459 private:
460 /*
461 Disabling the copy constructor and assignment operator.
462 */
465};
466
467int cb_xcom_match_port(xcom_port if_port);
468
469#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:49
This class stores all node suspicions, as well as the timeout and period parameters used by the threa...
Definition: gcs_xcom_control_interface.h:70
A Gcs_xcom_interface needs to have an instance of this class initialized before engaging XCom.
Definition: gcs_xcom_proxy.h:1046
Keep track of the most recent XCom configuration the node will deliver upwards.
Definition: gcs_xcom_interface.h:57
synode_no config_id_
Definition: gcs_xcom_interface.h:123
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:125
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:124
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:151
Gcs_async_buffer * m_default_sink
Definition: gcs_xcom_interface.h:421
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:748
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:438
Gcs_default_debugger * m_default_debugger
Definition: gcs_xcom_interface.h:427
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:733
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:831
static Gcs_interface * interface_reference_singleton
Definition: gcs_xcom_interface.h:154
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:718
Gcs_xcom_statistics_manager_interface * m_stats_mgr
Interface for statistic storage.
Definition: gcs_xcom_interface.h:452
bool m_is_initialized
Definition: gcs_xcom_interface.h:397
Network_namespace_manager * m_netns_manager
Network namespace service provider.
Definition: gcs_xcom_interface.h:447
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:656
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:873
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:725
Gcs_group_identifier * get_xcom_group_information(const u_long group_id)
Definition: gcs_xcom_interface.cc:1189
Gcs_ip_allowlist & get_ip_allowlist()
Must return the allowlist.
Definition: gcs_xcom_interface.cc:1345
enum_gcs_error cleanup_runtime_resources(Gcs_interface_runtime_requirements &reqs) override
Definition: gcs_xcom_interface.cc:844
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:897
~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:1147
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:916
enum_gcs_error finalize() override
Method used by a binding implementation in order to implement any internal shutdown procedure.
Definition: gcs_xcom_interface.cc:662
Gcs_xcom_node_address * m_node_address
Definition: gcs_xcom_interface.h:389
Gcs_ip_allowlist m_ip_allowlist
The IP allowlist.
Definition: gcs_xcom_interface.h:432
bool m_boot
Definition: gcs_xcom_interface.h:399
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:618
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:639
My_xp_mutex_impl m_wait_for_ssl_init_mutex
Definition: gcs_xcom_interface.h:442
bool is_initialized() override
Method used to report if the binding interface has already been initialized.
Definition: gcs_xcom_interface.cc:716
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:827
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:384
std::vector< Gcs_xcom_node_address * > m_xcom_peers
Definition: gcs_xcom_interface.h:394
My_xp_cond_impl m_wait_for_ssl_init_cond
protects the m_ssl_init_state thread shared variable
Definition: gcs_xcom_interface.h:441
void set_node_address(std::string const &address)
Definition: gcs_xcom_interface.cc:1214
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:424
Gcs_xcom_statistics_storage_impl * m_xcom_stats_storage
Interface for XCom statistic storage.
Definition: gcs_xcom_interface.h:457
Gcs_xcom_node_address * get_node_address()
Definition: gcs_xcom_interface.cc:1209
int m_ssl_init_state
Indicates whether SSL has been initialized and if that initialization was successful.
Definition: gcs_xcom_interface.h:438
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:741
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:412
Gcs_interface_parameters m_initialization_parameters
The initialization parameters provided through the initialize member function.
Definition: gcs_xcom_interface.h:418
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:250
void clean_group_interfaces()
Internal helper method to delete all previously created group interfaces.
Definition: gcs_xcom_interface.cc:855
void set_xcom_group_information(const std::string &group_id)
Definition: gcs_xcom_interface.cc:1170
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:1163
My_xp_socket_util * m_socket_util
Definition: gcs_xcom_interface.h:401
enum_gcs_error configure_message_stages(const Gcs_group_identifier &gid)
Definition: gcs_xcom_interface.cc:1220
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:1300
std::map< std::string, gcs_xcom_group_interfaces * > m_group_interfaces
Definition: gcs_xcom_interface.h:382
void initialize_ssl()
Used to initialize SSL assuming that the necessary parameters have already been read.
Definition: gcs_xcom_interface.cc:890
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:53
Definition: gcs_xcom_state_exchange.h:370
This class is the storage and provider of all statistics coming from either XCom and GCS.
Definition: gcs_xcom_statistics_manager.h:65
GCS implementation of the statistics storage of XCom.
Definition: gcs_xcom_statistics_storage_impl.h:35
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:242
const char * p
Definition: ctype-mb.cc:1235
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:1724
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:133
Gcs_statistics_interface * statistics_interface
Definition: gcs_xcom_interface.h:136
Gcs_group_management_interface * management_interface
Definition: gcs_xcom_interface.h:137
Gcs_xcom_state_exchange_interface * se
Definition: gcs_xcom_interface.h:144
Gcs_control_interface * control_interface
Definition: gcs_xcom_interface.h:134
Gcs_xcom_view_change_control_interface * vce
Definition: gcs_xcom_interface.h:143
Gcs_communication_interface * communication_interface
Definition: gcs_xcom_interface.h:135
__u_long u_long
Definition: types.h:74
unsigned short xcom_port
Definition: xcom_common.h:46