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