MySQL 8.4.0
Source Code Documentation
certifier.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 CERTIFIER_INCLUDE
25#define CERTIFIER_INCLUDE
26
27#include <assert.h>
29#include <atomic>
30#include <list>
31#include <map>
32#include <string>
33#include <unordered_map>
34#include <vector>
35
36#include "my_inttypes.h"
50
51#include "plugin/group_replication/generated/protobuf_lite/replication_group_recovery_metadata.pb.h"
52
54
55/**
56 While sending Recovery Metadata the Certification Information is divided into
57 several small packets of MAX_COMPRESSED_PACKET_SIZE before sending it to
58 group for Recovery.
59 The compressed packet size is choosen as 10MB so that multiple threads can
60 process (serialize and compress or unserialize and decompress) packets
61 simultaneously without consuming too much memory.
62*/
63#define MAX_COMPRESSED_PACKET_SIZE 10485760
64
65/**
66 This class extends Gtid_set to include a reference counter.
67
68 It is for Certifier only, so it is single-threaded and no locks
69 are needed since Certifier already ensures sequential use.
70
71 It is to be used to share by multiple entries in the
72 certification info and released when the last reference to it
73 needs to be freed.
74*/
75class Gtid_set_ref : public Gtid_set {
76 public:
81
82 virtual ~Gtid_set_ref() = default;
83
84 /**
85 Increment the number of references by one.
86
87 @return the number of references
88 */
89 size_t link() { return ++reference_counter; }
90
91 /**
92 Decrement the number of references by one.
93
94 @return the number of references
95 */
96 size_t unlink() {
97 assert(reference_counter > 0);
98 return --reference_counter;
99 }
100
103 }
104
105 private:
108};
109
110/**
111 This class is a core component of the database state machine
112 replication protocol. It implements conflict detection based
113 on a certification procedure.
114
115 Snapshot Isolation is based on assigning logical timestamp to optimistic
116 transactions, i.e. the ones which successfully meet certification and
117 are good to commit on all members in the group. This timestamp is a
118 monotonically increasing counter, and is same across all members in the group.
119
120 This timestamp, which in our algorithm is the snapshot version, is further
121 used to update the certification info.
122 The snapshot version maps the items in a transaction to the GTID_EXECUTED
123 that this transaction saw when it was executed, that is, on which version
124 the transaction was executed.
125
126 If the incoming transaction snapshot version is a subset of a
127 previous certified transaction for the same write set, the current
128 transaction was executed on top of outdated data, so it will be
129 negatively certified. Otherwise, this transaction is marked
130 certified and goes into applier.
131*/
133 public:
134 /**
135 Certifier_broadcast_thread constructor
136 */
139
140 /**
141 Initialize broadcast thread.
142
143 @return the operation status
144 @retval 0 OK
145 @retval !=0 Error
146 */
147 int initialize();
148
149 /**
150 Terminate broadcast thread.
151
152 @return the operation status
153 @retval 0 OK
154 @retval !=0 Error
155 */
156 int terminate();
157
158 /**
159 Broadcast thread worker method.
160 */
161 void dispatcher();
162
163 /**
164 Period (in seconds) between stable transactions set
165 broadcast.
166 */
167 static const int BROADCAST_GTID_EXECUTED_PERIOD = 60; // seconds
168
169 private:
170 /**
171 Thread control.
172 */
183
184 /**
185 Broadcast local GTID_EXECUTED to group.
186
187 @return the operation status
188 @retval 0 OK
189 @retval !=0 Error
190 */
192};
193
195 public:
196 ~Certifier_interface() override = default;
197 virtual void handle_view_change() = 0;
199 const uchar *data, ulong len,
200 const Gcs_member_identifier &gcs_member_id) = 0;
201
203 std::map<std::string, std::string> *cert_info) = 0;
205 Recovery_metadata_message *recovery_metadata_message) = 0;
207 std::map<std::string, std::string> *cert_info) = 0;
209 Recovery_metadata_message *recovery_metadata_message) = 0;
211 virtual void garbage_collect(Gtid_set *executed_gtid_set = nullptr,
212 bool on_member_join = false) = 0;
213 virtual void enable_conflict_detection() = 0;
214 virtual void disable_conflict_detection() = 0;
217};
218
220 public:
221 typedef std::unordered_map<
222 std::string, Gtid_set_ref *, std::hash<std::string>,
223 std::equal_to<std::string>,
226
227 typedef protobuf_replication_group_recovery_metadata::
228 CertificationInformationMap ProtoCertificationInformationMap;
229
230 Certifier();
231 ~Certifier() override;
232
233 /**
234 Key used to store errors in the certification info
235 on View_change_log_event.
236 */
237 static const std::string CERTIFICATION_INFO_ERROR_NAME;
238
239 /**
240 Initialize certifier.
241
242 @param gtid_assignment_block_size the group gtid assignment block size
243
244 @return the operation status
245 @retval 0 OK
246 @retval !=0 Error
247 */
248 int initialize(ulonglong gtid_assignment_block_size);
249
250 /**
251 Terminate certifier.
252
253 @return the operation status
254 @retval 0 OK
255 @retval !=0 Error
256 */
257 int terminate();
258
259 /**
260 Handle view changes on certifier.
261 */
262 void handle_view_change() override;
263
264 /**
265 Queues the packet coming from the reader for future processing.
266
267 @param[in] data the packet data
268 @param[in] len the packet length
269 @param[in] gcs_member_id the member_id which sent the message
270
271 @return the operation status
272 @retval 0 OK
273 @retval !=0 Error on queue
274 */
276 const uchar *data, ulong len,
277 const Gcs_member_identifier &gcs_member_id) override;
278
279 /**
280 This member function SHALL certify the set of items against transactions
281 that have already passed the certification test.
282
283 @param snapshot_version The incoming transaction snapshot version.
284 @param write_set The incoming transaction write set.
285 @param is_gtid_specified True in case GTID is specified for this trx
286 @param member_uuid The UUID of the member from which this
287 transaction originates.
288 @param gle The incoming transaction global identifier
289 event.
290 @param local_transaction True if this transaction did originate from
291 this member, false otherwise.
292
293 @retval >0 transaction identifier (positively certified).
294 If generate_group_id is false and certification
295 positive a 1 is returned;
296 @retval 0 negatively certified;
297 @retval -1 error.
298 */
299 gr::Certified_gtid certify(Gtid_set *snapshot_version,
300 std::list<const char *> *write_set,
301 bool is_gtid_specified, const char *member_uuid,
302 Gtid_log_event *gle, bool local_transaction);
303
304 /**
305 Returns the transactions in stable set in text format, that is, the set of
306 transactions already applied on all group members.
307
308 @param[out] buffer Pointer to pointer to string. The method will set it to
309 point to the newly allocated buffer, or NULL on out of
310 memory.
311 Caller must free the allocated memory.
312 @param[out] length Length of the generated string.
313
314 @return the operation status
315 @retval 0 OK
316 @retval !=0 Out of memory error
317 */
319 size_t *length) override;
320
321 /**
322 Retrieves the current certification info.
323
324 @note if concurrent access is introduce to these variables,
325 locking is needed in this method
326
327 @param[out] cert_info a pointer to retrieve the certification info
328 */
330 std::map<std::string, std::string> *cert_info) override;
331
332 /**
333 Retrieves the current certification info.
334
335 @note if concurrent access is introduce to these variables,
336 locking is needed in this method
337
338 @param[out] recovery_metadata_message Retrieves the metadata message
339
340 @return the operation status
341 @retval false OK
342 @retval true Error
343 */
345 Recovery_metadata_message *recovery_metadata_message) override;
346
347 /**
348 Sets the certification info according to the given value.
349
350 @note if concurrent access is introduce to these variables,
351 locking is needed in this method
352
353 @param[in] cert_info certification info retrieved from recovery procedure
354
355 @retval > 0 Error during setting certification info.
356 @retval = 0 Everything went fine.
357 */
359 std::map<std::string, std::string> *cert_info) override;
360
361 /**
362 The received certification info from Recovery Metadata is decoded,
363 compressed and added to the member certification info for certification.
364
365 @note if concurrent access is introduce to these variables,
366 locking is needed in this method
367
368 @param[in] recovery_metadata_message the pointer to
369 Recovery_metadata_message.
370
371 @return the operation status
372 @retval false OK
373 @retval true Error
374 */
376 Recovery_metadata_message *recovery_metadata_message) override;
377 /**
378 Initializes the gtid_executed set.
379
380 @return the operation status
381 @retval false OK
382 @retval true Error
383 */
385
386 /**
387 Get the number of postively certified transactions by the certifier
388 */
390
391 /**
392 Get method to retrieve the number of negatively certified transactions.
393 */
395
396 /**
397 Get method to retrieve the certification db size.
398 */
400
401 /**
402 Get method to retrieve the last conflict free transaction.
403
404 @param[out] value The last conflict free transaction
405 */
406 void get_last_conflict_free_transaction(std::string *value) override;
407
408 /**
409 Generate group GTID for a view change log event.
410 @return Generated gtid and Gtid generation result
411 @see Return_status
412 */
413 std::pair<Gtid, mysql::utils::Return_status>
415
416 /**
417 Public method to add the given GTID value in the group_gtid_executed set
418 which is used to support skip gtid functionality.
419
420 @param[in] gtid GTID to be added
421
422 @retval 1 error during addition.
423 @retval 0 success.
424 */
425 int add_gtid_to_group_gtid_executed(const Gtid &gtid);
426
427 /**
428 Enables conflict detection.
429 */
430 void enable_conflict_detection() override;
431
432 /**
433 Disables conflict detection.
434 */
435 void disable_conflict_detection() override;
436
437 /**
438 Check if conflict detection is enable.
439
440 @retval True conflict detection is enable
441 @retval False otherwise
442 */
443 bool is_conflict_detection_enable() override;
444
445 /**
446 Compute GTID intervals.
447 */
449
450 /**
451 Validates if garbage collect should run against the intersection of the
452 received transactions stable sets.
453
454 @param executed_gtid_set intersection gtid set
455 @param on_member_join call due to member joining
456 */
457 void garbage_collect(Gtid_set *executed_gtid_set = nullptr,
458 bool on_member_join = false) override;
459
460 private:
461 /**
462 Key used to store group_gtid_executed on certification
463 info on View_change_log_event.
464 */
465 static const std::string GTID_EXTRACTED_NAME;
466
467 /**
468 Is certifier initialized.
469 */
470 std::atomic<bool> initialized{false};
471
472 /**
473 Variable to store the sidno used for transactions which will be logged
474 with the group_uuid.
475 */
477
478 /**
479 The sidno used for view log events as seen by the group sid map
480 */
482 /**
483 The sidno used for view log events as seen by the server sid map
484 */
486
487 /**
488 Method to initialize the group_gtid_executed gtid set with the server gtid
489 executed set and applier retrieved gtid set values.
490
491 @param get_server_gtid_retrieved add applier retrieved gtid set to
492 group_gtid_executed gtid set
493
494 @retval 1 error during initialization
495 @retval 0 success
496
497 */
498 int initialize_server_gtid_set(bool get_server_gtid_retrieved = false);
499
500 /**
501 This function updates parallel applier indexes.
502 It must be called for each remote transaction.
503
504 @param[in] update_parallel_applier_last_committed_global
505 If true parallel_applier_last_committed_global
506 is updated to the current sequence number
507 (before update sequence number).
508
509 Note: parallel_applier_last_committed_global should be updated
510 on the following situations:
511 1) Transaction without write set is certified, since it
512 represents the lowest last_committed for all future
513 transactions;
514 2) After certification info garbage collection, since we
515 do not know what write sets were purged, which may cause
516 transactions last committed to be incorrectly computed.
517 */
519 bool update_parallel_applier_last_committed_global);
520
521 /**
522 Internal method to add the given gtid gno in the group_gtid_executed set.
523 This will be used in the skip gtid implementation.
524
525 @note this will update the last know local transaction GTID.
526
527 @param[in] sidno rpl_sidno part of the executing gtid of the ongoing
528 transaction.
529
530 @param[in] gno rpl_gno part of the executing gtid of the ongoing
531 transaction.
532 */
534
535 /// @brief Returns group_executed_gtid_set or group_extracted_gtid_set while
536 /// certifying already applied transactions from the donor
537 /// @returns Pointer to the 'correct' group_gtid_set
538 const Gtid_set *get_group_gtid_set() const;
539
540 /// @brief Returns group_executed_gtid_set or group_extracted_gtid_set while
541 /// certifying already applied transactions from the donor
542 /// @returns Pointer to the 'correct' group_gtid_set
544
545 /// @brief This function determines three sidnos for a specific TSID
546 /// based on information obtained from the Gtid_log_event.
547 /// @param gle Gtid_log_event from which tsid will be extracted
548 /// @param is_gtid_specified True in case GTID is specified
549 /// @param snapshot_gtid_set Snapshot GTIDs
550 /// @param group_gtid_set Current GTID set
551 /// @return A tuple of:
552 /// - group_sidno Sidno relative to the group sid map
553 /// - gtid_snapshot_sidno Sidno relative to the snapshot sid map
554 /// - gtid_global_sidno Sidno relative to the global sid map
555 /// - return status
556 /// @details
557 /// We need to ensure that group sidno does exist on snapshot
558 /// version due to the following scenario:
559 /// 1) Member joins the group.
560 /// 2) Goes through recovery procedure, view change is queued to
561 /// apply, member is marked ONLINE. This requires
562 /// --group_replication_recovery_complete_at=TRANSACTIONS_CERTIFIED
563 /// to happen.
564 /// 3) Despite the view change log event is still being applied,
565 /// since the member is already ONLINE it can execute
566 /// transactions. The first transaction from this member will
567 /// not include any group GTID, since no group transaction is
568 /// yet applied.
569 /// 4) As a result of this sequence snapshot_version will not
570 /// contain any group GTID and the below instruction
571 /// snapshot_version->_add_gtid(group_sidno, result);
572 /// would fail because of that
573 std::tuple<rpl_sidno, rpl_sidno, rpl_sidno, mysql::utils::Return_status>
574 extract_sidno(Gtid_log_event &gle, bool is_gtid_specified,
575 Gtid_set &snapshot_gtid_set, Gtid_set &group_gtid_set);
576
577 /// @brief Internal helper method for ending certification, determination
578 /// of final GTID values after certification according to certification result
579 /// @param[in] gtid_server_sidno SIDNO for transaction GTID as represented in
580 /// the server (global sid map)
581 /// @param[in] gtid_group_sidno SIDNO for transaction GTID as represented in
582 /// the group
583 /// @param[in] generated_gno GNO generated for the transaction
584 /// @param[in] is_gtid_specified True if GTID was specified
585 /// @param[in] local_transaction True in case this transaction originates
586 /// from the this server
587 /// @param[in] certification_result Determined certification result
589 const rpl_sidno &gtid_server_sidno, const rpl_sidno &gtid_group_sidno,
590 const rpl_gno &generated_gno, bool is_gtid_specified,
591 bool local_transaction,
592 const gr::Certification_result &certification_result);
593
594 /// @brief Adds the transaction's write set to certification info.
595 /// @param[out] transaction_last_committed The transaction's logical
596 /// timestamps used for MTS
597 /// @param[in,out] snapshot_version The incoming transaction snapshot
598 /// version.
599 /// @param[in, out] write_set The incoming transaction write set.
600 /// @param[in] local_transaction True in case this transaction originates
601 /// from the this server
603 int64 &transaction_last_committed, Gtid_set *snapshot_version,
604 std::list<const char *> *write_set, bool local_transaction);
605
606 /// @brief Updates parallel applier indexes in GLE
607 /// @param gle Gle currently processed
608 /// @param has_write_set True in case transaction write set is not empty
609 /// @param has_write_set_large_size True in case number of write sets in
610 /// transactions is greater than
611 /// group_replication_preemptive_garbage_collection_rows_threshold
612 /// @param transaction_last_committed The transaction's logical timestamps
613 /// used for MTS
615 Gtid_log_event &gle, bool has_write_set, bool has_write_set_large_size,
616 int64 transaction_last_committed);
617
618 bool inline is_initialized() { return initialized; }
619
620 /**
621 This shall serialize the certification info stored in protobuf map format,
622 and then compress provided serialized string. The compressed payload is
623 stored into multiple buffer containers of the output list.
624
625 @param[in] cert_info the certification info stored in protobuf map.
626 @param[out] uncompresssed_buffer the buffer for uncompressed data.
627 @param[out] compressor_list the certification info in compressed form
628 splitted into multiple container of list.
629 @param[in] compression_type the type of compression used
630
631 @return the operation status
632 @retval false OK
633 @retval true Error
634 */
636 unsigned char **uncompresssed_buffer,
637 std::vector<GR_compress *> &compressor_list,
638 GR_compress::enum_compression_type compression_type);
639
640 /**
641 Sets the certification info according to the given value.
642 This shall uncompress and then convert uncompressed string into the protobuf
643 map format storing certification info. This certification info is added to
644 certifier's certification info.
645
646 @note if concurrent access is introduce to these variables,
647 locking is needed in this method
648
649 @param[in] compression_type the compression type
650 @param[in] buffer the compressed certification info retrieved from
651 recovery procedure.
652 @param[in] buffer_length the size of the compressed retrieved
653 certification info.
654 @param[in] uncompressed_buffer_length the size of the uncompressed
655 certification info before it was
656 compressed.
657
658 @return the operation status
659 @retval false OK
660 @retval true Error
661 */
663 GR_compress::enum_compression_type compression_type,
664 const unsigned char *buffer, unsigned long long buffer_length,
665 unsigned long long uncompressed_buffer_length);
666
667 /**
668 Empties certification info.
669 */
671
672 /**
673 Method to clear the members.
674 */
675 void clear_members();
676
677 /**
678 Last conflict free transaction identification.
679 */
681
682 /**
683 Certification database.
684 */
687
692
693#if !defined(NDEBUG)
696#endif
697
699
700 /**
701 Stable set and garbage collector variables.
702 */
707
708 std::vector<std::string> members;
709
710 /*
711 Flag to indicate that certifier is handling already applied
712 transactions during distributed recovery procedure.
713
714 On donor we may have local transactions certified after
715 View_change_log_event (VCLE) logged into binary log before VCLE.
716 That is, these local transactions will be appear on recovery
717 and also on GCS messages. One can see on example scenario below:
718
719 GCS order | donor binary log order | joiner apply order
720 -----------+------------------------+--------------------
721 T1 | T1 | T1
722 T2 | T2 | T2
723 V1 | T3 | T3 (recovery)
724 T3 | V1 | V1
725 | | T3 (GCS)
726 -----------+------------------------+--------------------
727
728 T3 is delivered to donor by both recovery and GCS, so joiner needs
729 to ensure that T3 has the same global identifier on both cases, so
730 that it is correctly skipped on the second time it is applied.
731
732 We ensure that T3 (and other transactions on that situation) have
733 the same global identifiers on joiner by:
734 1) When the VCLE is applied, we set on joiner certification info
735 the same exact certification that was on donor, including the
736 set of certified transactions before the joiner joined:
737 group_gtid_extracted.
738 2) We compare group_gtid_extracted and group_gtid_executed:
739 If group_gtid_extracted is a non equal subset of
740 group_gtid_executed, it means that we are on the above
741 scenario, that is, when applying the last transaction from
742 the distributed recovery process we have more transactions
743 than the ones certified before the view on which joiner joined.
744 So until group_gtid_extracted is a non equal subset of
745 group_gtid_executed certifier will generate transactions ids
746 following group_gtid_extracted so that we have the same exact
747 ids that donor has.
748 3) When joiner group_gtid_extracted and group_gtid_executed are
749 equal, joiner switches to its regular ids generation mode,
750 generating ids from group_gtid_executed.
751 */
753
754 /*
755 Sid map to store the GTIDs that are executed in the group.
756 */
758
759 /*
760 A Gtid_set containing the already executed for the group.
761 This is used to support skip_gtid.
762 */
764
765 /**
766 A Gtid_set which contains the gtid extracted from the certification info
767 map of the donor. It is the set of transactions that is executed at the
768 time of View_change_log_event at donor.
769 */
771
772 /// Object responsible for generation of the GTIDs for transactions with
773 /// gtid_next equal to AUTOMATIC (tagged/untagged)
775
776 /**
777 Conflict detection is performed when:
778 1) group is on multi-master mode;
779 2) group is on single-primary mode and primary is applying
780 relay logs with transactions from a previous primary.
781 */
783
785
786 /**
787 Broadcast thread.
788 */
790
791 /**
792 Adds an item from transaction writeset to the certification DB.
793 @param[in] item item in the writeset to be added to the
794 Certification DB.
795 @param[in] snapshot_version Snapshot version of the incoming transaction
796 which modified the above mentioned item.
797 @param[out] item_previous_sequence_number
798 The previous parallel applier sequence number
799 for this item.
800
801 @retval False successfully added to the map.
802 True otherwise.
803 */
804 bool add_item(const char *item, Gtid_set_ref *snapshot_version,
805 int64 *item_previous_sequence_number);
806
807 /**
808 Find the snapshot_version corresponding to an item. Return if
809 it exists, other wise return NULL;
810
811 @param[in] item item for the snapshot version.
812 @retval Gtid_set pointer if exists in the map.
813 Otherwise 0;
814 */
816
817 /**
818 Clear incoming queue.
819 */
820 void clear_incoming();
821
822 /*
823 Update method to store the count of the positively and negatively
824 certified transaction on a particular group member.
825 */
826 void update_certified_transaction_count(bool result, bool local_transaction);
827
828 /*
829 The first remote transaction certified does need to reset
830 replication_group_applier channel previous transaction
831 sequence_number.
832 */
834
835 /**
836 Removes the intersection of the received transactions stable
837 sets from certification database.
838
839 @param intersection_gtid_set intersection gtid set
840 @param preemptive is a preemptive run
841 */
842 void garbage_collect_internal(Gtid_set *intersection_gtid_set,
843 bool preemptive = false);
844
845 /**
846 Computes intersection between all sets received, so that we
847 have the already applied transactions on all servers.
848
849 @return the operation status
850 @retval false it did not run garbage_collect
851 @retval true it did run garbage_collect
852 */
854
856 // stable set successfully updated
858 // stable set already contains set
860 // not able to update due error
862 };
863
864 /**
865 * Update stable set with set if not already contained.
866 *
867 * @param set Gtid to add to stable set
868 *
869 * @return status of operation
870 */
872};
873
874/*
875 @class Gtid_Executed_Message
876
877 Class to convey the serialized contents of the previously executed GTIDs
878 */
880 public:
882 // This type should not be used anywhere.
884
885 // Length of the payload item: variable
887
888 // Length of the payload item: 8 bytes
890
891 // No valid type codes can appear after this one.
892 PIT_MAX = 3
893 };
894
895 /**
896 Gtid_Executed_Message constructor
897 */
900
901 /**
902 Appends Gtid executed information in a raw format
903
904 * @param[in] gtid_data encoded GTID data
905 * @param[in] len GTID data length
906 */
907 void append_gtid_executed(uchar *gtid_data, size_t len);
908
909 /**
910 Return the time at which the message contained in the buffer was sent.
911 @see Metrics_handler::get_current_time()
912
913 @param[in] buffer the buffer to decode from.
914 @param[in] length the buffer length
915
916 @return the time on which the message was sent.
917 */
918 static uint64_t get_sent_timestamp(const unsigned char *buffer,
919 size_t length);
920
921 protected:
922 /*
923 Implementation of the template methods of Gcs_plugin_message
924 */
925 void encode_payload(std::vector<unsigned char> *buffer) const override;
926 void decode_payload(const unsigned char *buffer,
927 const unsigned char *) override;
928
929 private:
930 std::vector<uchar> data;
931};
932
933#endif /* CERTIFIER_INCLUDE */
This class is a core component of the database state machine replication protocol.
Definition: certifier.h:132
mysql_cond_t broadcast_dispatcher_cond
Definition: certifier.h:179
mysql_mutex_t broadcast_dispatcher_lock
Definition: certifier.h:178
Certifier_broadcast_thread()
Certifier_broadcast_thread constructor.
Definition: certifier.cc:54
THD * broadcast_thd
Definition: certifier.h:174
int initialize()
Initialize broadcast thread.
Definition: certifier.cc:78
int terminate()
Terminate broadcast thread.
Definition: certifier.cc:106
mysql_mutex_t broadcast_run_lock
Definition: certifier.h:176
static const int BROADCAST_GTID_EXECUTED_PERIOD
Period (in seconds) between stable transactions set broadcast.
Definition: certifier.h:167
int broadcast_gtid_executed()
Broadcast local GTID_EXECUTED to group.
Definition: certifier.cc:207
size_t broadcast_counter
Definition: certifier.h:181
int broadcast_gtid_executed_period
Definition: certifier.h:182
bool aborted
Thread control.
Definition: certifier.h:173
void dispatcher()
Broadcast thread worker method.
Definition: certifier.cc:134
my_thread_handle broadcast_pthd
Definition: certifier.h:175
virtual ~Certifier_broadcast_thread()
Definition: certifier.cc:71
thread_state broadcast_thd_state
Definition: certifier.h:180
mysql_cond_t broadcast_run_cond
Definition: certifier.h:177
Definition: certifier.h:194
virtual void handle_view_change()=0
virtual ulonglong get_certification_info_size() override=0
virtual bool is_conflict_detection_enable()=0
~Certifier_interface() override=default
virtual void get_certification_info(std::map< std::string, std::string > *cert_info)=0
virtual int handle_certifier_data(const uchar *data, ulong len, const Gcs_member_identifier &gcs_member_id)=0
virtual int set_certification_info(std::map< std::string, std::string > *cert_info)=0
virtual void disable_conflict_detection()=0
virtual void garbage_collect(Gtid_set *executed_gtid_set=nullptr, bool on_member_join=false)=0
virtual void enable_conflict_detection()=0
virtual bool set_certification_info_recovery_metadata(Recovery_metadata_message *recovery_metadata_message)=0
virtual bool get_certification_info_recovery_metadata(Recovery_metadata_message *recovery_metadata_message)=0
virtual bool initialize_server_gtid_set_after_distributed_recovery()=0
Definition: certifier_stats_interface.h:29
Definition: certifier.h:219
gr::Certified_gtid certify(Gtid_set *snapshot_version, std::list< const char * > *write_set, bool is_gtid_specified, const char *member_uuid, Gtid_log_event *gle, bool local_transaction)
This member function SHALL certify the set of items against transactions that have already passed the...
Definition: certifier.cc:812
static const std::string GTID_EXTRACTED_NAME
Key used to store group_gtid_executed on certification info on View_change_log_event.
Definition: certifier.h:465
int get_group_stable_transactions_set_string(char **buffer, size_t *length) override
Returns the transactions in stable set in text format, that is, the set of transactions already appli...
Definition: certifier.cc:1053
const Gtid_set * get_group_gtid_set() const
Returns group_executed_gtid_set or group_extracted_gtid_set while certifying already applied transact...
Definition: certifier.cc:975
Tsid_map * certification_info_tsid_map
Definition: certifier.h:686
Certification_info certification_info
Certification database.
Definition: certifier.h:685
int set_certification_info(std::map< std::string, std::string > *cert_info) override
Sets the certification info according to the given value.
Definition: certifier.cc:1910
bool set_certification_info_part(GR_compress::enum_compression_type compression_type, const unsigned char *buffer, unsigned long long buffer_length, unsigned long long uncompressed_buffer_length)
Sets the certification info according to the given value.
Definition: certifier.cc:1650
bool conflict_detection_enable
Conflict detection is performed when: 1) group is on multi-master mode; 2) group is on single-primary...
Definition: certifier.h:782
bool is_conflict_detection_enable() override
Check if conflict detection is enable.
Definition: certifier.cc:2075
bool set_certification_info_recovery_metadata(Recovery_metadata_message *recovery_metadata_message) override
The received certification info from Recovery Metadata is decoded, compressed and added to the member...
Definition: certifier.cc:1521
bool initialize_server_gtid_set_after_distributed_recovery() override
Initializes the gtid_executed set.
Definition: certifier.cc:1728
int handle_certifier_data(const uchar *data, ulong len, const Gcs_member_identifier &gcs_member_id) override
Queues the packet coming from the reader for future processing.
Definition: certifier.cc:1277
int64 parallel_applier_sequence_number
Definition: certifier.h:691
void clear_certification_info()
Empties certification info.
Definition: certifier.cc:489
rpl_sidno group_gtid_tsid_map_group_sidno
Variable to store the sidno used for transactions which will be logged with the group_uuid.
Definition: certifier.h:476
Tsid_map * group_gtid_tsid_map
Definition: certifier.h:757
Gtid_set * stable_gtid_set
Definition: certifier.h:705
int initialize(ulonglong gtid_assignment_block_size)
Initialize certifier.
Definition: certifier.cc:516
bool add_item(const char *item, Gtid_set_ref *snapshot_version, int64 *item_previous_sequence_number)
Adds an item from transaction writeset to the certification DB.
Definition: certifier.cc:999
void clear_members()
Method to clear the members.
Definition: certifier.cc:510
Gtid_set * group_gtid_extracted
A Gtid_set which contains the gtid extracted from the certification info map of the donor.
Definition: certifier.h:770
std::atomic< bool > initialized
Is certifier initialized.
Definition: certifier.h:470
void increment_parallel_applier_sequence_number(bool update_parallel_applier_last_committed_global)
This function updates parallel applier indexes.
Definition: certifier.cc:554
void disable_conflict_detection() override
Disables conflict detection.
Definition: certifier.cc:2059
Synchronized_queue< Data_packet * > * incoming
Definition: certifier.h:706
std::pair< Gtid, mysql::utils::Return_status > generate_view_change_group_gtid()
Generate group GTID for a view change log event.
Definition: certifier.cc:1884
std::unordered_map< std::string, Gtid_set_ref *, std::hash< std::string >, std::equal_to< std::string >, Malloc_allocator< std::pair< const std::string, Gtid_set_ref * > > > Certification_info
Definition: certifier.h:225
void update_certified_transaction_count(bool result, bool local_transaction)
Definition: certifier.cc:1986
void clear_incoming()
Clear incoming queue.
Definition: certifier.cc:500
Certifier()
Definition: certifier.cc:257
gr::Certification_result add_writeset_to_certification_info(int64 &transaction_last_committed, Gtid_set *snapshot_version, std::list< const char * > *write_set, bool local_transaction)
Adds the transaction's write set to certification info.
Definition: certifier.cc:664
enum_update_status
Definition: certifier.h:855
@ STABLE_SET_UPDATED
Definition: certifier.h:857
@ STABLE_SET_ALREADY_CONTAINED
Definition: certifier.h:859
@ STABLE_SET_ERROR
Definition: certifier.h:861
bool is_first_remote_transaction_certified
Definition: certifier.h:833
std::vector< std::string > members
Definition: certifier.h:708
~Certifier() override
Definition: certifier.cc:308
rpl_sidno views_sidno_group_representation
The sidno used for view log events as seen by the group sid map.
Definition: certifier.h:481
void get_last_conflict_free_transaction(std::string *value) override
Get method to retrieve the last conflict free transaction.
Definition: certifier.cc:2031
rpl_sidno views_sidno_server_representation
The sidno used for view log events as seen by the server sid map.
Definition: certifier.h:485
bool get_certification_info_recovery_metadata(Recovery_metadata_message *recovery_metadata_message) override
Retrieves the current certification info.
Definition: certifier.cc:1791
ulonglong get_certification_info_size() override
Get method to retrieve the certification db size.
Definition: certifier.cc:2027
void get_certification_info(std::map< std::string, std::string > *cert_info) override
Retrieves the current certification info.
Definition: certifier.cc:1487
bool certifying_already_applied_transactions
Definition: certifier.h:752
Checkable_rwlock * stable_gtid_set_lock
Stable set and garbage collector variables.
Definition: certifier.h:703
bool same_member_message_discarded
Definition: certifier.h:695
ulonglong positive_cert
Definition: certifier.h:688
ulonglong get_negative_certified() override
Get method to retrieve the number of negatively certified transactions.
Definition: certifier.cc:2025
enum enum_update_status update_stable_set(const Gtid_set &set)
Update stable set with set if not already contained.
Definition: certifier.cc:1260
bool compress_packet(ProtoCertificationInformationMap &cert_info, unsigned char **uncompresssed_buffer, std::vector< GR_compress * > &compressor_list, GR_compress::enum_compression_type compression_type)
This shall serialize the certification info stored in protobuf map format, and then compress provided...
Definition: certifier.cc:1746
ulonglong negative_cert
Definition: certifier.h:689
protobuf_replication_group_recovery_metadata::CertificationInformationMap ProtoCertificationInformationMap
Definition: certifier.h:228
void garbage_collect_internal(Gtid_set *intersection_gtid_set, bool preemptive=false)
Removes the intersection of the received transactions stable sets from certification database.
Definition: certifier.cc:1131
bool intersect_members_gtid_executed_and_garbage_collect()
Computes intersection between all sets received, so that we have the already applied transactions on ...
Definition: certifier.cc:1354
mysql_mutex_t LOCK_certification_info
Definition: certifier.h:698
ulonglong get_positive_certified() override
Get the number of postively certified transactions by the certifier.
Definition: certifier.cc:2023
int initialize_server_gtid_set(bool get_server_gtid_retrieved=false)
Method to initialize the group_gtid_executed gtid set with the server gtid executed set and applier r...
Definition: certifier.cc:333
gr::Gtid_generator gtid_generator
Object responsible for generation of the GTIDs for transactions with gtid_next equal to AUTOMATIC (ta...
Definition: certifier.h:774
int add_gtid_to_group_gtid_executed(const Gtid &gtid)
Public method to add the given GTID value in the group_gtid_executed set which is used to support ski...
Definition: certifier.cc:963
void add_to_group_gtid_executed_internal(rpl_sidno sidno, rpl_gno gno)
Internal method to add the given gtid gno in the group_gtid_executed set.
Definition: certifier.cc:469
void gtid_intervals_computation()
Compute GTID intervals.
Definition: certifier.cc:985
int64 parallel_applier_last_committed_global
Definition: certifier.h:690
void garbage_collect(Gtid_set *executed_gtid_set=nullptr, bool on_member_join=false) override
Validates if garbage collect should run against the intersection of the received transactions stable ...
Definition: certifier.cc:1084
void update_transaction_dependency_timestamps(Gtid_log_event &gle, bool has_write_set, bool has_write_set_large_size, int64 transaction_last_committed)
Updates parallel applier indexes in GLE.
Definition: certifier.cc:742
gr::Certified_gtid end_certification_result(const rpl_sidno &gtid_server_sidno, const rpl_sidno &gtid_group_sidno, const rpl_gno &generated_gno, bool is_gtid_specified, bool local_transaction, const gr::Certification_result &certification_result)
Internal helper method for ending certification, determination of final GTID values after certificati...
Definition: certifier.cc:641
void handle_view_change() override
Handle view changes on certifier.
Definition: certifier.cc:1474
Gtid_set * get_certified_write_set_snapshot_version(const char *item)
Find the snapshot_version corresponding to an item.
Definition: certifier.cc:1035
bool is_initialized()
Definition: certifier.h:618
void enable_conflict_detection() override
Enables conflict detection.
Definition: certifier.cc:2047
bool certifier_garbage_collection_block
Definition: certifier.h:694
Gtid_set * group_gtid_executed
Definition: certifier.h:763
std::tuple< rpl_sidno, rpl_sidno, rpl_sidno, mysql::utils::Return_status > extract_sidno(Gtid_log_event &gle, bool is_gtid_specified, Gtid_set &snapshot_gtid_set, Gtid_set &group_gtid_set)
This function determines three sidnos for a specific TSID based on information obtained from the Gtid...
Definition: certifier.cc:594
static const std::string CERTIFICATION_INFO_ERROR_NAME
Key used to store errors in the certification info on View_change_log_event.
Definition: certifier.h:237
Gtid last_conflict_free_transaction
Last conflict free transaction identification.
Definition: certifier.h:680
Tsid_map * stable_tsid_map
Definition: certifier.h:704
mysql_mutex_t LOCK_members
Definition: certifier.h:784
int terminate()
Terminate certifier.
Definition: certifier.cc:545
Certifier_broadcast_thread * broadcast_thread
Broadcast thread.
Definition: certifier.h:789
This has the functionality of mysql_rwlock_t, with two differences:
Definition: rpl_gtid.h:324
enum_compression_type
Compression Type.
Definition: gr_compression.h:46
It represents the identity of a group member within a certain group.
Definition: gcs_member_identifier.h:40
Definition: certifier.h:879
enum_payload_item_type
Definition: certifier.h:881
@ PIT_SENT_TIMESTAMP
Definition: certifier.h:889
@ PIT_MAX
Definition: certifier.h:892
@ PIT_GTID_EXECUTED
Definition: certifier.h:886
@ PIT_UNKNOWN
Definition: certifier.h:883
Gtid_Executed_Message()
Gtid_Executed_Message constructor.
Definition: certifier.cc:2091
std::vector< uchar > data
Definition: certifier.h:930
static uint64_t get_sent_timestamp(const unsigned char *buffer, size_t length)
Return the time at which the message contained in the buffer was sent.
Definition: certifier.cc:2124
~Gtid_Executed_Message() override
void append_gtid_executed(uchar *gtid_data, size_t len)
Appends Gtid executed information in a raw format.
Definition: certifier.cc:2096
void encode_payload(std::vector< unsigned char > *buffer) const override
Encodes the contents of this instance payload into the buffer.
Definition: certifier.cc:2100
void decode_payload(const unsigned char *buffer, const unsigned char *) override
Decodes the contents of the buffer and sets the payload field values according to the values decoded.
Definition: certifier.cc:2111
This is a subclass if Gtid_event and Log_event.
Definition: log_event.h:3951
This class extends Gtid_set to include a reference counter.
Definition: certifier.h:75
int64 parallel_applier_sequence_number
Definition: certifier.h:107
virtual ~Gtid_set_ref()=default
size_t link()
Increment the number of references by one.
Definition: certifier.h:89
Gtid_set_ref(Tsid_map *tsid_map, int64 parallel_applier_sequence_number)
Definition: certifier.h:77
size_t unlink()
Decrement the number of references by one.
Definition: certifier.h:96
int64 get_parallel_applier_sequence_number() const
Definition: certifier.h:101
size_t reference_counter
Definition: certifier.h:106
Represents a set of GTIDs.
Definition: rpl_gtid.h:1556
Tsid_map * tsid_map
Tsid_map associated with this Gtid_set.
Definition: rpl_gtid.h:2467
Malloc_allocator is a C++ STL memory allocator based on my_malloc/my_free.
Definition: malloc_allocator.h:63
This is the base GCS plugin message.
Definition: gcs_plugin_messages.h:64
Definition: recovery_metadata_message.h:36
Definition: plugin_utils.h:182
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Represents a bidirectional map between TSID and SIDNO.
Definition: rpl_gtid.h:749
Class that aggregates important information about already certified gtid.
Definition: certified_gtid.h:46
This class is responsible for generating GTIDs in the Certifier.
Definition: gtid_generator.h:47
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
unsigned char uchar
Definition: my_inttypes.h:52
int64_t int64
Definition: my_inttypes.h:68
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
Certification_result
Represents result of certification function.
Definition: certification_result.h:30
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:418
std::unordered_map< Key, Value, Hash, Key_equal, ut::allocator< std::pair< const Key, Value > > > unordered_map
Definition: ut0new.h:2898
std::set< Key, Compare, ut::allocator< Key > > set
Specialization of set which uses ut_allocator.
Definition: ut0new.h:2882
Experimental API header.
mysql::gtid::gno_t rpl_gno
GNO, the second (numeric) component of a GTID, is an alias of mysql::gtid::gno_t.
Definition: rpl_gtid.h:112
cs::index::rpl_sidno rpl_sidno
Type of SIDNO (source ID number, first component of GTID)
Definition: rpl_gtid.h:108
TODO: Move this structure to mysql/binlog/event/control_events.h when we start using C++11.
Definition: rpl_gtid.h:1100
Definition: my_thread_bits.h:58
An instrumented cond structure.
Definition: mysql_cond_bits.h:50
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50
Definition: result.h:30
Definition: plugin_utils.h:48