MySQL 8.1.0
Source Code Documentation
gcs_xcom_state_exchange.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 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_STATE_EXCHANGE_INCLUDED
24#define GCS_XCOM_STATE_EXCHANGE_INCLUDED
25
26#include <stdio.h>
27#include <sys/types.h>
28#include <map>
29#include <memory> // std::unique_ptr
30#include <set>
31#include <string>
32#include <vector>
33
43#include "plugin/group_replication/libmysqlgcs/xdr_gen/xcom_vp.h"
44
45/**
46 @class Xcom_member_state
47
48 Class that conveys the state to be exchanged between members, which is not
49 provided by XCom.
50
51 In the original GCS protocol (version 1), this message had the following wire
52 format:
53
54 +--------+---------------------+
55 | Header | Upper-layer payload |
56 +--------+---------------------+
57
58 Where the header has the following format:
59
60 +---------+------------+
61 | View ID | XCom synod |
62 +---------+------------+
63
64 With the introduction of the fragmentation stage into the message pipeline, it
65 is possible that an original message is fragmented into several fragments, and
66 each fragment is delivered by XCom individually.
67
68 This means that when a node joins, it is possible for the transmission of a
69 fragmented message to be ongoing, i.e. the existing group members have already
70 received some, but not all, of the fragments.
71 In this situation, the last fragment will arrive after the new node has joined
72 the group.
73 Since the original message is only delivered when all its fragments are
74 received, this means that the original message will need to be delivered by
75 the new node as well.
76 But the problem is that new node does not have the fragments that were
77 received before the new node joined.
78
79 We solve this problem by augmenting the state exchange message with
80 information about the ongoing transmission of fragmented messages.
81 In particular, for every fragmented message whose transmission is ongoing, a
82 node will attach the XCom synods of the fragments it has already received.
83 The new node can use this information to fetch the fragments from XCom.
84
85 As such, in GCS protocol version 2, this message has the following wire
86 format:
87
88 +--------+---------------------+----------------+
89 | Header | Upper-layer payload | Recovery info. |
90 +--------+---------------------+----------------+
91
92 Where the recovery information has the following format:
93
94 +---------------+-...-+----------------+------------+
95 | XCom synod #1 | | XCom synode #n | Nr. synods |
96 +---------------+-...-+----------------+------------+
97
98 Older GCS instances that only support protocol version 1 will deserialize the
99 recovery information as part of the upper-layer payload.
100 However, this works as long as the upper layer consumes only the portion it is
101 expecting (upper-layer payload), even though it is fed its expected payload
102 with the recovery information appended.
103*/
105 public:
106 /**
107 Xcom_member_state constructor.
108
109 @param[in] view_id the view identifier from the node
110 @param[in] configuration_id Configuration identifier in use when the state
111 exchange message was created
112 @param[in] version Protocol version used to represent the state
113 @param[in] snapshot Snapshot information currently in use
114 @param[in] data the generic data to be exchanged
115 @param[in] data_size data's size
116 */
117
118 explicit Xcom_member_state(const Gcs_xcom_view_identifier &view_id,
119 synode_no configuration_id,
121 const Gcs_xcom_synode_set &snapshot,
122 const uchar *data, uint64_t data_size);
123
124 /**
125 Xcom_member_state constructor.
126
127 @param[in] version Protocol version used to represent the state
128 @param[in] data the generic data to be exchanged
129 @param[in] data_size data's size
130 */
131
133 uint64_t data_size);
134
135 /**
136 Member state destructor.
137 */
138
140
141 /**
142 Encodes the Member State's header to be sent through the newtwork.
143
144 @param[out] buffer where the header will be stored.
145 @param[in,out] buffer_len pointer to the variable that will hold the
146 header's size and has the buffer's len as input.
147
148 @return True if there is no space to store the header.
149 Otherwise, false.
150 */
151 bool encode_header(uchar *buffer, uint64_t *buffer_len) const;
152
153 /**
154 Decodes the Member State's header that was sent through the network.
155
156 @param[out] buffer Where the header was stored.
157 @param[in,out] buffer_len Pointer to the variable that holds the
158 header's size and has the buffer's len as input.
159
160 @return true if nothing went wrong. Otherwise, false.
161 */
162 bool decode_header(const uchar *buffer, uint64_t buffer_len);
163
164 /**
165 Encodes the Member State's snapshot to be sent through the network.
166
167 @param[out] buffer where the snapshot will be stored.
168 @param[in,out] buffer_len pointer to the variable that will hold the
169 snapshot's size and has the buffer's len as input.
170
171 @return True if there is no space to store the snapshot.
172 Otherwise, false.
173 */
174 bool encode_snapshot(uchar *buffer, uint64_t *buffer_len) const;
175
176 /**
177 Decodes the Member State's snapshot that was sent through the network.
178
179 @param[out] buffer Where the snapshot was stored.
180 @param[in,out] buffer_len It holds the snapshot's size.
181
182 @return true if nothing went wrong. Otherwise, false.
183 */
184 bool decode_snapshot(const uchar *buffer, uint64_t buffer_len);
185
186 /**
187 Decodes Member State that was sent through the network.
188
189 @param[out] data where the data was stored.
190 @param[out] data_size pointer to the variable that holds the
191 data's size.
192
193 @return True if for any reason the data could not be exchanged.
194 Otherwise, false.
195 */
196 bool decode(const uchar *data, uint64_t data_size);
197
198 /**
199 @return the size of the encoded payload when put on the wire.
200 */
201
202 uint64_t get_encode_payload_size() const;
203
204 /**
205 @return the size of the encoded header when put on the wire.
206 */
207
208 static constexpr uint64_t get_encode_header_size() {
212 }
213
214 /**
215 @return the size of the encoded snapshot when put on the wire.
216 */
217
218 uint64_t get_encode_snapshot_size() const;
219
220 /**
221 @return the view identifier
222 */
223
225
226 /**
227 @return the configuration identifier
228 */
229
230 synode_no get_configuration_id() const { return m_configuration_id; }
231
232 /**
233 @return the generic exchangeable data
234 */
235
236 const uchar *get_data() const { return m_data; }
237
238 /**
239 @return the size of the generic exchangeable data
240 */
241
242 uint64_t get_data_size() const { return m_data_size; }
243
244 const Gcs_xcom_synode_set &get_snapshot() const { return m_snapshot; }
245
246 private:
247 static constexpr auto WIRE_XCOM_VARIABLE_VIEW_ID_SIZE = 8;
248 static constexpr auto WIRE_XCOM_VIEW_ID_SIZE = 4;
249 static constexpr auto WIRE_XCOM_GROUP_ID_SIZE = 4;
250 static constexpr auto WIRE_XCOM_MSG_ID_SIZE = 8;
251 static constexpr auto WIRE_XCOM_NODE_ID_SIZE = 4;
252 static constexpr auto WIRE_XCOM_SNAPSHOT_NR_ELEMS_SIZE = 8;
253
254 static constexpr uint64_t get_encode_snapshot_elem_size() {
256 }
257
258 /*
259 View identifier installed by the current member if there
260 is any.
261 */
263
264 /*
265 Configuration identifier in use when the state exchange message
266 was created.
267 */
269
270 /*
271 Data to be disseminated by the state exchange phase.
272 */
274
275 /*
276 Data's size disseminated by the state exchange phase.
277 */
278 uint64_t m_data_size;
279
280 /**
281 Recovery information which is currently a list of the XCom synods of the
282 fragments that are in buffers when a node is joining.
283
284 This is currently used only to transfer information on slice packets that
285 need to be fetched by the joining node before it may become ready to serve
286 requests.
287 */
289
290 /**
291 GCS communication version number in use.
292 */
294
295 /*
296 Disabling the copy constructor and assignment operator.
297 */
300};
301
302/**
303 @class gcs_xcom_state_exchange_interface
304
305 Interface that defines the operations that state exchange will provide.
306 In what follows, we describe how the state exchange algorithm works and
307 the view change process where it is inserted and which is an essential
308 part of our system.
309
310 The view change process is comprised of two major parts:
311 - Adding or removing a node from the system, accomplished in the
312 XCom/Paxos layer: "The SMART Way to Migrate Replicated Stateful
313 Services"
314
315 - A state exchange phase in which all members distribute data among
316 themselves.
317
318 Whenever a node wants to add or remove itself from the group, or after
319 a failure when a healthy member expels the faulty node from the group, a
320 reconfiguration request is sent in the form of an add_node or remove_node
321 message.
322
323 After the success of the request, XCOM sends a global view message
324 that contains information on all nodes tagging them as alive or
325 faulty to all non-faulty members. MySQL GCS looks at this information
326 and computes who has joined and who has left the group. The computation
327 is trivially simple and compares the set of nodes received in the
328 current view with the set of nodes in the previous view:
329
330 . left nodes = (alive_members in old_set) - (alive_members in new_set)
331
332 . joined nodes = (alive_members in new_set) - (alive_members in old_set)
333
334 However, the new view is only delivered to an upper layer after all
335 members exchange what we call a state message. While the view is being
336 processed and the state exchange is ongoing, all incoming data messages
337 are not delivered to the application and are put into a buffer. So after
338 getting state messages from all members, the view change is delivered
339 to the upper layer along with the content of the state messages and any
340 buffered message is delivered afterwards.
341
342 Why blocking the delivery of data messages and why these state
343 messages?
344
345 Recall that all messages are atomically delivered and we can guarantee
346 that all nodes will have the same state which encompasses messages
347 (e.g. transactions) in queues and in the storage (e.g. binary log)
348 because all new data messages are buffered while the state messages
349 are being exchanged.
350
351 Blocking the delivery of new data messages give us a synchronization
352 point.
353
354 But if all nodes have the same state why gathering a state message
355 from all members?
356
357 The power of choice. Let us use MySQL Group Replication as a concrete
358 example of an upper layer to understand why. This is done because having
359 information on all members allow the new node to choose a member that is
360 not lagging behind (i.e. has a small queue) as a donor in a recovery
361 phase. Besides, the state message also carries information on IPs and
362 Ports used to access the MySQL Instances. This information is necessary
363 to start the recovery which will be asynchronously started and will dump
364 the missing data from a donor.
365
366 Note that the content of the state message is opaque to the MySQL GCS
367 layer which only provides a synchronization point.
368*/
370 public:
372
373 /**
374 Accomplishes all necessary initialization steps.
375 */
376
377 virtual void init() = 0;
378
379 /**
380 If messages were buffered during its processing, they are discarded
381 and internal structures needed are cleaned up.
382 */
383
384 virtual void reset() = 0;
385
386 /**
387 Has the same behavior as the reset but additionally flushes buffered
388 messages.
389 */
390
391 virtual void reset_with_flush() = 0;
392
393 /**
394 If messages were buffered during its processing, they are delivered
395 to upper layers and internal structures needed are cleaned up.
396 */
397
398 virtual void end() = 0;
399
400 /**
401 Signals the module to start a State Exchange.
402
403 @param[in] configuration_id Configuration identifier in use when the state
404 exchange phase started
405 @param[in] total xcom total members in the new view
406 @param[in] left xcom members that left in the new view
407 @param[in] joined xcom members that joined in the new view
408 @param[in] exchangeable_data generic exchanged data
409 @param[in] current_view the currently installed view
410 @param[in] group group name
411 @param[in] local_info the local GCS member identifier
412 @param[in] xcom_nodes list of nodes
413
414 @return true if the member is leaving
415 */
416
417 virtual bool state_exchange(
418 synode_no configuration_id, std::vector<Gcs_member_identifier *> &total,
419 std::vector<Gcs_member_identifier *> &left,
420 std::vector<Gcs_member_identifier *> &joined,
421 std::vector<std::unique_ptr<Gcs_message_data>> &exchangeable_data,
422 Gcs_view *current_view, std::string *group,
423 const Gcs_member_identifier &local_info,
424 const Gcs_xcom_nodes &xcom_nodes) = 0;
425
426 /**
427 Processes a member state message on an ongoing State Exchange round.
428
429 @param[in] ms_info received Member State
430 @param[in] p_id the node that the Member State pertains
431 @param[in] maximum_supported_protocol_version maximum supported protocol
432 version
433 @param[in] used_protocol_version protocol version in use by a member during
434 the state exchange phase
435
436 @return true if State Exchanged is to be finished and the view can be
437 installed
438 */
439
441 Xcom_member_state *ms_info, const Gcs_member_identifier &p_id,
442 Gcs_protocol_version maximum_supported_protocol_version,
443 Gcs_protocol_version used_protocol_version) = 0;
444
445 /**
446 Compute the set of incompatible members after the state exchange has
447 finished.
448 A member M is incompatible if it is attempting to join a group that is
449 using protocol X, but M is using protocol Y s.t. X != Y.
450 @returns the set of incompatible members
451 */
452 virtual std::vector<Gcs_xcom_node_information>
454
455 /**
456 Recovers any missing packets required for the member to join the group.
457 @retval true if successful
458 @retval false otherwise
459 */
460 virtual bool process_recovery_state() = 0;
461
462 /**
463 Retrieves the new view identifier after a State Exchange.
464
465 @return the new view identifier
466 */
467
469
470 /**
471 @return the members that joined in this State Exchange round
472 */
473
474 virtual std::set<Gcs_member_identifier *> *get_joined() = 0;
475
476 /**
477 @return the members that left in this State Exchange round
478 */
479
480 virtual std::set<Gcs_member_identifier *> *get_left() = 0;
481
482 /**
483 @return All the members in this State Exchange round
484 */
485
486 virtual std::set<Gcs_member_identifier *> *get_total() = 0;
487
488 /**
489 @return the group in which this State Exchange is occurring
490 */
491
492 virtual std::string *get_group() = 0;
493
494 /**
495 @return the saved states
496 */
497
498 virtual std::map<Gcs_member_identifier, Xcom_member_state *>
500
501 /**
502 Computes the maximum protocol version supported by the group.
503 */
505};
506
507/**
508 Implementation of the gcs_xcom_state_exchange_interface.
509*/
511 public:
512 /**
513 State Exchange constructor.
514
515 @param[in] comm Communication interface reference to allow broadcasting of
516 member states
517 */
518
520
521 ~Gcs_xcom_state_exchange() override;
522
523 // Implementation of gcs_xcom_state_exchange_interface
524 void init() override;
525
526 void reset() override;
527
528 void reset_with_flush() override;
529
530 void end() override;
531
532 bool state_exchange(
533 synode_no configuration_id, std::vector<Gcs_member_identifier *> &total,
534 std::vector<Gcs_member_identifier *> &left,
535 std::vector<Gcs_member_identifier *> &joined,
536 std::vector<std::unique_ptr<Gcs_message_data>> &exchangeable_data,
537 Gcs_view *current_view, std::string *group,
538 const Gcs_member_identifier &local_info,
539 const Gcs_xcom_nodes &xcom_nodes) override;
540
542 Xcom_member_state *ms_info, const Gcs_member_identifier &p_id,
543 Gcs_protocol_version maximum_supported_protocol_version,
544 Gcs_protocol_version used_protocol_version) override;
545
546 std::vector<Gcs_xcom_node_information> compute_incompatible_members()
547 override;
548
549 bool process_recovery_state() override;
550
552
553 std::set<Gcs_member_identifier *> *get_joined() override {
554 return &m_ms_joined;
555 }
556
557 std::set<Gcs_member_identifier *> *get_left() override { return &m_ms_left; }
558
559 std::set<Gcs_member_identifier *> *get_total() override {
560 return &m_ms_total;
561 }
562
563 std::map<Gcs_member_identifier, Xcom_member_state *> *get_member_states()
564 override {
565 return &m_member_states;
566 }
567
568 std::string *get_group() override { return m_group_name; }
569
571
572 private:
573 /**
574 Computes if the local member is leaving.
575
576 @return true in case of the local member is leaving
577 */
578
579 bool is_leaving();
580
581 /**
582 Computes if the local member is joining.
583
584 @return true in case of the local member is joining
585 */
586
587 bool is_joining();
588
589 /**
590 Update the communication system with information on membership.
591
592 @param xcom_nodes List of nodes that belong to the current membership.
593 */
594 void update_communication_channel(const Gcs_xcom_nodes &xcom_nodes);
595
596 /**
597 Broadcasts the local state to all nodes in the Cluster.
598
599 @param[in] proposed_view proposed view to broadcast
600 @param[in] exchangeable_data List with exchangeable messages
601 */
602
604 const Gcs_xcom_view_identifier &proposed_view,
605 std::vector<std::unique_ptr<Gcs_message_data>> &exchangeable_data);
606
607 /**
608 Updates the structure that waits for State Exchanges.
609 */
610
612
613 /**
614 Converts xcom data to a set of internal representation.
615
616 @param[in] in xcom list
617 @param[in] pset Set where the converted member ids will be written
618 */
619
620 void fill_member_set(std::vector<Gcs_member_identifier *> &in,
621 std::set<Gcs_member_identifier *> &pset);
622
623 /**
624 Stores the member's state and protocol version.
625
626 @param ms_info state
627 @param p_id member
628 @param[in] maximum_supported_protocol_version maximum supported protocol
629 version
630 @param used_protocol_version protocol version
631 */
633 Xcom_member_state *ms_info, const Gcs_member_identifier &p_id,
634 Gcs_protocol_version maximum_supported_protocol_version,
635 Gcs_protocol_version used_protocol_version);
636
637 /**
638 Auxiliary method that checks whether @c snapshot_to_recover contains all
639 the synodes required.
640 */
641 bool snapshot_is_enough(Gcs_xcom_synode_set const &snapshot_to_recover) const;
642
643 /**
644 Checks whether all the existing group members, myself excluded, announce the
645 same protocol version.
646 @retval {false, _} if they do not all announce the same protocol version
647 @retval {true, Gcs_protocol_version} if they all announced the same protocol
648 version of the return value
649 */
650 std::pair<bool, Gcs_protocol_version> members_announce_same_version() const;
651
652 /**
653 Checks whether this server is incompatible with the group.
654 @retval true If it is incompatible
655 @retval false If it is compatible
656 */
657 bool incompatible_with_group() const;
658
659 /**
660 Computes the set of incompatible nodes that are trying to join the group.
661 @returns the set of incompatible joiners
662 */
663 std::vector<Gcs_xcom_node_information> compute_incompatible_joiners();
664
666
667 std::map<Gcs_member_identifier, uint> m_awaited_vector;
668
669 std::map<Gcs_member_identifier, uint> m_recover_vector;
670
671 /* Set of ids in GCS native format as reported by View-change handler. */
672 std::set<Gcs_member_identifier *> m_ms_total, m_ms_left, m_ms_joined;
673
674 /* Collection of State Message contents to facilitate view installation. */
675 std::map<Gcs_member_identifier, Xcom_member_state *> m_member_states;
676
677 /* Collection of protocol version in use per member. */
678 std::map<Gcs_member_identifier, Gcs_protocol_version> m_member_versions;
679
680 /* Collection of maximum protocol version supported per member. */
681 std::map<Gcs_member_identifier, Gcs_protocol_version> m_member_max_versions;
682
683 // Group name to exchange state
684 std::string *m_group_name;
685
686 // Local GCS member identification
688
689 /* Configuration identifier in use when the state exchange phase started */
691
692 std::vector<synode_no> cached_ids;
693
694 /* XCom identifiers of the members in m_ms_total */
696
697 /*
698 Disabling the copy constructor and assignment operator.
699 */
702};
703
704/*
705 @interface gcs_xcom_view_change_control_interface
706
707 This interface will serve as a synchronization point to all those that are
708 interested in maintaining view safety. This will guarantee that no actions are
709 accomplished while a view change procedure is ongoing.
710
711 The promoters of view change will indicate via start_view_exchange() and
712 end_view_exchange() the boundaries of the process. Those that want to wait
713 for the end, will synchronize on wait_for_view_change_end().
714*/
716 public:
718
719 virtual void start_view_exchange() = 0;
720 virtual void end_view_exchange() = 0;
721 virtual void wait_for_view_change_end() = 0;
722 virtual bool is_view_changing() = 0;
723
724 // Leave related information
725 virtual bool start_leave() = 0;
726 virtual void end_leave() = 0;
727 virtual bool is_leaving() = 0;
728
729 // Join related information
730 virtual bool start_join() = 0;
731 virtual void end_join() = 0;
732 virtual bool is_joining() = 0;
733
734 // Keep track of delivered views
735 virtual void set_current_view(Gcs_view *current_view) = 0;
737 virtual bool belongs_to_group() = 0;
738 virtual void set_belongs_to_group(bool belong) = 0;
739 virtual void set_unsafe_current_view(Gcs_view *current_view) = 0;
741
742 // Keep track if GCS as a whole has been ordered to finalize;
743 virtual void finalize() = 0;
744 virtual bool is_finalized() = 0;
745};
746
747/*
748 @class gcs_xcom_view_change_control
749
750 Implementation of gcs_xcom_view_change_control_interface.
751*/
754 public:
757
758 void start_view_exchange() override;
759 void end_view_exchange() override;
760 void wait_for_view_change_end() override;
761 bool is_view_changing() override;
762
763 bool start_leave() override;
764 void end_leave() override;
765 bool is_leaving() override;
766
767 bool start_join() override;
768 void end_join() override;
769 bool is_joining() override;
770
771 void set_current_view(Gcs_view *current_view) override;
772 Gcs_view *get_current_view() override;
773 bool belongs_to_group() override;
774 void set_belongs_to_group(bool belong) override;
775 void set_unsafe_current_view(Gcs_view *current_view) override;
777
778 void finalize() override;
779 bool is_finalized() override;
780
781 private:
785
789
790 /*
791 Reference to the currently installed view.
792 */
794
795 /*
796 Protect access to the current view so that it can be
797 copied and returned.
798 */
800
801 /*
802 Whether the current node belongs to a group or not.
803 */
805
806 /*
807 */
808 std::atomic<bool> m_finalized;
809
810 /*
811 Disabling the copy constructor and assignment operator.
812 */
815};
816#endif /* GCS_XCOM_STATE_EXCHANGE_INCLUDED */
This interface represents all the communication facilities that a binding implementation should provi...
Definition: gcs_communication_interface.h:89
It represents the identity of a group member within a certain group.
Definition: gcs_member_identifier.h:39
This represents the membership view that a member has from a group.
Definition: gcs_view.h:54
This class contains information on the configuration, i.e set of nodes or simply site definition.
Definition: gcs_xcom_group_member_information.h:390
Definition: gcs_xcom_state_exchange.h:369
virtual std::map< Gcs_member_identifier, Xcom_member_state * > * get_member_states()=0
virtual std::string * get_group()=0
virtual std::vector< Gcs_xcom_node_information > compute_incompatible_members()=0
Compute the set of incompatible members after the state exchange has finished.
virtual void init()=0
Accomplishes all necessary initialization steps.
virtual bool process_recovery_state()=0
Recovers any missing packets required for the member to join the group.
virtual std::set< Gcs_member_identifier * > * get_total()=0
virtual void end()=0
If messages were buffered during its processing, they are delivered to upper layers and internal stru...
virtual Gcs_xcom_view_identifier * get_new_view_id()=0
Retrieves the new view identifier after a State Exchange.
virtual std::set< Gcs_member_identifier * > * get_left()=0
virtual std::set< Gcs_member_identifier * > * get_joined()=0
virtual ~Gcs_xcom_state_exchange_interface()=default
virtual void reset()=0
If messages were buffered during its processing, they are discarded and internal structures needed ar...
virtual void reset_with_flush()=0
Has the same behavior as the reset but additionally flushes buffered messages.
virtual void compute_maximum_supported_protocol_version()=0
Computes the maximum protocol version supported by the group.
virtual bool state_exchange(synode_no configuration_id, std::vector< Gcs_member_identifier * > &total, std::vector< Gcs_member_identifier * > &left, std::vector< Gcs_member_identifier * > &joined, std::vector< std::unique_ptr< Gcs_message_data > > &exchangeable_data, Gcs_view *current_view, std::string *group, const Gcs_member_identifier &local_info, const Gcs_xcom_nodes &xcom_nodes)=0
Signals the module to start a State Exchange.
virtual bool process_member_state(Xcom_member_state *ms_info, const Gcs_member_identifier &p_id, Gcs_protocol_version maximum_supported_protocol_version, Gcs_protocol_version used_protocol_version)=0
Processes a member state message on an ongoing State Exchange round.
Implementation of the gcs_xcom_state_exchange_interface.
Definition: gcs_xcom_state_exchange.h:510
void init() override
Accomplishes all necessary initialization steps.
Definition: gcs_xcom_state_exchange.cc:333
std::map< Gcs_member_identifier, uint > m_awaited_vector
Definition: gcs_xcom_state_exchange.h:667
void update_communication_channel(const Gcs_xcom_nodes &xcom_nodes)
Update the communication system with information on membership.
Definition: gcs_xcom_state_exchange.cc:655
std::pair< bool, Gcs_protocol_version > members_announce_same_version() const
Checks whether all the existing group members, myself excluded, announce the same protocol version.
Definition: gcs_xcom_state_exchange.cc:753
std::string * get_group() override
Definition: gcs_xcom_state_exchange.h:568
void compute_maximum_supported_protocol_version() override
Computes the maximum protocol version supported by the group.
Definition: gcs_xcom_state_exchange.cc:940
Gcs_member_identifier m_local_information
Definition: gcs_xcom_state_exchange.h:687
std::string * m_group_name
Definition: gcs_xcom_state_exchange.h:684
std::set< Gcs_member_identifier * > * get_joined() override
Definition: gcs_xcom_state_exchange.h:553
Gcs_xcom_view_identifier * get_new_view_id() override
Retrieves the new view identifier after a State Exchange.
Definition: gcs_xcom_state_exchange.cc:1029
Gcs_communication_interface * m_broadcaster
Definition: gcs_xcom_state_exchange.h:665
std::map< Gcs_member_identifier, Xcom_member_state * > * get_member_states() override
Definition: gcs_xcom_state_exchange.h:563
bool is_joining()
Computes if the local member is joining.
Definition: gcs_xcom_state_exchange.cc:493
std::map< Gcs_member_identifier, Gcs_protocol_version > m_member_versions
Definition: gcs_xcom_state_exchange.h:678
Gcs_xcom_nodes m_ms_xcom_nodes
Definition: gcs_xcom_state_exchange.h:695
enum_gcs_error broadcast_state(const Gcs_xcom_view_identifier &proposed_view, std::vector< std::unique_ptr< Gcs_message_data > > &exchangeable_data)
Broadcasts the local state to all nodes in the Cluster.
Definition: gcs_xcom_state_exchange.cc:516
bool process_member_state(Xcom_member_state *ms_info, const Gcs_member_identifier &p_id, Gcs_protocol_version maximum_supported_protocol_version, Gcs_protocol_version used_protocol_version) override
Processes a member state message on an ongoing State Exchange round.
Definition: gcs_xcom_state_exchange.cc:664
std::vector< Gcs_xcom_node_information > compute_incompatible_members() override
Compute the set of incompatible members after the state exchange has finished.
Definition: gcs_xcom_state_exchange.cc:720
std::set< Gcs_member_identifier * > * get_left() override
Definition: gcs_xcom_state_exchange.h:557
void fill_member_set(std::vector< Gcs_member_identifier * > &in, std::set< Gcs_member_identifier * > &pset)
Converts xcom data to a set of internal representation.
Definition: gcs_xcom_state_exchange.cc:1009
bool incompatible_with_group() const
Checks whether this server is incompatible with the group.
Definition: gcs_xcom_state_exchange.cc:787
void update_awaited_vector()
Updates the structure that waits for State Exchanges.
Definition: gcs_xcom_state_exchange.cc:636
bool state_exchange(synode_no configuration_id, std::vector< Gcs_member_identifier * > &total, std::vector< Gcs_member_identifier * > &left, std::vector< Gcs_member_identifier * > &joined, std::vector< std::unique_ptr< Gcs_message_data > > &exchangeable_data, Gcs_view *current_view, std::string *group, const Gcs_member_identifier &local_info, const Gcs_xcom_nodes &xcom_nodes) override
Signals the module to start a State Exchange.
Definition: gcs_xcom_state_exchange.cc:408
bool is_leaving()
Computes if the local member is leaving.
Definition: gcs_xcom_state_exchange.cc:505
std::map< Gcs_member_identifier, uint > m_recover_vector
Definition: gcs_xcom_state_exchange.h:669
void reset_with_flush() override
Has the same behavior as the reset but additionally flushes buffered messages.
Definition: gcs_xcom_state_exchange.cc:335
std::set< Gcs_member_identifier * > m_ms_total
Definition: gcs_xcom_state_exchange.h:672
std::set< Gcs_member_identifier * > m_ms_left
Definition: gcs_xcom_state_exchange.h:672
bool snapshot_is_enough(Gcs_xcom_synode_set const &snapshot_to_recover) const
Auxiliary method that checks whether snapshot_to_recover contains all the synodes required.
void save_member_state(Xcom_member_state *ms_info, const Gcs_member_identifier &p_id, Gcs_protocol_version maximum_supported_protocol_version, Gcs_protocol_version used_protocol_version)
Stores the member's state and protocol version.
Definition: gcs_xcom_state_exchange.cc:1015
~Gcs_xcom_state_exchange() override
Definition: gcs_xcom_state_exchange.cc:324
std::map< Gcs_member_identifier, Xcom_member_state * > m_member_states
Definition: gcs_xcom_state_exchange.h:675
std::vector< synode_no > cached_ids
Definition: gcs_xcom_state_exchange.h:692
std::map< Gcs_member_identifier, Gcs_protocol_version > m_member_max_versions
Definition: gcs_xcom_state_exchange.h:681
void reset() override
If messages were buffered during its processing, they are discarded and internal structures needed ar...
Definition: gcs_xcom_state_exchange.cc:360
std::vector< Gcs_xcom_node_information > compute_incompatible_joiners()
Computes the set of incompatible nodes that are trying to join the group.
Definition: gcs_xcom_state_exchange.cc:884
std::set< Gcs_member_identifier * > m_ms_joined
Definition: gcs_xcom_state_exchange.h:672
Gcs_xcom_state_exchange(Gcs_xcom_state_exchange const &)
synode_no m_configuration_id
Definition: gcs_xcom_state_exchange.h:690
Gcs_xcom_state_exchange(Gcs_communication_interface *comm)
State Exchange constructor.
Definition: gcs_xcom_state_exchange.cc:308
void end() override
If messages were buffered during its processing, they are delivered to upper layers and internal stru...
Definition: gcs_xcom_state_exchange.cc:399
bool process_recovery_state() override
Recovers any missing packets required for the member to join the group.
Definition: gcs_xcom_state_exchange.cc:962
Gcs_xcom_state_exchange & operator=(Gcs_xcom_state_exchange const &)
std::set< Gcs_member_identifier * > * get_total() override
Definition: gcs_xcom_state_exchange.h:559
Definition: gcs_xcom_state_exchange.h:715
virtual void set_current_view(Gcs_view *current_view)=0
virtual void set_unsafe_current_view(Gcs_view *current_view)=0
virtual void set_belongs_to_group(bool belong)=0
virtual Gcs_view * get_current_view()=0
virtual ~Gcs_xcom_view_change_control_interface()=default
virtual Gcs_view * get_unsafe_current_view()=0
Definition: gcs_xcom_state_exchange.h:753
void end_join() override
Definition: gcs_xcom_state_exchange.cc:1213
bool start_join() override
Definition: gcs_xcom_state_exchange.cc:1202
bool is_finalized() override
Definition: gcs_xcom_state_exchange.cc:1231
bool m_view_changing
Definition: gcs_xcom_state_exchange.h:782
My_xp_mutex_impl m_current_view_mutex
Definition: gcs_xcom_state_exchange.h:799
Gcs_view * get_current_view() override
Definition: gcs_xcom_state_exchange.cc:1122
void end_view_exchange() override
Definition: gcs_xcom_state_exchange.cc:1150
My_xp_cond_impl m_wait_for_view_cond
Definition: gcs_xcom_state_exchange.h:786
Gcs_xcom_view_change_control(Gcs_xcom_view_change_control const &)
~Gcs_xcom_view_change_control() override
Definition: gcs_xcom_state_exchange.cc:1101
bool is_view_changing() override
Definition: gcs_xcom_state_exchange.cc:1157
bool is_joining() override
Definition: gcs_xcom_state_exchange.cc:1219
void finalize() override
Definition: gcs_xcom_state_exchange.cc:1229
bool is_leaving() override
Definition: gcs_xcom_state_exchange.cc:1192
void start_view_exchange() override
Definition: gcs_xcom_state_exchange.cc:1144
void wait_for_view_change_end() override
Definition: gcs_xcom_state_exchange.cc:1166
Gcs_xcom_view_change_control & operator=(Gcs_xcom_view_change_control const &)
bool belongs_to_group() override
Definition: gcs_xcom_state_exchange.cc:1136
void set_belongs_to_group(bool belong) override
Definition: gcs_xcom_state_exchange.cc:1140
void set_current_view(Gcs_view *current_view) override
Definition: gcs_xcom_state_exchange.cc:1108
bool start_leave() override
Definition: gcs_xcom_state_exchange.cc:1175
bool m_joining
Definition: gcs_xcom_state_exchange.h:784
My_xp_mutex_impl m_joining_leaving_mutex
Definition: gcs_xcom_state_exchange.h:788
void end_leave() override
Definition: gcs_xcom_state_exchange.cc:1186
Gcs_xcom_view_change_control()
Definition: gcs_xcom_state_exchange.cc:1078
bool m_belongs_to_group
Definition: gcs_xcom_state_exchange.h:804
std::atomic< bool > m_finalized
Definition: gcs_xcom_state_exchange.h:808
Gcs_view * m_current_view
Definition: gcs_xcom_state_exchange.h:793
My_xp_mutex_impl m_wait_for_view_mutex
Definition: gcs_xcom_state_exchange.h:787
Gcs_view * get_unsafe_current_view() override
Definition: gcs_xcom_state_exchange.cc:1132
bool m_leaving
Definition: gcs_xcom_state_exchange.h:783
void set_unsafe_current_view(Gcs_view *current_view) override
Definition: gcs_xcom_state_exchange.cc:1116
Definition: gcs_xcom_view_identifier.h:32
Definition: my_xp_cond.h:135
Definition: my_xp_mutex.h:122
Class that conveys the state to be exchanged between members, which is not provided by XCom.
Definition: gcs_xcom_state_exchange.h:104
Xcom_member_state & operator=(Xcom_member_state const &)=delete
Xcom_member_state(Xcom_member_state const &)=delete
Gcs_xcom_view_identifier * m_view_id
Definition: gcs_xcom_state_exchange.h:262
synode_no m_configuration_id
Definition: gcs_xcom_state_exchange.h:268
const Gcs_xcom_synode_set & get_snapshot() const
Definition: gcs_xcom_state_exchange.h:244
Gcs_protocol_version m_version
GCS communication version number in use.
Definition: gcs_xcom_state_exchange.h:293
static constexpr uint64_t get_encode_snapshot_elem_size()
Definition: gcs_xcom_state_exchange.h:254
Gcs_xcom_view_identifier * get_view_id()
Definition: gcs_xcom_state_exchange.h:224
uint64_t get_encode_payload_size() const
Definition: gcs_xcom_state_exchange.cc:73
static constexpr uint64_t get_encode_header_size()
Definition: gcs_xcom_state_exchange.h:208
bool decode_header(const uchar *buffer, uint64_t buffer_len)
Decodes the Member State's header that was sent through the network.
Definition: gcs_xcom_state_exchange.cc:205
uchar * m_data
Definition: gcs_xcom_state_exchange.h:273
static constexpr auto WIRE_XCOM_SNAPSHOT_NR_ELEMS_SIZE
Definition: gcs_xcom_state_exchange.h:252
static constexpr auto WIRE_XCOM_VARIABLE_VIEW_ID_SIZE
Definition: gcs_xcom_state_exchange.h:247
static constexpr auto WIRE_XCOM_VIEW_ID_SIZE
Definition: gcs_xcom_state_exchange.h:248
static constexpr auto WIRE_XCOM_GROUP_ID_SIZE
Definition: gcs_xcom_state_exchange.h:249
uint64_t get_data_size() const
Definition: gcs_xcom_state_exchange.h:242
uint64_t m_data_size
Definition: gcs_xcom_state_exchange.h:278
bool encode_header(uchar *buffer, uint64_t *buffer_len) const
Encodes the Member State's header to be sent through the newtwork.
Definition: gcs_xcom_state_exchange.cc:91
bool encode_snapshot(uchar *buffer, uint64_t *buffer_len) const
Encodes the Member State's snapshot to be sent through the network.
Definition: gcs_xcom_state_exchange.cc:158
static constexpr auto WIRE_XCOM_NODE_ID_SIZE
Definition: gcs_xcom_state_exchange.h:251
~Xcom_member_state()
Member state destructor.
Definition: gcs_xcom_state_exchange.cc:68
static constexpr auto WIRE_XCOM_MSG_ID_SIZE
Definition: gcs_xcom_state_exchange.h:250
bool decode(const uchar *data, uint64_t data_size)
Decodes Member State that was sent through the network.
Definition: gcs_xcom_state_exchange.cc:280
Xcom_member_state(const Gcs_xcom_view_identifier &view_id, synode_no configuration_id, Gcs_protocol_version version, const Gcs_xcom_synode_set &snapshot, const uchar *data, uint64_t data_size)
Xcom_member_state constructor.
Definition: gcs_xcom_state_exchange.cc:37
bool decode_snapshot(const uchar *buffer, uint64_t buffer_len)
Decodes the Member State's snapshot that was sent through the network.
Definition: gcs_xcom_state_exchange.cc:238
synode_no get_configuration_id() const
Definition: gcs_xcom_state_exchange.h:230
Gcs_xcom_synode_set m_snapshot
Recovery information which is currently a list of the XCom synods of the fragments that are in buffer...
Definition: gcs_xcom_state_exchange.h:288
const uchar * get_data() const
Definition: gcs_xcom_state_exchange.h:236
uint64_t get_encode_snapshot_size() const
Definition: gcs_xcom_state_exchange.cc:77
enum_gcs_error
This enumeration describes errors which can occur during group communication operations.
Definition: gcs_types.h:40
Gcs_protocol_version
The GCS protocol versions.
Definition: gcs_types.h:127
std::unordered_set< Gcs_xcom_synode > Gcs_xcom_synode_set
Definition: gcs_xcom_synode.h:83
unsigned char uchar
Definition: my_inttypes.h:51
Type total(const Shards< COUNT > &shards) noexcept
Get the total value of all shards.
Definition: ut0counter.h:332
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:419
std::vector< T, ut::allocator< T > > vector
Specialization of vector which uses allocator.
Definition: ut0new.h:2873
required uint64 version
Definition: replication_group_member_actions.proto:40