MySQL 9.2.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:
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 @return the operation status
174 @retval 0 OK
175 @retval !=0 Error
176 */
177 int terminate();
178
179 /**
180 Broadcast thread worker method.
181 */
182 void dispatcher();
183
184 /**
185 Period (in seconds) between stable transactions set
186 broadcast.
187 */
188 static const int BROADCAST_GTID_EXECUTED_PERIOD = 60; // seconds
189
190 private:
191 /**
192 Thread control.
193 */
204
205 /**
206 Broadcast local GTID_EXECUTED to group.
207
208 @return the operation status
209 @retval 0 OK
210 @retval !=0 Error
211 */
213};
214
216 public:
217 ~Certifier_interface() override = default;
218 virtual void handle_view_change() = 0;
220 const uchar *data, ulong len,
221 const Gcs_member_identifier &gcs_member_id) = 0;
222
224 std::map<std::string, std::string> *cert_info) = 0;
226 Recovery_metadata_message *recovery_metadata_message) = 0;
228 std::map<std::string, std::string> *cert_info) = 0;
230 Recovery_metadata_message *recovery_metadata_message) = 0;
232 virtual void garbage_collect(Gtid_set *executed_gtid_set = nullptr,
233 bool on_member_join = false) = 0;
234 virtual void enable_conflict_detection() = 0;
235 virtual void disable_conflict_detection() = 0;
238};
239
241 public:
242 typedef std::unordered_map<
243 std::string, Gtid_set_ref *, std::hash<std::string>,
244 std::equal_to<std::string>,
247
248 typedef protobuf_replication_group_recovery_metadata::
249 CertificationInformationMap ProtoCertificationInformationMap;
250
251 Certifier();
252 ~Certifier() override;
253
254 /**
255 Key used to store errors in the certification info
256 on View_change_log_event.
257 */
258 static const std::string CERTIFICATION_INFO_ERROR_NAME;
259
260 /**
261 Initialize certifier.
262
263 @param gtid_assignment_block_size the group gtid assignment block size
264
265 @return the operation status
266 @retval 0 OK
267 @retval !=0 Error
268 */
269 int initialize(ulonglong gtid_assignment_block_size);
270
271 /**
272 Terminate certifier.
273
274 @return the operation status
275 @retval 0 OK
276 @retval !=0 Error
277 */
278 int terminate();
279
280 /**
281 Handle view changes on certifier.
282 */
283 void handle_view_change() override;
284
285 /**
286 Queues the packet coming from the reader for future processing.
287
288 @param[in] data the packet data
289 @param[in] len the packet length
290 @param[in] gcs_member_id the member_id which sent the message
291
292 @return the operation status
293 @retval 0 OK
294 @retval !=0 Error on queue
295 */
297 const uchar *data, ulong len,
298 const Gcs_member_identifier &gcs_member_id) override;
299
300 /**
301 This member function SHALL certify the set of items against transactions
302 that have already passed the certification test.
303
304 @param snapshot_version The incoming transaction snapshot version.
305 @param write_set The incoming transaction write set.
306 @param is_gtid_specified True in case GTID is specified for this trx
307 @param member_uuid The UUID of the member from which this
308 transaction originates.
309 @param gle The incoming transaction global identifier
310 event.
311 @param local_transaction True if this transaction did originate from
312 this member, false otherwise.
313
314 @retval >0 transaction identifier (positively certified).
315 If generate_group_id is false and certification
316 positive a 1 is returned;
317 @retval 0 negatively certified;
318 @retval -1 error.
319 */
320 gr::Certified_gtid certify(Gtid_set *snapshot_version,
321 std::list<const char *> *write_set,
322 bool is_gtid_specified, const char *member_uuid,
323 Gtid_log_event *gle, bool local_transaction);
324
325 /**
326 Returns the transactions in stable set in text format, that is, the set of
327 transactions already applied on all group members.
328
329 @param[out] buffer Pointer to pointer to string. The method will set it to
330 point to the newly allocated buffer, or NULL on out of
331 memory.
332 Caller must free the allocated memory.
333 @param[out] length Length of the generated string.
334
335 @return the operation status
336 @retval 0 OK
337 @retval !=0 Out of memory error
338 */
340 size_t *length) override;
341
342 /**
343 Retrieves the current certification info.
344
345 @note if concurrent access is introduce to these variables,
346 locking is needed in this method
347
348 @param[out] cert_info a pointer to retrieve the certification info
349 */
351 std::map<std::string, std::string> *cert_info) override;
352
353 /**
354 Retrieves the current certification info.
355
356 @note if concurrent access is introduce to these variables,
357 locking is needed in this method
358
359 @param[out] recovery_metadata_message Retrieves the metadata message
360
361 @return the operation status
362 @retval false OK
363 @retval true Error
364 */
366 Recovery_metadata_message *recovery_metadata_message) override;
367
368 /**
369 Sets the certification info according to the given value.
370
371 @note if concurrent access is introduce to these variables,
372 locking is needed in this method
373
374 @param[in] cert_info certification info retrieved from recovery procedure
375
376 @retval > 0 Error during setting certification info.
377 @retval = 0 Everything went fine.
378 */
380 std::map<std::string, std::string> *cert_info) override;
381
382 /**
383 The received certification info from Recovery Metadata is decoded,
384 compressed and added to the member certification info for certification.
385
386 @note if concurrent access is introduce to these variables,
387 locking is needed in this method
388
389 @param[in] recovery_metadata_message the pointer to
390 Recovery_metadata_message.
391
392 @return the operation status
393 @retval false OK
394 @retval true Error
395 */
397 Recovery_metadata_message *recovery_metadata_message) override;
398 /**
399 Initializes the gtid_executed set.
400
401 @return the operation status
402 @retval false OK
403 @retval true Error
404 */
406
407 /**
408 Get the number of postively certified transactions by the certifier
409 */
411
412 /**
413 Get method to retrieve the number of negatively certified transactions.
414 */
416
417 /**
418 Get method to retrieve the certification db size.
419 */
421
422 /**
423 Get method to retrieve the last conflict free transaction.
424
425 @param[out] value The last conflict free transaction
426 */
427 void get_last_conflict_free_transaction(std::string *value) override;
428
429 /**
430 Generate group GTID for a view change log event.
431 @return Generated gtid and Gtid generation result
432 @see Return_status
433 */
434 std::pair<Gtid, mysql::utils::Return_status>
436
437 /**
438 Public method to add the given GTID value in the group_gtid_executed set
439 which is used to support skip gtid functionality.
440
441 @param[in] gtid GTID to be added
442
443 @retval 1 error during addition.
444 @retval 0 success.
445 */
446 int add_gtid_to_group_gtid_executed(const Gtid &gtid);
447
448 /**
449 Enables conflict detection.
450 */
451 void enable_conflict_detection() override;
452
453 /**
454 Disables conflict detection.
455 */
456 void disable_conflict_detection() override;
457
458 /**
459 Check if conflict detection is enable.
460
461 @retval True conflict detection is enable
462 @retval False otherwise
463 */
464 bool is_conflict_detection_enable() override;
465
466 /**
467 Compute GTID intervals.
468 */
470
471 /**
472 Validates if garbage collect should run against the intersection of the
473 received transactions stable sets.
474
475 @param executed_gtid_set intersection gtid set
476 @param on_member_join call due to member joining
477 */
478 void garbage_collect(Gtid_set *executed_gtid_set = nullptr,
479 bool on_member_join = false) override;
480
481 private:
482 /**
483 Key used to store group_gtid_executed on certification
484 info on View_change_log_event.
485 */
486 static const std::string GTID_EXTRACTED_NAME;
487
488 /**
489 Is certifier initialized.
490 */
491 std::atomic<bool> initialized{false};
492
493 /**
494 Variable to store the sidno used for transactions which will be logged
495 with the group_uuid.
496 */
498
499 /**
500 The sidno used for view log events as seen by the group sid map
501 */
503 /**
504 The sidno used for view log events as seen by the server sid map
505 */
507
508 /**
509 Method to initialize the group_gtid_executed gtid set with the server gtid
510 executed set and applier retrieved gtid set values.
511
512 @param get_server_gtid_retrieved add applier retrieved gtid set to
513 group_gtid_executed gtid set
514
515 @retval 1 error during initialization
516 @retval 0 success
517
518 */
519 int initialize_server_gtid_set(bool get_server_gtid_retrieved = false);
520
521 /**
522 This function updates parallel applier indexes.
523 It must be called for each remote transaction.
524
525 @param[in] update_parallel_applier_last_committed_global
526 If true parallel_applier_last_committed_global
527 is updated to the current sequence number
528 (before update sequence number).
529 @param[in] increment_parallel_applier_sequence_number
530 If false (during certification garbage collection)
531 parallel_applier_last_committed_global is set to
532 parallel_applier_last_sequence_number and
533 parallel_applier_last_sequence_number is not updated
534
535 Note: parallel_applier_last_committed_global should be updated
536 on the following situations:
537 1) Transaction without write set is certified, since it
538 represents the lowest last_committed for all future
539 transactions;
540 2) After certification info garbage collection, since we
541 do not know what write sets were purged, which may cause
542 transactions last committed to be incorrectly computed.
543 */
545 bool update_parallel_applier_last_committed_global,
546 bool increment_parallel_applier_sequence_number);
547
548 /**
549 Internal method to add the given gtid gno in the group_gtid_executed set.
550 This will be used in the skip gtid implementation.
551
552 @note this will update the last know local transaction GTID.
553
554 @param[in] sidno rpl_sidno part of the executing gtid of the ongoing
555 transaction.
556
557 @param[in] gno rpl_gno part of the executing gtid of the ongoing
558 transaction.
559 */
561
562 /// @brief Returns group_executed_gtid_set or group_extracted_gtid_set while
563 /// certifying already applied transactions from the donor
564 /// @returns Pointer to the 'correct' group_gtid_set
565 const Gtid_set *get_group_gtid_set() const;
566
567 /// @brief Returns group_executed_gtid_set or group_extracted_gtid_set while
568 /// certifying already applied transactions from the donor
569 /// @returns Pointer to the 'correct' group_gtid_set
571
572 /// @brief This function determines three sidnos for a specific TSID
573 /// based on information obtained from the Gtid_log_event.
574 /// @param gle Gtid_log_event from which tsid will be extracted
575 /// @param is_gtid_specified True in case GTID is specified
576 /// @param snapshot_gtid_set Snapshot GTIDs
577 /// @param group_gtid_set Current GTID set
578 /// @return A tuple of:
579 /// - group_sidno Sidno relative to the group sid map
580 /// - gtid_snapshot_sidno Sidno relative to the snapshot sid map
581 /// - gtid_global_sidno Sidno relative to the global sid map
582 /// - return status
583 /// @details
584 /// We need to ensure that group sidno does exist on snapshot
585 /// version due to the following scenario:
586 /// 1) Member joins the group.
587 /// 2) Goes through recovery procedure, view change is queued to
588 /// apply, member is marked ONLINE. This requires
589 /// --group_replication_recovery_complete_at=TRANSACTIONS_CERTIFIED
590 /// to happen.
591 /// 3) Despite the view change log event is still being applied,
592 /// since the member is already ONLINE it can execute
593 /// transactions. The first transaction from this member will
594 /// not include any group GTID, since no group transaction is
595 /// yet applied.
596 /// 4) As a result of this sequence snapshot_version will not
597 /// contain any group GTID and the below instruction
598 /// snapshot_version->_add_gtid(group_sidno, result);
599 /// would fail because of that
600 std::tuple<rpl_sidno, rpl_sidno, rpl_sidno, mysql::utils::Return_status>
601 extract_sidno(Gtid_log_event &gle, bool is_gtid_specified,
602 Gtid_set &snapshot_gtid_set, Gtid_set &group_gtid_set);
603
604 /// @brief Internal helper method for ending certification, determination
605 /// of final GTID values after certification according to certification result
606 /// @param[in] gtid_server_sidno SIDNO for transaction GTID as represented in
607 /// the server (global sid map)
608 /// @param[in] gtid_group_sidno SIDNO for transaction GTID as represented in
609 /// the group
610 /// @param[in] generated_gno GNO generated for the transaction
611 /// @param[in] is_gtid_specified True if GTID was specified
612 /// @param[in] local_transaction True in case this transaction originates
613 /// from the this server
614 /// @param[in] certification_result Determined certification result
616 const rpl_sidno &gtid_server_sidno, const rpl_sidno &gtid_group_sidno,
617 const rpl_gno &generated_gno, bool is_gtid_specified,
618 bool local_transaction,
619 const gr::Certification_result &certification_result);
620
621 /// @brief Adds the transaction's write set to certification info.
622 /// @param[out] transaction_last_committed The transaction's logical
623 /// timestamps used for MTS
624 /// @param[in,out] snapshot_version The incoming transaction snapshot
625 /// version.
626 /// @param[in, out] write_set The incoming transaction write set.
627 /// @param[in] local_transaction True in case this transaction originates
628 /// from the this server
630 int64 &transaction_last_committed, Gtid_set *snapshot_version,
631 std::list<const char *> *write_set, bool local_transaction);
632
633 /// @brief Updates parallel applier indexes in GLE
634 /// @param gle Gle currently processed
635 /// @param has_write_set True in case transaction write set is not empty
636 /// @param has_write_set_large_size True in case number of write sets in
637 /// transactions is greater than
638 /// group_replication_preemptive_garbage_collection_rows_threshold
639 /// @param transaction_last_committed The transaction's logical timestamps
640 /// used for MTS
642 Gtid_log_event &gle, bool has_write_set, bool has_write_set_large_size,
643 int64 transaction_last_committed);
644
645 bool inline is_initialized() { return initialized; }
646
647 /**
648 This shall serialize the certification info stored in protobuf map format,
649 and then compress provided serialized string. The compressed payload is
650 stored into multiple buffer containers of the output list.
651
652 @param[in] cert_info the certification info stored in protobuf map.
653 @param[out] uncompresssed_buffer the buffer for uncompressed data.
654 @param[out] compressor_list the certification info in compressed form
655 splitted into multiple container of list.
656 @param[in] compression_type the type of compression used
657
658 @return the operation status
659 @retval false OK
660 @retval true Error
661 */
663 unsigned char **uncompresssed_buffer,
664 std::vector<GR_compress *> &compressor_list,
665 GR_compress::enum_compression_type compression_type);
666
667 /**
668 Sets the certification info according to the given value.
669 This shall uncompress and then convert uncompressed string into the protobuf
670 map format storing certification info. This certification info is added to
671 certifier's certification info.
672
673 @note if concurrent access is introduce to these variables,
674 locking is needed in this method
675
676 @param[in] compression_type the compression type
677 @param[in] buffer the compressed certification info retrieved from
678 recovery procedure.
679 @param[in] buffer_length the size of the compressed retrieved
680 certification info.
681 @param[in] uncompressed_buffer_length the size of the uncompressed
682 certification info before it was
683 compressed.
684
685 @return the operation status
686 @retval false OK
687 @retval true Error
688 */
690 GR_compress::enum_compression_type compression_type,
691 const unsigned char *buffer, unsigned long long buffer_length,
692 unsigned long long uncompressed_buffer_length);
693
694 /**
695 Empties certification info.
696 */
698
699 /**
700 Method to clear the members.
701 */
702 void clear_members();
703
704 /**
705 Last conflict free transaction identification.
706 */
708
709 /**
710 Certification database.
711 */
714
720
721#if !defined(NDEBUG)
724#endif
725
727
728 /**
729 Stable set and garbage collector variables.
730 */
735
736 std::vector<std::string> members;
737
738 /*
739 Flag to indicate that certifier is handling already applied
740 transactions during distributed recovery procedure.
741
742 On donor we may have local transactions certified after
743 View_change_log_event (VCLE) logged into binary log before VCLE.
744 That is, these local transactions will be appear on recovery
745 and also on GCS messages. One can see on example scenario below:
746
747 GCS order | donor binary log order | joiner apply order
748 -----------+------------------------+--------------------
749 T1 | T1 | T1
750 T2 | T2 | T2
751 V1 | T3 | T3 (recovery)
752 T3 | V1 | V1
753 | | T3 (GCS)
754 -----------+------------------------+--------------------
755
756 T3 is delivered to donor by both recovery and GCS, so joiner needs
757 to ensure that T3 has the same global identifier on both cases, so
758 that it is correctly skipped on the second time it is applied.
759
760 We ensure that T3 (and other transactions on that situation) have
761 the same global identifiers on joiner by:
762 1) When the VCLE is applied, we set on joiner certification info
763 the same exact certification that was on donor, including the
764 set of certified transactions before the joiner joined:
765 group_gtid_extracted.
766 2) We compare group_gtid_extracted and group_gtid_executed:
767 If group_gtid_extracted is a non equal subset of
768 group_gtid_executed, it means that we are on the above
769 scenario, that is, when applying the last transaction from
770 the distributed recovery process we have more transactions
771 than the ones certified before the view on which joiner joined.
772 So until group_gtid_extracted is a non equal subset of
773 group_gtid_executed certifier will generate transactions ids
774 following group_gtid_extracted so that we have the same exact
775 ids that donor has.
776 3) When joiner group_gtid_extracted and group_gtid_executed are
777 equal, joiner switches to its regular ids generation mode,
778 generating ids from group_gtid_executed.
779 */
781
782 /*
783 Sid map to store the GTIDs that are executed in the group.
784 */
786
787 /*
788 A Gtid_set containing the already executed for the group.
789 This is used to support skip_gtid.
790 */
792
793 /**
794 A Gtid_set which contains the gtid extracted from the certification info
795 map of the donor. It is the set of transactions that is executed at the
796 time of View_change_log_event at donor.
797 */
799
800 /// Object responsible for generation of the GTIDs for transactions with
801 /// gtid_next equal to AUTOMATIC (tagged/untagged)
803
804 /**
805 Conflict detection is performed when:
806 1) group is on multi-master mode;
807 2) group is on single-primary mode and primary is applying
808 relay logs with transactions from a previous primary.
809 */
811
813
814 /**
815 Broadcast thread.
816 */
818
819 /**
820 Adds an item from transaction writeset to the certification DB.
821 @param[in] item item in the writeset to be added to the
822 Certification DB.
823 @param[in] snapshot_version Snapshot version of the incoming transaction
824 which modified the above mentioned item.
825 @param[out] item_previous_sequence_number
826 The previous parallel applier sequence number
827 for this item.
828
829 @retval False successfully added to the map.
830 True otherwise.
831 */
832 bool add_item(const char *item, Gtid_set_ref *snapshot_version,
833 int64 *item_previous_sequence_number);
834
835 /**
836 Find the snapshot_version corresponding to an item. Return if
837 it exists, other wise return NULL;
838
839 @param[in] item item for the snapshot version.
840 @retval Gtid_set pointer if exists in the map.
841 Otherwise 0;
842 */
844
845 /**
846 Clear incoming queue.
847 */
848 void clear_incoming();
849
850 /*
851 Update method to store the count of the positively and negatively
852 certified transaction on a particular group member.
853 */
854 void update_certified_transaction_count(bool result, bool local_transaction);
855
856 /*
857 The first remote transaction certified does need to reset
858 replication_group_applier channel previous transaction
859 sequence_number.
860 */
862
863 /**
864 Removes the intersection of the received transactions stable
865 sets from certification database.
866
867 @param intersection_gtid_set intersection gtid set
868 @param preemptive is a preemptive run
869 */
870 void garbage_collect_internal(Gtid_set *intersection_gtid_set,
871 bool preemptive = false);
872
873 /**
874 Computes intersection between all sets received, so that we
875 have the already applied transactions on all servers.
876
877 @return the operation status
878 @retval false it did not run garbage_collect
879 @retval true it did run garbage_collect
880 */
882
884 // stable set successfully updated
886 // stable set already contains set
888 // not able to update due error
890 };
891
892 /**
893 * Update stable set with set if not already contained.
894 *
895 * @param set Gtid to add to stable set
896 *
897 * @return status of operation
898 */
900};
901
902/*
903 @class Gtid_Executed_Message
904
905 Class to convey the serialized contents of the previously executed GTIDs
906 */
908 public:
910 // This type should not be used anywhere.
912
913 // Length of the payload item: variable
915
916 // Length of the payload item: 8 bytes
918
919 // No valid type codes can appear after this one.
920 PIT_MAX = 3
921 };
922
923 /**
924 Gtid_Executed_Message constructor
925 */
928
929 /**
930 Appends Gtid executed information in a raw format
931
932 * @param[in] gtid_data encoded GTID data
933 * @param[in] len GTID data length
934 */
935 void append_gtid_executed(uchar *gtid_data, size_t len);
936
937 /**
938 Return the time at which the message contained in the buffer was sent.
939 @see Metrics_handler::get_current_time()
940
941 @param[in] buffer the buffer to decode from.
942 @param[in] length the buffer length
943
944 @return the time on which the message was sent.
945 */
946 static uint64_t get_sent_timestamp(const unsigned char *buffer,
947 size_t length);
948
949 protected:
950 /*
951 Implementation of the template methods of Gcs_plugin_message
952 */
953 void encode_payload(std::vector<unsigned char> *buffer) const override;
954 void decode_payload(const unsigned char *buffer,
955 const unsigned char *) override;
956
957 private:
958 std::vector<uchar> data;
959};
960
961#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:200
mysql_mutex_t broadcast_dispatcher_lock
Definition: certifier.h:199
Certifier_broadcast_thread()
Certifier_broadcast_thread constructor.
Definition: certifier.cc:54
THD * broadcast_thd
Definition: certifier.h:195
int initialize()
Initialize broadcast thread.
Definition: certifier.cc:80
int terminate()
Terminate broadcast thread.
Definition: certifier.cc:110
mysql_mutex_t broadcast_run_lock
Definition: certifier.h:197
static const int BROADCAST_GTID_EXECUTED_PERIOD
Period (in seconds) between stable transactions set broadcast.
Definition: certifier.h:188
int broadcast_gtid_executed()
Broadcast local GTID_EXECUTED to group.
Definition: certifier.cc:214
size_t broadcast_counter
Definition: certifier.h:202
int broadcast_gtid_executed_period
Definition: certifier.h:203
bool aborted
Thread control.
Definition: certifier.h:194
void dispatcher()
Broadcast thread worker method.
Definition: certifier.cc:141
my_thread_handle broadcast_pthd
Definition: certifier.h:196
virtual ~Certifier_broadcast_thread()
Definition: certifier.cc:73
thread_state broadcast_thd_state
Definition: certifier.h:201
mysql_cond_t broadcast_run_cond
Definition: certifier.h:198
Definition: certifier.h:215
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:240
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:856
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:486
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:1107
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:1021
Tsid_map * certification_info_tsid_map
Definition: certifier.h:713
Certification_info certification_info
Certification database.
Definition: certifier.h:712
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:2009
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:1740
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:810
bool is_conflict_detection_enable() override
Check if conflict detection is enable.
Definition: certifier.cc:2184
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:1611
bool initialize_server_gtid_set_after_distributed_recovery() override
Initializes the gtid_executed set.
Definition: certifier.cc:1827
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:1367
int64 parallel_applier_sequence_number
Definition: certifier.h:719
void clear_certification_info()
Empties certification info.
Definition: certifier.cc:497
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:497
Tsid_map * group_gtid_tsid_map
Definition: certifier.h:785
Gtid_set * stable_gtid_set
Definition: certifier.h:733
int initialize(ulonglong gtid_assignment_block_size)
Initialize certifier.
Definition: certifier.cc:532
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:1045
void clear_members()
Method to clear the members.
Definition: certifier.cc:526
Gtid_set * group_gtid_extracted
A Gtid_set which contains the gtid extracted from the certification info map of the donor.
Definition: certifier.h:798
std::atomic< bool > initialized
Is certifier initialized.
Definition: certifier.h:491
void disable_conflict_detection() override
Disables conflict detection.
Definition: certifier.cc:2168
Synchronized_queue< Data_packet * > * incoming
Definition: certifier.h:734
std::pair< Gtid, mysql::utils::Return_status > generate_view_change_group_gtid()
Generate group GTID for a view change log event.
Definition: certifier.cc:1983
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:246
void update_certified_transaction_count(bool result, bool local_transaction)
Definition: certifier.cc:2095
void clear_incoming()
Clear incoming queue.
Definition: certifier.cc:516
Certifier()
Definition: certifier.cc:264
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:698
enum_update_status
Definition: certifier.h:883
@ STABLE_SET_UPDATED
Definition: certifier.h:885
@ STABLE_SET_ALREADY_CONTAINED
Definition: certifier.h:887
@ STABLE_SET_ERROR
Definition: certifier.h:889
bool is_first_remote_transaction_certified
Definition: certifier.h:861
int64 parallel_applier_last_sequence_number
Definition: certifier.h:718
std::vector< std::string > members
Definition: certifier.h:736
~Certifier() override
Definition: certifier.cc:316
rpl_sidno views_sidno_group_representation
The sidno used for view log events as seen by the group sid map.
Definition: certifier.h:502
void get_last_conflict_free_transaction(std::string *value) override
Get method to retrieve the last conflict free transaction.
Definition: certifier.cc:2140
rpl_sidno views_sidno_server_representation
The sidno used for view log events as seen by the server sid map.
Definition: certifier.h:506
bool get_certification_info_recovery_metadata(Recovery_metadata_message *recovery_metadata_message) override
Retrieves the current certification info.
Definition: certifier.cc:1890
ulonglong get_certification_info_size() override
Get method to retrieve the certification db size.
Definition: certifier.cc:2136
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:570
void get_certification_info(std::map< std::string, std::string > *cert_info) override
Retrieves the current certification info.
Definition: certifier.cc:1577
bool certifying_already_applied_transactions
Definition: certifier.h:780
Checkable_rwlock * stable_gtid_set_lock
Stable set and garbage collector variables.
Definition: certifier.h:731
bool same_member_message_discarded
Definition: certifier.h:723
ulonglong positive_cert
Definition: certifier.h:715
ulonglong get_negative_certified() override
Get method to retrieve the number of negatively certified transactions.
Definition: certifier.cc:2134
enum enum_update_status update_stable_set(const Gtid_set &set)
Update stable set with set if not already contained.
Definition: certifier.cc:1350
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:1845
ulonglong negative_cert
Definition: certifier.h:716
protobuf_replication_group_recovery_metadata::CertificationInformationMap ProtoCertificationInformationMap
Definition: certifier.h:249
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:1185
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:1444
mysql_mutex_t LOCK_certification_info
Definition: certifier.h:726
ulonglong get_positive_certified() override
Get the number of postively certified transactions by the certifier.
Definition: certifier.cc:2132
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:341
gr::Gtid_generator gtid_generator
Object responsible for generation of the GTIDs for transactions with gtid_next equal to AUTOMATIC (ta...
Definition: certifier.h:802
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:1009
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:477
void gtid_intervals_computation()
Compute GTID intervals.
Definition: certifier.cc:1031
int64 parallel_applier_last_committed_global
Definition: certifier.h:717
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:1138
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:785
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:675
void handle_view_change() override
Handle view changes on certifier.
Definition: certifier.cc:1564
Gtid_set * get_certified_write_set_snapshot_version(const char *item)
Find the snapshot_version corresponding to an item.
Definition: certifier.cc:1089
bool is_initialized()
Definition: certifier.h:645
void enable_conflict_detection() override
Enables conflict detection.
Definition: certifier.cc:2156
bool certifier_garbage_collection_block
Definition: certifier.h:722
Gtid_set * group_gtid_executed
Definition: certifier.h:791
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:628
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:258
Gtid last_conflict_free_transaction
Last conflict free transaction identification.
Definition: certifier.h:707
Tsid_map * stable_tsid_map
Definition: certifier.h:732
mysql_mutex_t LOCK_members
Definition: certifier.h:812
int terminate()
Terminate certifier.
Definition: certifier.cc:561
Certifier_broadcast_thread * broadcast_thread
Broadcast thread.
Definition: certifier.h:817
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:907
enum_payload_item_type
Definition: certifier.h:909
@ PIT_SENT_TIMESTAMP
Definition: certifier.h:917
@ PIT_MAX
Definition: certifier.h:920
@ PIT_GTID_EXECUTED
Definition: certifier.h:914
@ PIT_UNKNOWN
Definition: certifier.h:911
Gtid_Executed_Message()
Gtid_Executed_Message constructor.
Definition: certifier.cc:2200
std::vector< uchar > data
Definition: certifier.h:958
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:2233
~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:2205
void encode_payload(std::vector< unsigned char > *buffer) const override
Encodes the contents of this instance payload into the buffer.
Definition: certifier.cc:2209
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:2220
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
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