MySQL 9.1.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 @param[in] increment_parallel_applier_sequence_number
509 If false (during certification garbage collection)
510 parallel_applier_last_committed_global is set to
511 parallel_applier_last_sequence_number and
512 parallel_applier_last_sequence_number is not updated
513
514 Note: parallel_applier_last_committed_global should be updated
515 on the following situations:
516 1) Transaction without write set is certified, since it
517 represents the lowest last_committed for all future
518 transactions;
519 2) After certification info garbage collection, since we
520 do not know what write sets were purged, which may cause
521 transactions last committed to be incorrectly computed.
522 */
524 bool update_parallel_applier_last_committed_global,
525 bool increment_parallel_applier_sequence_number);
526
527 /**
528 Internal method to add the given gtid gno in the group_gtid_executed set.
529 This will be used in the skip gtid implementation.
530
531 @note this will update the last know local transaction GTID.
532
533 @param[in] sidno rpl_sidno part of the executing gtid of the ongoing
534 transaction.
535
536 @param[in] gno rpl_gno part of the executing gtid of the ongoing
537 transaction.
538 */
540
541 /// @brief Returns group_executed_gtid_set or group_extracted_gtid_set while
542 /// certifying already applied transactions from the donor
543 /// @returns Pointer to the 'correct' group_gtid_set
544 const Gtid_set *get_group_gtid_set() const;
545
546 /// @brief Returns group_executed_gtid_set or group_extracted_gtid_set while
547 /// certifying already applied transactions from the donor
548 /// @returns Pointer to the 'correct' group_gtid_set
550
551 /// @brief This function determines three sidnos for a specific TSID
552 /// based on information obtained from the Gtid_log_event.
553 /// @param gle Gtid_log_event from which tsid will be extracted
554 /// @param is_gtid_specified True in case GTID is specified
555 /// @param snapshot_gtid_set Snapshot GTIDs
556 /// @param group_gtid_set Current GTID set
557 /// @return A tuple of:
558 /// - group_sidno Sidno relative to the group sid map
559 /// - gtid_snapshot_sidno Sidno relative to the snapshot sid map
560 /// - gtid_global_sidno Sidno relative to the global sid map
561 /// - return status
562 /// @details
563 /// We need to ensure that group sidno does exist on snapshot
564 /// version due to the following scenario:
565 /// 1) Member joins the group.
566 /// 2) Goes through recovery procedure, view change is queued to
567 /// apply, member is marked ONLINE. This requires
568 /// --group_replication_recovery_complete_at=TRANSACTIONS_CERTIFIED
569 /// to happen.
570 /// 3) Despite the view change log event is still being applied,
571 /// since the member is already ONLINE it can execute
572 /// transactions. The first transaction from this member will
573 /// not include any group GTID, since no group transaction is
574 /// yet applied.
575 /// 4) As a result of this sequence snapshot_version will not
576 /// contain any group GTID and the below instruction
577 /// snapshot_version->_add_gtid(group_sidno, result);
578 /// would fail because of that
579 std::tuple<rpl_sidno, rpl_sidno, rpl_sidno, mysql::utils::Return_status>
580 extract_sidno(Gtid_log_event &gle, bool is_gtid_specified,
581 Gtid_set &snapshot_gtid_set, Gtid_set &group_gtid_set);
582
583 /// @brief Internal helper method for ending certification, determination
584 /// of final GTID values after certification according to certification result
585 /// @param[in] gtid_server_sidno SIDNO for transaction GTID as represented in
586 /// the server (global sid map)
587 /// @param[in] gtid_group_sidno SIDNO for transaction GTID as represented in
588 /// the group
589 /// @param[in] generated_gno GNO generated for the transaction
590 /// @param[in] is_gtid_specified True if GTID was specified
591 /// @param[in] local_transaction True in case this transaction originates
592 /// from the this server
593 /// @param[in] certification_result Determined certification result
595 const rpl_sidno &gtid_server_sidno, const rpl_sidno &gtid_group_sidno,
596 const rpl_gno &generated_gno, bool is_gtid_specified,
597 bool local_transaction,
598 const gr::Certification_result &certification_result);
599
600 /// @brief Adds the transaction's write set to certification info.
601 /// @param[out] transaction_last_committed The transaction's logical
602 /// timestamps used for MTS
603 /// @param[in,out] snapshot_version The incoming transaction snapshot
604 /// version.
605 /// @param[in, out] write_set The incoming transaction write set.
606 /// @param[in] local_transaction True in case this transaction originates
607 /// from the this server
609 int64 &transaction_last_committed, Gtid_set *snapshot_version,
610 std::list<const char *> *write_set, bool local_transaction);
611
612 /// @brief Updates parallel applier indexes in GLE
613 /// @param gle Gle currently processed
614 /// @param has_write_set True in case transaction write set is not empty
615 /// @param has_write_set_large_size True in case number of write sets in
616 /// transactions is greater than
617 /// group_replication_preemptive_garbage_collection_rows_threshold
618 /// @param transaction_last_committed The transaction's logical timestamps
619 /// used for MTS
621 Gtid_log_event &gle, bool has_write_set, bool has_write_set_large_size,
622 int64 transaction_last_committed);
623
624 bool inline is_initialized() { return initialized; }
625
626 /**
627 This shall serialize the certification info stored in protobuf map format,
628 and then compress provided serialized string. The compressed payload is
629 stored into multiple buffer containers of the output list.
630
631 @param[in] cert_info the certification info stored in protobuf map.
632 @param[out] uncompresssed_buffer the buffer for uncompressed data.
633 @param[out] compressor_list the certification info in compressed form
634 splitted into multiple container of list.
635 @param[in] compression_type the type of compression used
636
637 @return the operation status
638 @retval false OK
639 @retval true Error
640 */
642 unsigned char **uncompresssed_buffer,
643 std::vector<GR_compress *> &compressor_list,
644 GR_compress::enum_compression_type compression_type);
645
646 /**
647 Sets the certification info according to the given value.
648 This shall uncompress and then convert uncompressed string into the protobuf
649 map format storing certification info. This certification info is added to
650 certifier's certification info.
651
652 @note if concurrent access is introduce to these variables,
653 locking is needed in this method
654
655 @param[in] compression_type the compression type
656 @param[in] buffer the compressed certification info retrieved from
657 recovery procedure.
658 @param[in] buffer_length the size of the compressed retrieved
659 certification info.
660 @param[in] uncompressed_buffer_length the size of the uncompressed
661 certification info before it was
662 compressed.
663
664 @return the operation status
665 @retval false OK
666 @retval true Error
667 */
669 GR_compress::enum_compression_type compression_type,
670 const unsigned char *buffer, unsigned long long buffer_length,
671 unsigned long long uncompressed_buffer_length);
672
673 /**
674 Empties certification info.
675 */
677
678 /**
679 Method to clear the members.
680 */
681 void clear_members();
682
683 /**
684 Last conflict free transaction identification.
685 */
687
688 /**
689 Certification database.
690 */
693
699
700#if !defined(NDEBUG)
703#endif
704
706
707 /**
708 Stable set and garbage collector variables.
709 */
714
715 std::vector<std::string> members;
716
717 /*
718 Flag to indicate that certifier is handling already applied
719 transactions during distributed recovery procedure.
720
721 On donor we may have local transactions certified after
722 View_change_log_event (VCLE) logged into binary log before VCLE.
723 That is, these local transactions will be appear on recovery
724 and also on GCS messages. One can see on example scenario below:
725
726 GCS order | donor binary log order | joiner apply order
727 -----------+------------------------+--------------------
728 T1 | T1 | T1
729 T2 | T2 | T2
730 V1 | T3 | T3 (recovery)
731 T3 | V1 | V1
732 | | T3 (GCS)
733 -----------+------------------------+--------------------
734
735 T3 is delivered to donor by both recovery and GCS, so joiner needs
736 to ensure that T3 has the same global identifier on both cases, so
737 that it is correctly skipped on the second time it is applied.
738
739 We ensure that T3 (and other transactions on that situation) have
740 the same global identifiers on joiner by:
741 1) When the VCLE is applied, we set on joiner certification info
742 the same exact certification that was on donor, including the
743 set of certified transactions before the joiner joined:
744 group_gtid_extracted.
745 2) We compare group_gtid_extracted and group_gtid_executed:
746 If group_gtid_extracted is a non equal subset of
747 group_gtid_executed, it means that we are on the above
748 scenario, that is, when applying the last transaction from
749 the distributed recovery process we have more transactions
750 than the ones certified before the view on which joiner joined.
751 So until group_gtid_extracted is a non equal subset of
752 group_gtid_executed certifier will generate transactions ids
753 following group_gtid_extracted so that we have the same exact
754 ids that donor has.
755 3) When joiner group_gtid_extracted and group_gtid_executed are
756 equal, joiner switches to its regular ids generation mode,
757 generating ids from group_gtid_executed.
758 */
760
761 /*
762 Sid map to store the GTIDs that are executed in the group.
763 */
765
766 /*
767 A Gtid_set containing the already executed for the group.
768 This is used to support skip_gtid.
769 */
771
772 /**
773 A Gtid_set which contains the gtid extracted from the certification info
774 map of the donor. It is the set of transactions that is executed at the
775 time of View_change_log_event at donor.
776 */
778
779 /// Object responsible for generation of the GTIDs for transactions with
780 /// gtid_next equal to AUTOMATIC (tagged/untagged)
782
783 /**
784 Conflict detection is performed when:
785 1) group is on multi-master mode;
786 2) group is on single-primary mode and primary is applying
787 relay logs with transactions from a previous primary.
788 */
790
792
793 /**
794 Broadcast thread.
795 */
797
798 /**
799 Adds an item from transaction writeset to the certification DB.
800 @param[in] item item in the writeset to be added to the
801 Certification DB.
802 @param[in] snapshot_version Snapshot version of the incoming transaction
803 which modified the above mentioned item.
804 @param[out] item_previous_sequence_number
805 The previous parallel applier sequence number
806 for this item.
807
808 @retval False successfully added to the map.
809 True otherwise.
810 */
811 bool add_item(const char *item, Gtid_set_ref *snapshot_version,
812 int64 *item_previous_sequence_number);
813
814 /**
815 Find the snapshot_version corresponding to an item. Return if
816 it exists, other wise return NULL;
817
818 @param[in] item item for the snapshot version.
819 @retval Gtid_set pointer if exists in the map.
820 Otherwise 0;
821 */
823
824 /**
825 Clear incoming queue.
826 */
827 void clear_incoming();
828
829 /*
830 Update method to store the count of the positively and negatively
831 certified transaction on a particular group member.
832 */
833 void update_certified_transaction_count(bool result, bool local_transaction);
834
835 /*
836 The first remote transaction certified does need to reset
837 replication_group_applier channel previous transaction
838 sequence_number.
839 */
841
842 /**
843 Removes the intersection of the received transactions stable
844 sets from certification database.
845
846 @param intersection_gtid_set intersection gtid set
847 @param preemptive is a preemptive run
848 */
849 void garbage_collect_internal(Gtid_set *intersection_gtid_set,
850 bool preemptive = false);
851
852 /**
853 Computes intersection between all sets received, so that we
854 have the already applied transactions on all servers.
855
856 @return the operation status
857 @retval false it did not run garbage_collect
858 @retval true it did run garbage_collect
859 */
861
863 // stable set successfully updated
865 // stable set already contains set
867 // not able to update due error
869 };
870
871 /**
872 * Update stable set with set if not already contained.
873 *
874 * @param set Gtid to add to stable set
875 *
876 * @return status of operation
877 */
879};
880
881/*
882 @class Gtid_Executed_Message
883
884 Class to convey the serialized contents of the previously executed GTIDs
885 */
887 public:
889 // This type should not be used anywhere.
891
892 // Length of the payload item: variable
894
895 // Length of the payload item: 8 bytes
897
898 // No valid type codes can appear after this one.
899 PIT_MAX = 3
900 };
901
902 /**
903 Gtid_Executed_Message constructor
904 */
907
908 /**
909 Appends Gtid executed information in a raw format
910
911 * @param[in] gtid_data encoded GTID data
912 * @param[in] len GTID data length
913 */
914 void append_gtid_executed(uchar *gtid_data, size_t len);
915
916 /**
917 Return the time at which the message contained in the buffer was sent.
918 @see Metrics_handler::get_current_time()
919
920 @param[in] buffer the buffer to decode from.
921 @param[in] length the buffer length
922
923 @return the time on which the message was sent.
924 */
925 static uint64_t get_sent_timestamp(const unsigned char *buffer,
926 size_t length);
927
928 protected:
929 /*
930 Implementation of the template methods of Gcs_plugin_message
931 */
932 void encode_payload(std::vector<unsigned char> *buffer) const override;
933 void decode_payload(const unsigned char *buffer,
934 const unsigned char *) override;
935
936 private:
937 std::vector<uchar> data;
938};
939
940#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:80
int terminate()
Terminate broadcast thread.
Definition: certifier.cc:110
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:214
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:141
my_thread_handle broadcast_pthd
Definition: certifier.h:175
virtual ~Certifier_broadcast_thread()
Definition: certifier.cc:73
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: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: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: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:692
Certification_info certification_info
Certification database.
Definition: certifier.h:691
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:1988
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:1719
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:789
bool is_conflict_detection_enable() override
Check if conflict detection is enable.
Definition: certifier.cc:2163
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:1590
bool initialize_server_gtid_set_after_distributed_recovery() override
Initializes the gtid_executed set.
Definition: certifier.cc:1806
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:1346
int64 parallel_applier_sequence_number
Definition: certifier.h:698
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:476
Tsid_map * group_gtid_tsid_map
Definition: certifier.h:764
Gtid_set * stable_gtid_set
Definition: certifier.h:712
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:777
std::atomic< bool > initialized
Is certifier initialized.
Definition: certifier.h:470
void disable_conflict_detection() override
Disables conflict detection.
Definition: certifier.cc:2147
Synchronized_queue< Data_packet * > * incoming
Definition: certifier.h:713
std::pair< Gtid, mysql::utils::Return_status > generate_view_change_group_gtid()
Generate group GTID for a view change log event.
Definition: certifier.cc:1962
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:2074
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:862
@ STABLE_SET_UPDATED
Definition: certifier.h:864
@ STABLE_SET_ALREADY_CONTAINED
Definition: certifier.h:866
@ STABLE_SET_ERROR
Definition: certifier.h:868
bool is_first_remote_transaction_certified
Definition: certifier.h:840
int64 parallel_applier_last_sequence_number
Definition: certifier.h:697
std::vector< std::string > members
Definition: certifier.h:715
~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:481
void get_last_conflict_free_transaction(std::string *value) override
Get method to retrieve the last conflict free transaction.
Definition: certifier.cc:2119
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:1869
ulonglong get_certification_info_size() override
Get method to retrieve the certification db size.
Definition: certifier.cc:2115
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:1556
bool certifying_already_applied_transactions
Definition: certifier.h:759
Checkable_rwlock * stable_gtid_set_lock
Stable set and garbage collector variables.
Definition: certifier.h:710
bool same_member_message_discarded
Definition: certifier.h:702
ulonglong positive_cert
Definition: certifier.h:694
ulonglong get_negative_certified() override
Get method to retrieve the number of negatively certified transactions.
Definition: certifier.cc:2113
enum enum_update_status update_stable_set(const Gtid_set &set)
Update stable set with set if not already contained.
Definition: certifier.cc:1329
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:1824
ulonglong negative_cert
Definition: certifier.h:695
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: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:1423
mysql_mutex_t LOCK_certification_info
Definition: certifier.h:705
ulonglong get_positive_certified() override
Get the number of postively certified transactions by the certifier.
Definition: certifier.cc:2111
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:781
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:696
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:1543
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:624
void enable_conflict_detection() override
Enables conflict detection.
Definition: certifier.cc:2135
bool certifier_garbage_collection_block
Definition: certifier.h:701
Gtid_set * group_gtid_executed
Definition: certifier.h:770
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:237
Gtid last_conflict_free_transaction
Last conflict free transaction identification.
Definition: certifier.h:686
Tsid_map * stable_tsid_map
Definition: certifier.h:711
mysql_mutex_t LOCK_members
Definition: certifier.h:791
int terminate()
Terminate certifier.
Definition: certifier.cc:561
Certifier_broadcast_thread * broadcast_thread
Broadcast thread.
Definition: certifier.h:796
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:886
enum_payload_item_type
Definition: certifier.h:888
@ PIT_SENT_TIMESTAMP
Definition: certifier.h:896
@ PIT_MAX
Definition: certifier.h:899
@ PIT_GTID_EXECUTED
Definition: certifier.h:893
@ PIT_UNKNOWN
Definition: certifier.h:890
Gtid_Executed_Message()
Gtid_Executed_Message constructor.
Definition: certifier.cc:2179
std::vector< uchar > data
Definition: certifier.h:937
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:2212
~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:2184
void encode_payload(std::vector< unsigned char > *buffer) const override
Encodes the contents of this instance payload into the buffer.
Definition: certifier.cc:2188
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:2199
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: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: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
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: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