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