MySQL 8.0.40
Source Code Documentation
gcs_xcom_group_member_information.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_XCOM_GROUP_MEMBER_INFORMATION_INCLUDED
25#define GCS_XCOM_GROUP_MEMBER_INFORMATION_INCLUDED
26
27#include <stdint.h>
28#include <string>
29
46#include "plugin/group_replication/libmysqlgcs/xdr_gen/xcom_vp.h"
47
48/**
49 Stores connection information associated with a node.
50*/
52 public:
53 /**
54 Gcs_xcom_node_address constructor.
55 */
56
57 explicit Gcs_xcom_node_address(std::string member_address);
58
60
61 /**
62 Return address using the format ip:port.
63 */
64
65 std::string &get_member_address();
66
67 /**
68 Return the IP address.
69 */
70
71 std::string &get_member_ip();
72
73 /**
74 Return the port number.
75 */
76
78
79 /**
80 Return an internal representation.
81 */
82
83 std::string *get_member_representation() const;
84
85 /**
86 A Gcs_xcom_node_address holds the representation IP:PORT of an XCom node.
87 It is initialized with default values for IP = null and PORT = 0.
88
89 This method checks if this address contains valid values after a successful
90 initialization or if it still contains the default ones.
91
92 @return true if this contains values other than the default values
93 */
94 bool is_valid() const;
95
96 private:
97 /*
98 Member's address.
99 */
100 std::string m_member_address;
101
102 /*
103 Member's IP.
104 */
105 std::string m_member_ip;
106
107 /*
108 Member's port.
109 */
111};
112
113/*
114 Internal GCS unique identifier.
115*/
117 public:
118 /*
119 Default constructor.
120 */
121 Gcs_xcom_uuid() = default;
122
123 /*
124 Constructor from a string that represents the uuid in use.
125 */
126 explicit Gcs_xcom_uuid(const std::string xcom_uuid) noexcept
127 : actual_value(xcom_uuid) {}
128
129 /*
130 Create a GCS unique identifier.
131 */
132
133 static Gcs_xcom_uuid create_uuid();
134
135 /*
136 Copies the internal buffer which is used to store a uuid to an
137 external buffer. If the parameters buffer or size point to NULL,
138 nothing is returned.
139
140 @param [out] buffer storage buffer
141 @param [out] size data size
142 @return Whether the data was returned or not.
143 */
144
145 bool encode(uchar **buffer, unsigned int *size) const;
146
147 /*
148 Copies the external buffer to an internal buffer. If the
149 parameter buffer points to NULL, nothing is returned.
150
151 @param [in] buffer storage buffer
152 @param [in] size data size
153 @return Whether the data was copied or not.
154 */
155
156 bool decode(const uchar *buffer, const unsigned int size);
157
158 /**
159 Converts this UUID into its corresponding XCom blob type.
160
161 @retval {true, _} if there was an error creating the blob
162 @retval {false, blob} if the blob was created successfully
163 */
164 std::pair<bool, blob> make_xcom_blob() const;
165
166 /*
167 Unique identifier which currently only accommodates 64 bits but
168 can easily be extended to 128 bits and become a truly UUID in
169 the future.
170 */
171
172 std::string actual_value;
173};
174
175class Gcs_xcom_proxy;
176
177/**
178 @class Gcs_xcom_node_information
179
180 It represents a node within a group and is identified by the member
181 identifier, unique identifier and node number. Users are responsible
182 for guaranteeing that they are related to the same node.
183
184 One should avoid creating this representation from outside the binding,
185 since each one might have its own internal representations. Instead
186 one should use the Gcs_control_interface::get_local_information method
187 to know our own identification within the group.
188
189 Note also that it is possible to use the copy constructor and assignment
190 operator and these properties are required by several other classes such
191 as the Gcs_xcom_nodes.
192 */
194 public:
195 /**
196 Gcs_xcom_node_information constructor.
197
198 @param[in] member_id the member identifier
199 @param[in] alive whether the node is alive or not.
200 */
201
202 explicit Gcs_xcom_node_information(const std::string &member_id,
203 bool alive = true);
204
205 /**
206 Gcs_xcom_node_information constructor.
207
208 @param[in] member_id the member identifier
209 @param[in] uuid the member uuid
210 @param[in] node_no the member node number
211 @param[in] alive whether the node is alive or not.
212 */
213
214 explicit Gcs_xcom_node_information(const std::string &member_id,
215 const Gcs_xcom_uuid &uuid,
216 const unsigned int node_no,
217 const bool alive);
218
219 virtual ~Gcs_xcom_node_information() = default;
222 default;
223
224 /**
225 Sets the timestamp to indicate the creation of the suspicion.
226 */
227
228 void set_suspicion_creation_timestamp(uint64_t ts);
229
230 /**
231 Gets the timestamp that indicates the creation of the suspicion.
232 */
233
234 uint64_t get_suspicion_creation_timestamp() const;
235
236 /**
237 Compares the object's timestamp with the received one, in order
238 to check if the suspicion has timed out and the suspect node
239 must be removed.
240
241 @param[in] ts Provided timestamp
242 @param[in] timeout Provided timeout
243 @return Indicates if the suspicion has timed out
244 */
245
246 bool has_timed_out(uint64_t ts, uint64_t timeout);
247
248 /**
249 @return the member identifier
250 */
251
253
254 /**
255 @return the member uuid
256 */
257
258 const Gcs_xcom_uuid &get_member_uuid() const;
259
260 /**
261 Regenerate the member uuid.
262 */
263
265
266 /**
267 Set the member node_no.
268 */
269
270 void set_node_no(unsigned int);
271
272 /**
273 Return member node_no.
274 */
275
276 unsigned int get_node_no() const;
277
278 /**
279 Get whether the member is alive or not.
280 */
281
282 bool is_alive() const;
283
284 /**
285 Get whether the node is already a member of the group or not.
286 */
287
288 bool is_member() const;
289
290 /**
291 Set whether the node is already a member of the group or not.
292 */
293
294 void set_member(bool m);
295
296 /**
297 Get whether the local XCom cache has removed messages that the remote
298 node represented by this object has missed. When this happens, the remote
299 node will no longer be able to recover the missed messages from the local
300 node and a corresponding message will be printed to the local node's error
301 log. The message will only be printed the first time a missed message is
302 lost.
303
304 */
305 bool has_lost_messages() const;
306
307 /**
308 Set whether the local XCom cache has removed messages that the node has
309 missed.
310 */
311 void set_lost_messages(bool lost_msgs);
312
313 /**
314 Gets the highest synode_no known by the group when the node became
315 unreachable.
316 */
317 synode_no get_max_synode() const;
318
319 /**
320 Sets the highest synode_no known by the group when the node became
321 unreachable.
322 */
323 void set_max_synode(synode_no synode);
324
325 /**
326 Converts this node information into its corresponding XCom node_address type.
327
328 @param xcom_proxy XCom proxy
329 @retval {true, nullptr} if there was an error creating the node_address
330 @retval {false, node_address*} if the node_address was successfully created
331 */
332
333 std::pair<bool, node_address *> make_xcom_identity(
334 Gcs_xcom_proxy &xcom_proxy) const;
335
336 private:
338
339 /**
340 Member unique identifier.
341 */
343
344 /**
345 Member node_no.
346 */
347 unsigned int m_node_no;
348
349 /**
350 Whether the member is alive or dead.
351 */
353
354 /**
355 Whether the node is a member of the group or not.
356 */
358
359 /**
360 Stores the timestamp of the creation of the suspicion.
361 */
363
364 /**
365 Indicates whether the local XCom cache has removed messages that the remote
366 node represented by this object has missed. Used to avoid printing the
367 corresponding error message more than once.
368 */
370
371 /**
372 The highest synode known by the group when the node became unreachable.
373 */
374 synode_no m_max_synode;
375};
376
377/**
378 This class contains information on the configuration, i.e set of nodes
379 or simply site definition.
380
381 Users are responsible for guaranteeing that information encapsulated
382 by different Gcs_xcom_nodes is properly defined. In the sense that
383 the member identifier, the unique identifier and the address uniquely
384 identify a node and the same holds for any combination of those three.
385
386 Nodes inserted in this set are copied and stored in a vector object.
387 Currently, we don't check whether the same node is inserted twice or
388 not and as such duplicated entries are allowed. Users are responsible
389 for guaranteeing that duplicated entries are not inserted.
390*/
392 public:
393 /**
394 Constructor that reads the site definition and whether a node
395 is considered dead or alive to build a list of addresses and
396 statuses.
397 */
398
399 explicit Gcs_xcom_nodes();
400
401 /**
402 Constructor that reads the site definition and whether a node
403 is considered dead or alive to build a list of addresses and
404 statuses.
405 */
406
407 explicit Gcs_xcom_nodes(const site_def *site, node_set &nodes);
408
409 /**
410 Destructor for Gcs_xcom_nodes.
411 */
412
413 virtual ~Gcs_xcom_nodes();
414
415 /*
416 Set the index of the current node (i.e. member);
417 */
418
419 void set_node_no(unsigned int node_no);
420
421 /**
422 Return the index of the current node (i.e. member).
423 */
424
425 unsigned int get_node_no() const;
426
427 /**
428 Return with the configuration is valid or not.
429 */
430
431 inline bool is_valid() const {
432 /*
433 Unfortunately a node may get notifications even when its configuration
434 inside XCOM is not properly established and this may trigger view
435 changes and may lead to problems because the node is not really ready.
436
437 We detect this fact by checking the node identification is valid.
438 */
439 return m_node_no != VOID_NODE_NO;
440 }
441
442 /**
443 Return a reference to the addresses' vector.
444 */
445
446 const std::vector<Gcs_xcom_node_information> &get_nodes() const;
447
448 /**
449 Return a pointer to a node if it exists, otherwise NULL.
450 */
451
453 const Gcs_member_identifier &member_id) const;
454
455 /**
456 Return a pointer to a node if it exists, otherwise NULL.
457 */
458
459 const Gcs_xcom_node_information *get_node(const std::string &member_id) const;
460
461 /**
462 Return a pointer to a node if it exists, otherwise NULL.
463 */
464
465 const Gcs_xcom_node_information *get_node(unsigned int node_no) const;
466
467 /**
468 Return a pointer to a node if it exists, otherwise NULL.
469 */
470
471 const Gcs_xcom_node_information *get_node(const Gcs_xcom_uuid &uuid) const;
472
473 /**
474 Add a node to the set of nodes. Note that the method does not
475 verify if the node already exists.
476 */
477
478 void add_node(const Gcs_xcom_node_information &node);
479
480 /**
481 Remove a node from the set of nodes.
482
483 @param node Node to be removed from the set of nodes.
484 */
485
486 void remove_node(const Gcs_xcom_node_information &node);
487
488 /**
489 Clear up the current set and add a new set of nodes.
490
491 @param xcom_nodes Set of nodes.
492 */
493
494 void add_nodes(const Gcs_xcom_nodes &xcom_nodes);
495
496 /**
497 Clear the set of nodes.
498 */
499
500 void clear_nodes();
501
502 /**
503 Return the number of nodes in the set.
504 */
505
506 unsigned int get_size() const;
507
508 /**
509 Whether the set of nodes is empty or not.
510 */
511
512 bool empty() const;
513
514 /**
515 Encode the information on the set of nodes in a format that can be
516 interpreted by XCOM to boot, add or remove nodes.
517 */
518
519 bool encode(unsigned int *ptr_size, char const ***ptr_addrs,
520 blob **ptr_uuids);
521
522 private:
523 /*
524 Free memory allocated to encode the object.
525 */
526
527 void free_encode();
528
529 /*
530 Number of the current node which is used as an index to
531 the other data structures.
532 */
533 unsigned int m_node_no;
534
535 /*
536 List of nodes known by the group communication.
537 */
538 std::vector<Gcs_xcom_node_information> m_nodes;
539
540 /*
541 The size of the lists.
542 */
543 unsigned int m_size;
544
545 /*
546 Memory allocated to encode addresses.
547 */
548 char const **m_addrs;
549
550 /*
551 Memory allocated to encode uuids.
552 */
554
555 private:
556 /*
557 Disabling the copy constructor and assignment operator.
558 */
561};
562#endif // GCS_XCOM_GROUP_MEMBER_INFORMATION_INCLUDED
It represents the identity of a group member within a certain group.
Definition: gcs_member_identifier.h:40
Stores connection information associated with a node.
Definition: gcs_xcom_group_member_information.h:51
virtual ~Gcs_xcom_node_address()
std::string m_member_ip
Definition: gcs_xcom_group_member_information.h:105
bool is_valid() const
A Gcs_xcom_node_address holds the representation IP:PORT of an XCom node.
Definition: gcs_xcom_group_member_information.cc:62
xcom_port get_member_port()
Return the port number.
Definition: gcs_xcom_group_member_information.cc:56
std::string & get_member_ip()
Return the IP address.
Definition: gcs_xcom_group_member_information.cc:54
std::string m_member_address
Definition: gcs_xcom_group_member_information.h:100
Gcs_xcom_node_address(std::string member_address)
Gcs_xcom_node_address constructor.
Definition: gcs_xcom_group_member_information.cc:37
xcom_port m_member_port
Definition: gcs_xcom_group_member_information.h:110
std::string & get_member_address()
Return address using the format ip:port.
Definition: gcs_xcom_group_member_information.cc:50
std::string * get_member_representation() const
Return an internal representation.
Definition: gcs_xcom_group_member_information.cc:58
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
const Gcs_member_identifier & get_member_id() const
Definition: gcs_xcom_group_member_information.cc:101
const Gcs_xcom_uuid & get_member_uuid() const
Definition: gcs_xcom_group_member_information.cc:105
void set_node_no(unsigned int)
Set the member node_no.
Definition: gcs_xcom_group_member_information.cc:114
virtual ~Gcs_xcom_node_information()=default
synode_no get_max_synode() const
Gets the highest synode_no known by the group when the node became unreachable.
Definition: gcs_xcom_group_member_information.cc:170
Gcs_member_identifier m_member_id
Definition: gcs_xcom_group_member_information.h:337
bool m_lost_messages
Indicates whether the local XCom cache has removed messages that the remote node represented by this ...
Definition: gcs_xcom_group_member_information.h:369
uint64_t get_suspicion_creation_timestamp() const
Gets the timestamp that indicates the creation of the suspicion.
Definition: gcs_xcom_group_member_information.cc:96
unsigned int get_node_no() const
Return member node_no.
Definition: gcs_xcom_group_member_information.cc:119
Gcs_xcom_uuid m_uuid
Member unique identifier.
Definition: gcs_xcom_group_member_information.h:342
unsigned int m_node_no
Member node_no.
Definition: gcs_xcom_group_member_information.h:347
bool m_member
Whether the node is a member of the group or not.
Definition: gcs_xcom_group_member_information.h:357
Gcs_xcom_node_information(const std::string &member_id, bool alive=true)
Gcs_xcom_node_information constructor.
Definition: gcs_xcom_group_member_information.cc:68
void set_suspicion_creation_timestamp(uint64_t ts)
Sets the timestamp to indicate the creation of the suspicion.
Definition: gcs_xcom_group_member_information.cc:91
bool is_alive() const
Get whether the member is alive or not.
Definition: gcs_xcom_group_member_information.cc:123
void set_member(bool m)
Set whether the node is already a member of the group or not.
Definition: gcs_xcom_group_member_information.cc:127
std::pair< bool, node_address * > make_xcom_identity(Gcs_xcom_proxy &xcom_proxy) const
Converts this node information into its corresponding XCom node_address type.
Definition: gcs_xcom_group_member_information.cc:129
bool has_timed_out(uint64_t ts, uint64_t timeout)
Compares the object's timestamp with the received one, in order to check if the suspicion has timed o...
Definition: gcs_xcom_group_member_information.cc:157
uint64_t m_suspicion_creation_timestamp
Stores the timestamp of the creation of the suspicion.
Definition: gcs_xcom_group_member_information.h:362
void set_lost_messages(bool lost_msgs)
Set whether the local XCom cache has removed messages that the node has missed.
Definition: gcs_xcom_group_member_information.cc:166
Gcs_xcom_node_information(const Gcs_xcom_node_information &)=default
bool has_lost_messages() const
Get whether the local XCom cache has removed messages that the remote node represented by this object...
Definition: gcs_xcom_group_member_information.cc:162
void set_max_synode(synode_no synode)
Sets the highest synode_no known by the group when the node became unreachable.
Definition: gcs_xcom_group_member_information.cc:174
bool m_alive
Whether the member is alive or dead.
Definition: gcs_xcom_group_member_information.h:352
synode_no m_max_synode
The highest synode known by the group when the node became unreachable.
Definition: gcs_xcom_group_member_information.h:374
bool is_member() const
Get whether the node is already a member of the group or not.
Definition: gcs_xcom_group_member_information.cc:125
void regenerate_member_uuid()
Regenerate the member uuid.
Definition: gcs_xcom_group_member_information.cc:109
Gcs_xcom_node_information & operator=(const Gcs_xcom_node_information &)=default
This class contains information on the configuration, i.e set of nodes or simply site definition.
Definition: gcs_xcom_group_member_information.h:391
bool is_valid() const
Return with the configuration is valid or not.
Definition: gcs_xcom_group_member_information.h:431
void add_node(const Gcs_xcom_node_information &node)
Add a node to the set of nodes.
Definition: gcs_xcom_group_member_information.cc:350
unsigned int get_node_no() const
Return the index of the current node (i.e.
Definition: gcs_xcom_group_member_information.cc:299
bool encode(unsigned int *ptr_size, char const ***ptr_addrs, blob **ptr_uuids)
Encode the information on the set of nodes in a format that can be interpreted by XCOM to boot,...
Definition: gcs_xcom_group_member_information.cc:382
void set_node_no(unsigned int node_no)
Definition: gcs_xcom_group_member_information.cc:295
char const ** m_addrs
Definition: gcs_xcom_group_member_information.h:548
const std::vector< Gcs_xcom_node_information > & get_nodes() const
Return a reference to the addresses' vector.
Definition: gcs_xcom_group_member_information.cc:302
blob * m_uuids
Definition: gcs_xcom_group_member_information.h:553
void remove_node(const Gcs_xcom_node_information &node)
Remove a node from the set of nodes.
Definition: gcs_xcom_group_member_information.cc:355
unsigned int m_node_no
Definition: gcs_xcom_group_member_information.h:533
const Gcs_xcom_node_information * get_node(const Gcs_member_identifier &member_id) const
Return a pointer to a node if it exists, otherwise NULL.
Definition: gcs_xcom_group_member_information.cc:307
void clear_nodes()
Clear the set of nodes.
Definition: gcs_xcom_group_member_information.cc:377
Gcs_xcom_nodes(const Gcs_xcom_nodes &)
Gcs_xcom_nodes()
Constructor that reads the site definition and whether a node is considered dead or alive to build a ...
Definition: gcs_xcom_group_member_information.cc:258
unsigned int m_size
Definition: gcs_xcom_group_member_information.h:543
void free_encode()
Definition: gcs_xcom_group_member_information.cc:431
unsigned int get_size() const
Return the number of nodes in the set.
Definition: gcs_xcom_group_member_information.cc:346
std::vector< Gcs_xcom_node_information > m_nodes
Definition: gcs_xcom_group_member_information.h:538
bool empty() const
Whether the set of nodes is empty or not.
Definition: gcs_xcom_group_member_information.cc:348
void add_nodes(const Gcs_xcom_nodes &xcom_nodes)
Clear up the current set and add a new set of nodes.
Definition: gcs_xcom_group_member_information.cc:367
virtual ~Gcs_xcom_nodes()
Destructor for Gcs_xcom_nodes.
Definition: gcs_xcom_group_member_information.cc:292
Gcs_xcom_nodes & operator=(const Gcs_xcom_nodes &)
Definition: gcs_xcom_proxy.h:52
Definition: gcs_xcom_group_member_information.h:116
Gcs_xcom_uuid()=default
std::pair< bool, blob > make_xcom_blob() const
Converts this UUID into its corresponding XCom blob type.
Definition: gcs_xcom_group_member_information.cc:239
std::string actual_value
Definition: gcs_xcom_group_member_information.h:172
static Gcs_xcom_uuid create_uuid()
Definition: gcs_xcom_group_member_information.cc:178
Gcs_xcom_uuid(const std::string xcom_uuid) noexcept
Definition: gcs_xcom_group_member_information.h:126
bool decode(const uchar *buffer, const unsigned int size)
Definition: gcs_xcom_group_member_information.cc:226
bool encode(uchar **buffer, unsigned int *size) const
Definition: gcs_xcom_group_member_information.cc:213
unsigned char uchar
Definition: my_inttypes.h:52
constexpr value_type blob
Definition: classic_protocol_constants.h:272
static bool timeout(bool(*wait_condition)())
Timeout function.
Definition: log0meb.cc:496
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:420
#define VOID_NODE_NO
Definition: node_no.h:36
Definition: site_struct.h:43
Rudimentary task system in portable C, based on Tom Duff's switch-based coroutine trick and a stack o...
unsigned short xcom_port
Definition: xcom_common.h:46
static void alive(server *s)
Definition: xcom_transport.cc:161