MySQL 9.6.0
Source Code Documentation
gcs_logging_system.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 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#ifndef GCS_LOG_SYSTEM_INCLUDED
24#define GCS_LOG_SYSTEM_INCLUDED
25
26#include <errno.h>
27#include <stddef.h>
28#include <string.h>
29#include <cstdarg>
30#include <cstdio>
31#include <cstdlib>
32#include <iostream>
33#include <memory>
34#include <sstream>
35#include <string>
36#include <thread>
37#include <vector>
38
42
43#ifndef XCOM_STANDALONE
44#include "my_sys.h"
45#endif /* XCOM_STANDALONE */
46
47/**
48 Maximum size of a message stored in a single entry in the circular buffer.
49*/
50#define GCS_MAX_LOG_BUFFER 512
51
52/**
53 Default number of circular buffer entries.
54*/
55#define DEFAULT_ASYNC_BUFFERS 4096
56
57/*
58 Definitions to compose a message to be written into a sink.
59*/
60#define GCS_PREFIX "[GCS] "
61#define GCS_PREFIX_SIZE 6
62#define GCS_DEBUG_PREFIX "[MYSQL_GCS_DEBUG] "
63#define GCS_DEBUG_PREFIX_SIZE 18
64#ifdef _WIN32
65#define GCS_NEWLINE "\r\n"
66#define GCS_NEWLINE_SIZE 2
67#else
68#define GCS_NEWLINE "\n"
69#define GCS_NEWLINE_SIZE 1
70#endif
71
72/**
73 Entry or element in the circular buffer maintained by the Gcs_async_buffer
74 responsible for storing a message that will eventually be asynchronously
75 written to a sink.
76*/
78 public:
79 explicit Gcs_log_event() = default;
80
81 /**
82 Set whether the message is ready to be consumed or not.
83 */
84
85 inline void set_event(bool ready) { m_ready_flag.store(ready); }
86
87 /**
88 Write the current message into a sink.
89
90 @param sink Where the message should be written to.
91
92 @retval Currently, it always false.
93 */
94
95 inline bool flush_event(Sink_interface &sink) {
96 /*
97 The producer is filling in the message and eventually it will be available
98 so the consumer should wait for a while until the flag is true. Note that
99 the number of entries in the buffer is increased before filling the
100 buffer. This happens because the copy itself is done outside the critical
101 section.
102
103 After consuming the entry, the flag is set back to false again.
104 */
105 while (!m_ready_flag.load()) {
107 }
109 m_ready_flag.store(false);
110
111 return false;
112 }
113
114 /**
115 Get a reference to a buffer entry that holds a message that will be
116 eventually written to a sink.
117 */
118
119 inline char *get_buffer() { return m_message_buffer; }
120
121 /**
122 Get the content size provided it was already filled in. Otherwise,
123 an unknown value is returned.
124 */
125
126 inline size_t get_buffer_size() const { return m_message_size; }
127
128 /**
129 Get the maximum buffer size.
130 */
131
132 inline size_t get_max_buffer_size() const { return GCS_MAX_LOG_BUFFER - 3; }
133
134 /**
135 Set the message's size.
136 */
137
138 inline void set_buffer_size(size_t message_size) {
139 m_message_size = message_size;
140 }
141
142 private:
143 /**
144 Buffer to hold a message that will eventually be written to a sink.
145 */
147
148 /*
149 Size of the message stored in the buffer entry.
150 */
151 size_t m_message_size{0};
152
153 /**
154 Flag used to indicate whether the message can be consumed or not.
155 */
156 std::atomic<bool> m_ready_flag{false};
157
158 /*
159 Disabling copy constructor and assignment operator.
160 */
163};
164
165/**
166 Circular buffer that can be used to asynchronously feed a sink. In this,
167 messages are temporarily stored in-memory and asynchronously written to the
168 sink. Using this in-memory intermediate buffer is possible to minimize
169 performance drawbacks associated with the direct access to the sink which is
170 usually the terminal, a file or a remote process.
171
172 By default, the circular buffer has DEFAULT_ASYNC_BUFFERS entries and this
173 value can be changed by providing different contructor's parameters. Note
174 that, however, this is not currently exposed to the end-user. If there is no
175 free slot available, the caller thread will be temporarily blocked until it
176 can copy its message into a free slot. Only one thread will read the entries
177 in the circular buffer and write them to a sink.
178
179 Concurrent access to the buffer is controlled by using a mutex and atomic
180 variables. If you are tempted to change this, please, measure the performance
181 first before changing anything. We have done so and the bulk of the time is
182 spent in formatting the messages and for that reason a simple circular buffer
183 implementation is enough.
184
185 Another alternative would be to format the message within the consumer but
186 this would require to always pass information by value. In order to give
187 users flexibility, we have decided not to do this. Besides, XCOM almost
188 always formats its messages within the context of the caller thread. For
189 those reasons, we kept the current behavior but we might revisit this in
190 the future.
191*/
193 private:
194 /**
195 Slots where messages will be copied to before a consumer thread writes
196 them to a sink.
197 */
198 std::vector<Gcs_log_event> m_buffer;
199
200 /**
201 Number of available slots in the buffer.
202 */
204
205 /**
206 Next entry in the buffer where producers will write their messages to.
207 */
209
210 /**
211 Next entry in the buffer that will be read by the consumer.
212 */
214
215 /**
216 Number of entries written by producers and not yet consumed.
217 */
219
220 /**
221 Whether the asynchronous circular buffer has been stopped or not.
222 */
224
225 /**
226 Whether the asynchronous circular buffer has been started or not.
227 */
229
230 /**
231 Sink where the consumer will write messages to.
232 */
234
235 /**
236 Consumer thread that is responsible for reading the entries in
237 the circular buffer.
238 */
240
241 /**
242 Conditional variable that is used by the producer to notify the consumer
243 that it should wake up.
244 */
246
247 /**
248 Conditional variable that is used by the consumer to notify the producer
249 that there are free slots.
250 */
252
253 /**
254 Mutex variable that is used to synchronize access to the circular buffer
255 in particular the m_number_entries, m_write_index and m_terminated shared
256 variables.
257 */
259
260 public:
261 explicit Gcs_async_buffer(Sink_interface *sink,
264
265 /**
266 Asynchronous circular buffer initialization method.
267
268 @retval GCS_OK in case everything goes well. Any other value of
269 gcs_error in case of error.
270 */
271
273
274 /**
275 Asynchronous circular buffer finalization method.
276
277 @retval GCS_OK in case everything goes well. Any other value of
278 gcs_error in case of error.
279 */
280
282
283 /**
284 The purpose of this method is to return information on the associated
285 sink such as its location. In this particular case, it will return the
286 string "asynchronous" along with the information returned by then sink
287 in use.
288
289 Calling this method would return "asynchronous::output" if the sink
290 in use was the standard output.
291 */
292
293 std::string get_information() const;
294
295 /**
296 Consumer thread invokes this method to process log events until it is
297 terminated.
298 */
299
300 void consume_events();
301
302 /**
303 Producer threads invoke this method to log events (i.e. messages).
304
305 This method is only provided for the sake of completeness and is
306 currently not used because the message would have to be copied into the
307 circular buffer and usually it is necessary to compose the message first
308 thus incurring an extra copy.
309
310 Currently, a producer calls directly the get_entry() and notify_entry()
311 methods directly.
312 */
313
314 void produce_events(const char *message, size_t message_size);
315
316 /**
317 Producer threads invoke this method to log events (i.e. messages).
318
319 This method is only provided for the sake of completeness and is
320 currently not used because the message would have to be copied into the
321 circular buffer and usually it is necessary to compose the message first
322 thus incurring an extra copy.
323
324 Currently, a producer calls directly the get_entry() and notify_entry()
325 methods directly
326 */
327
328 void produce_events(const std::string &message);
329
330 /**
331 Get a reference to an in-memory buffer where a message content will be
332 written to.
333 */
334
336
337 /**
338 Notify that an in-memory buffer was filled in and is ready to be
339 consumed.
340 */
341 void notify_entry(Gcs_log_event &buffer_entry);
342
343 /*
344 Get a reference to the associated sink.
345 */
346
347 Sink_interface *get_sink() const;
348
349 private:
350 /**
351 Get the correct index to an entry according to the buffer size.
352 */
353
354 uint64_t get_index(int64_t index) const { return index % m_buffer_size; }
355
356 /**
357 Get an index entry to an in-memory buffer where a message content will
358 be written to.
359 */
360
361 int64_t get_write_index();
362
363 /**
364 Make the consumer sleep while there is no entry to be consumed.
365 */
366
367 void sleep_consumer() const {
369 }
370
371 /**
372 Wake up the consumer thread so that it can write whatever was added to
373 the asynchronous buffer to a sink.
374 */
375
377
378 /*
379 Disabling copy constructor and assignment operator.
380 */
383};
384
385/* purecov: begin deadcode */
386/**
387 Standard output sink.
388*/
390 public:
391 explicit Gcs_output_sink();
392 ~Gcs_output_sink() override = default;
393
394 /**
395 Output sink initialization method.
396
397 @retval GCS_OK in case everything goes well. Any other value of
398 gcs_error in case of error
399 */
400
401 enum_gcs_error initialize() override;
402
403 /**
404 Output sink finalization method.
405
406 @retval GCS_OK in case everything goes well. Any other value of
407 gcs_error in case of error.
408 */
409
410 enum_gcs_error finalize() override;
411
412 /**
413 Print the received message to the standard output stream.
414
415 @param message rendered stream of the logging message
416 */
417
418 void log_event(const std::string &message) override;
419
420 /**
421 Print the received message to the standard output stream.
422
423 @param message rendered stream of the logging message
424 @param message_size logging message size
425 */
426
427 void log_event(const char *message, size_t message_size) override;
428
429 /**
430 Return information on the sink such as its location.
431 */
432
433 const std::string get_information() const override;
434
435 private:
436 /*
437 Whether the sink was initialized or not.
438 */
440
441 /*
442 Disabling copy constructor and assignment operator.
443 */
446};
447
448/**
449 Default logger which is internally used by GCS and XCOM if nothing else
450 is injected by Group Replication.
451*/
453 public:
454 explicit Gcs_default_logger(Gcs_async_buffer *sink);
455 ~Gcs_default_logger() override = default;
456
457 /**
458 Default logger initialization method.
459
460 @returns GCS_OK
461 */
462
463 enum_gcs_error initialize() override;
464
465 /**
466 Default logger finalization method.
467
468 @returns GCS_OK
469 */
470
471 enum_gcs_error finalize() override;
472
473 /**
474 Asynchronously forwards the received message to a sink.
475
476 This method prepares the message and writes it to an in-memory buffer.
477 If there is no free entry in the in-memory buffer, the call blocks until
478 an entry becomes available.
479
480 Note that the write to the sink is done asynchronously.
481
482 This method shouldn't be invoked directly in the code, as it is wrapped
483 by the MYSQL_GCS_LOG_[LEVEL] macros which deal with the rendering of the
484 logging message into a final string that is then handed alongside with
485 the level to this method.
486
487 @param level logging level of the message
488 @param message rendered string of the logging message
489 */
490
491 void log_event(const gcs_log_level_t level,
492 const std::string &message) override;
493
494 private:
495 /**
496 Reference to an asynchronous buffer that encapsulates a sink.
497 */
499
500 /*
501 Disabling copy constructor and assignment operator.
502 */
505};
506/* purecov: end */
507
508/**
509 Default debugger which is used only by GCS and XCOM.
510*/
512 public:
513 explicit Gcs_default_debugger(
514 Gcs_async_buffer *sink,
515 std::shared_ptr<Clock_timestamp_interface> clock_timestamp_provider);
516 virtual ~Gcs_default_debugger() = default;
517
518 /**
519 Default debugger initialization method.
520
521 @returns GCS_OK
522 */
523
525
526 /**
527 Default debugger finalization method.
528
529 @returns GCS_OK
530 */
531
533
534 /**
535 Asynchronously forwards the received message to a sink.
536
537 This method prepares the message and writes it to an in-memory buffer.
538 If there is no free entry in the in-memory buffer, the call blocks until
539 an entry becomes available.
540
541 Note that the write to the sink is done asynchronously.
542
543 This method shouldn't be invoked directly in the code, as it is wrapped
544 by the MYSQL_GCS_LOG_[LEVEL] macros which deal with the rendering of the
545 logging message into a final string that is then handed alongside with
546 the level to this method.
547
548 @param [in] format Message format using a c-style string
549 @param [in] args Arguments to fill in the format string
550 */
551
552 inline void log_event(const char *format, va_list args)
553 MY_ATTRIBUTE((format(printf, 2, 0))) {
554 Gcs_log_event &event = m_sink->get_entry();
555 char *buffer = event.get_buffer();
556 size_t size = append_timestamp(buffer, event.get_max_buffer_size());
558 size += vsnprintf(buffer + size, event.get_max_buffer_size() - size, format,
559 args);
560 if (unlikely(size > event.get_max_buffer_size())) {
561 fprintf(stderr, "The following message was truncated: %s\n", buffer);
562 size = event.get_max_buffer_size();
563 }
565 event.set_buffer_size(size);
567 }
568
569 /**
570 Default debugger simply forwards the received message to a sink.
571
572 @param message rendered string of the logging message
573 */
574
575 void log_event(const std::string &message);
576
577 /**
578 Get a reference to the in-memory buffer where the message content will
579 be copied to if there is any.
580 */
581
582 inline Gcs_log_event &get_entry() { return m_sink->get_entry(); }
583
584 /**
585 Notify that the in-memory buffer were filled in and is ready to be
586 consumed.
587 */
588
591 }
592
593 /**
594 Asynchronously forwards the received message to a sink.
595
596 This method prepares the message and writes it to an in-memory buffer.
597 If there is no free entry in the in-memory buffer, the call blocks until
598 an entry becomes available.
599
600 Note that the write to the sink is done asynchronously.
601
602 This method shouldn't be invoked directly in the code, as it is wrapped
603 by the MYSQL_GCS_LOG_[LEVEL] macros which deal with the rendering of the
604 logging message into a final string that is then handed alongside with
605 the level to this method.
606
607 @param [in] options Debug options that are associated with the message
608 @param [in] message Message to be written to the in-memory buffer
609 */
610
611 inline void log_event(int64_t options, const char *message) {
612 log_event(options, "%s", message);
613 }
614
615 /**
616 Asynchronously forwards the received message to a sink.
617
618 This method prepares the message and writes it to an in-memory buffer.
619 If there is no free entry in the in-memory buffer, the call blocks until
620 an entry becomes available.
621
622 Note that the write to the sink is done asynchronously.
623
624 This method shouldn't be invoked directly in the code, as it is wrapped
625 by the MYSQL_GCS_LOG_[LEVEL] macros which deal with the rendering of the
626 logging message into a final string that is then handed alongside with
627 the level to this method.
628
629 @param [in] options Debug options that are associated with the message
630 @param [in] args Arguments This includes the c-style string and arguments
631 to fill it in
632 */
633 template <typename... Args>
634 inline void log_event(const int64_t options, Args... args) {
636 Gcs_log_event &event = get_entry();
637 char *buffer = event.get_buffer();
638 size_t size = append_timestamp(buffer, event.get_max_buffer_size());
640 size +=
641 snprintf(buffer + size, event.get_max_buffer_size() - size, args...);
642 if (unlikely(size > event.get_max_buffer_size())) {
643 fprintf(stderr, "The following message was truncated: %s\n", buffer);
644 size = event.get_max_buffer_size();
645 }
647 event.set_buffer_size(size);
649 }
650 }
651
652 private:
653 /**
654 Reference to an asynchronous buffer that encapsulates a sink.
655 */
657
658 /**
659 @brief The GCS TRACE file timestamp provider.
660
661 The application using this library may choose to use a specific format for
662 the timestamps, so that the logs created by GCS can be correlated with
663 other application logs.
664
665 This must be injected before the debugger is used, typically before it is
666 initialized.
667
668 The application owns this object, so it is the application responsibility
669 to delete the this object and thus free resources.
670 */
671 std::shared_ptr<Clock_timestamp_interface> m_clock_timestamp_provider;
672
673 /**
674 Add extra information as a message prefix.
675
676 We assume that there is room to accommodate it. Before changing this
677 method, make sure the maximum buffer size will always have room to
678 accommodate any new information.
679
680 @return Return the size of appended information
681 */
682 inline size_t append_prefix(char *buffer) {
683 strcpy(buffer, GCS_DEBUG_PREFIX);
685
687 }
688
689 /**
690 Append information into a message such as end of line.
691
692 We assume that there is room to accommodate it. Before changing this
693 method, make sure the maximum buffer size will always have room to
694 accommodate any new information.
695
696 @return Return the size of appended information
697 */
698 inline size_t append_sufix(char *buffer, size_t size) {
699 strcpy(buffer + size, GCS_NEWLINE);
700 buffer[size + GCS_NEWLINE_SIZE] = '\0';
701 return GCS_NEWLINE_SIZE;
702 }
703
704 /**
705 Appends a timestamp, in UTC, to the buffer. It also adds an extra white
706 space at the end.
707 @param buffer the buffer to store the timestamp to.
708 @param size the size of the buffer.
709 @return the number of bytes appended.
710 */
711 inline size_t append_timestamp(char *buffer, size_t size) {
712 m_clock_timestamp_provider->get_timestamp_as_c_string(buffer, &size);
713 if (size == 0) return 0;
714
715 buffer[size] = ' ';
716 return size + 1;
717 }
718
719 /*
720 Disabling copy constructor and assignment operator.
721 */
724};
725
727 private:
728 /*
729 It stores a reference to a debugger interface object.
730 */
731
733
734 public:
735 /**
736 Set the debugger object and initialize it by invoking its initialization
737 method.
738
739 This allows any resources needed by the debugging system to be initialized,
740 and ensures its usage throughout the lifecycle of the current application.
741
742 @param[in] debugger debugging system
743 @retval GCS_OK in case everything goes well. Any other value of
744 gcs_error in case of error.
745 */
746
748 m_debugger = debugger;
749 return m_debugger->initialize();
750 }
751
752 /**
753 Get a reference to the debugger object if there is any.
754 @return The current debugging system.
755 */
756
758
759 /**
760 Free any resource used in the debugging system.
761
762 @retval GCS_OK in case everything goes well. Any other value of
763 gcs_error in case of error.
764 */
765
768
769 if (m_debugger != nullptr) {
770 ret = m_debugger->finalize();
771 m_debugger = nullptr;
772 }
773
774 return ret;
775 }
776};
777
778/* purecov: end */
779
780#ifndef XCOM_STANDALONE
781/* File debugger */
783 public:
784 Gcs_file_sink(const std::string &file_name, const std::string &dir_name);
785 ~Gcs_file_sink() override = default;
786
787 /**
788 File sink initialization method.
789
790 @retval GCS_OK in case everything goes well. Any other value of
791 gcs_error in case of error.
792 */
793
794 enum_gcs_error initialize() override;
795
796 /**
797 File sink finalization method.
798
799 @retval GCS_OK in case everything goes well. Any other value of
800 gcs_error in case of error.
801 */
802
803 enum_gcs_error finalize() override;
804
805 /**
806 Print the received message to a log file.
807 @param message rendered stream of the logging message
808 */
809
810 void log_event(const std::string &message) override;
811
812 /**
813 Print the received message to a log file.
814
815 @param message rendered stream of the logging message
816 @param message_size logging message size
817 */
818
819 void log_event(const char *message, size_t message_size) override;
820
821 /**
822 The purpose of this method is to return information on the sink such
823 as its location.
824 */
825
826 const std::string get_information() const override;
827
828 /**
829 Return the full path of the file that shall be created. If the path is
830 too long GCS_NOK is returned.
831
832 @param[out] file_name_buffer Buffer that will contain the resulting path
833 @retval GCS_OK in case everything goes well. Any other value of
834 gcs_error in case of error
835 */
836
837 enum_gcs_error get_file_name(char *file_name_buffer) const;
838
839 private:
840 /*
841 File descriptor.
842 */
844
845 /*
846 Reference to a file name.
847 */
848 std::string m_file_name;
849
850 /*
851 Reference to a directory that will be used as relative path.
852 */
853 std::string m_dir_name;
854
855 /*
856 Whether the sink was initialized or not.
857 */
859
860 /*
861 Disabling copy constructor and assignment operator.
862 */
865};
866#endif /* XCOM_STANDALONE */
867
869 public:
871 ~Gcs_clock_timestamp_provider() override = default;
872 // non-copyable
874 delete;
876 const Gcs_clock_timestamp_provider &other) = delete;
877 // non-movable
880 Gcs_clock_timestamp_provider &&other) = delete;
881
882 enum_gcs_error initialize() override { return GCS_OK; }
883 enum_gcs_error finalize() override { return GCS_OK; }
884
885 void get_timestamp_as_c_string(char *buffer, size_t *size) override;
886 void get_timestamp_as_string(std::string &str) override;
887};
888
889#define MYSQL_GCS_LOG(l, x) \
890 do { \
891 if (Gcs_log_manager::get_logger() != NULL) { \
892 std::stringstream log; \
893 log << GCS_PREFIX << x; \
894 Gcs_log_manager::get_logger()->log_event(l, log.str()); \
895 } \
896 } while (0);
897
898#define MYSQL_GCS_LOG_INFO(x) MYSQL_GCS_LOG(GCS_INFO, x)
899#define MYSQL_GCS_LOG_WARN(x) MYSQL_GCS_LOG(GCS_WARN, x)
900#define MYSQL_GCS_LOG_ERROR(x) MYSQL_GCS_LOG(GCS_ERROR, x)
901#define MYSQL_GCS_LOG_FATAL(x) MYSQL_GCS_LOG(GCS_FATAL, x)
902
903#define MYSQL_GCS_DEBUG_EXECUTE(x) \
904 MYSQL_GCS_DEBUG_EXECUTE_WITH_OPTION(GCS_DEBUG_BASIC | GCS_DEBUG_TRACE, x)
905
906#define MYSQL_GCS_TRACE_EXECUTE(x) \
907 MYSQL_GCS_DEBUG_EXECUTE_WITH_OPTION(GCS_DEBUG_TRACE, x)
908
909#define MYSQL_GCS_LOG_DEBUG(...) \
910 MYSQL_GCS_LOG_DEBUG_WITH_OPTION(GCS_DEBUG_BASIC | GCS_DEBUG_TRACE, \
911 __VA_ARGS__)
912
913#define MYSQL_GCS_LOG_TRACE(...) \
914 MYSQL_GCS_LOG_DEBUG_WITH_OPTION(GCS_DEBUG_TRACE, __VA_ARGS__)
915
916#define MYSQL_GCS_DEBUG_EXECUTE_WITH_OPTION(option, x) \
917 do { \
918 if (Gcs_debug_manager::test_debug_options(option)) { \
919 x; \
920 } \
921 } while (0);
922
923#define MYSQL_GCS_LOG_DEBUG_WITH_OPTION(options, ...) \
924 do { \
925 Gcs_default_debugger *debugger = Gcs_debug_manager::get_debugger(); \
926 debugger->log_event(options, __VA_ARGS__); \
927 } while (0);
928#endif /* GCS_LOG_SYSTEM_INCLUDED */
This is the interface for the timestamp provider for entries that end up in the Debugger log.
Definition: gcs_logging.h:73
Circular buffer that can be used to asynchronously feed a sink.
Definition: gcs_logging_system.h:192
My_xp_thread * m_consumer
Consumer thread that is responsible for reading the entries in the circular buffer.
Definition: gcs_logging_system.h:239
bool m_terminated
Whether the asynchronous circular buffer has been stopped or not.
Definition: gcs_logging_system.h:223
Sink_interface * m_sink
Sink where the consumer will write messages to.
Definition: gcs_logging_system.h:233
int64_t m_read_index
Next entry in the buffer that will be read by the consumer.
Definition: gcs_logging_system.h:213
enum_gcs_error finalize()
Asynchronous circular buffer finalization method.
Definition: gcs_logging_system.cc:122
bool m_initialized
Whether the asynchronous circular buffer has been started or not.
Definition: gcs_logging_system.h:228
int64_t get_write_index()
Get an index entry to an in-memory buffer where a message content will be written to.
Definition: gcs_logging_system.cc:158
Sink_interface * get_sink() const
Definition: gcs_logging_system.cc:71
int m_buffer_size
Number of available slots in the buffer.
Definition: gcs_logging_system.h:203
void sleep_consumer() const
Make the consumer sleep while there is no entry to be consumed.
Definition: gcs_logging_system.h:367
void produce_events(const char *message, size_t message_size)
Producer threads invoke this method to log events (i.e.
Definition: gcs_logging_system.cc:196
int64_t m_write_index
Next entry in the buffer where producers will write their messages to.
Definition: gcs_logging_system.h:208
enum_gcs_error initialize()
Asynchronous circular buffer initialization method.
Definition: gcs_logging_system.cc:73
void consume_events()
Consumer thread invokes this method to process log events until it is terminated.
Definition: gcs_logging_system.cc:210
void notify_entry(Gcs_log_event &buffer_entry)
Notify that an in-memory buffer was filled in and is ready to be consumed.
Definition: gcs_logging_system.cc:186
uint64_t get_index(int64_t index) const
Get the correct index to an entry according to the buffer size.
Definition: gcs_logging_system.h:354
Gcs_async_buffer & operator=(const Gcs_async_buffer &l)
My_xp_cond * m_free_buffer_cond
Conditional variable that is used by the consumer to notify the producer that there are free slots.
Definition: gcs_logging_system.h:251
std::string get_information() const
The purpose of this method is to return information on the associated sink such as its location.
Definition: gcs_logging_system.cc:272
Gcs_async_buffer(Sink_interface *sink, const int buffer_size=DEFAULT_ASYNC_BUFFERS)
Definition: gcs_logging_system.cc:49
My_xp_cond * m_wait_for_events_cond
Conditional variable that is used by the producer to notify the consumer that it should wake up.
Definition: gcs_logging_system.h:245
std::vector< Gcs_log_event > m_buffer
Slots where messages will be copied to before a consumer thread writes them to a sink.
Definition: gcs_logging_system.h:198
Gcs_log_event & get_entry()
Get a reference to an in-memory buffer where a message content will be written to.
Definition: gcs_logging_system.cc:146
int64_t m_number_entries
Number of entries written by producers and not yet consumed.
Definition: gcs_logging_system.h:218
My_xp_mutex * m_free_buffer_mutex
Mutex variable that is used to synchronize access to the circular buffer in particular the m_number_e...
Definition: gcs_logging_system.h:258
Gcs_async_buffer(Gcs_async_buffer &l)
~Gcs_async_buffer()
Definition: gcs_logging_system.cc:63
void wake_up_consumer() const
Wake up the consumer thread so that it can write whatever was added to the asynchronous buffer to a s...
Definition: gcs_logging_system.h:376
Definition: gcs_logging_system.h:868
Gcs_clock_timestamp_provider(const Gcs_clock_timestamp_provider &other)=delete
void get_timestamp_as_string(std::string &str) override
Get the timestamp as std::string.
Definition: gcs_logging_system.cc:481
Gcs_clock_timestamp_provider(Gcs_clock_timestamp_provider &&other)=delete
~Gcs_clock_timestamp_provider() override=default
void get_timestamp_as_c_string(char *buffer, size_t *size) override
Get the timestamp as c string object.
Definition: gcs_logging_system.cc:472
Gcs_clock_timestamp_provider & operator=(const Gcs_clock_timestamp_provider &other)=delete
enum_gcs_error finalize() override
The purpose of this method is to free any resources used by the objects that implement this interface...
Definition: gcs_logging_system.h:883
enum_gcs_error initialize() override
The purpose of this method is to initialize resources used by the objects that implement this interfa...
Definition: gcs_logging_system.h:882
Gcs_clock_timestamp_provider & operator=(Gcs_clock_timestamp_provider &&other)=delete
Definition: gcs_logging_system.h:726
static enum_gcs_error finalize()
Free any resource used in the debugging system.
Definition: gcs_logging_system.h:766
static Gcs_default_debugger * m_debugger
Reference to the default debugger which is used internally by GCS and XCOM.
Definition: gcs_logging_system.h:732
static Gcs_default_debugger * get_debugger()
Get a reference to the debugger object if there is any.
Definition: gcs_logging_system.h:757
static enum_gcs_error initialize(Gcs_default_debugger *debugger)
Set the debugger object and initialize it by invoking its initialization method.
Definition: gcs_logging_system.h:747
This class sets up and configures the debugging infrastructure, storing the debugger to be used by th...
Definition: gcs_logging.h:303
static bool test_debug_options(const int64_t debug_options)
Verify whether any of the debug options are defined.
Definition: gcs_logging.h:355
Default debugger which is used only by GCS and XCOM.
Definition: gcs_logging_system.h:511
Gcs_async_buffer * m_sink
Reference to an asynchronous buffer that encapsulates a sink.
Definition: gcs_logging_system.h:656
Gcs_default_debugger & operator=(const Gcs_default_debugger &d)
void log_event(int64_t options, const char *message)
Asynchronously forwards the received message to a sink.
Definition: gcs_logging_system.h:611
enum_gcs_error finalize()
Default debugger finalization method.
Definition: gcs_logging_system.cc:343
size_t append_prefix(char *buffer)
Add extra information as a message prefix.
Definition: gcs_logging_system.h:682
enum_gcs_error initialize()
Default debugger initialization method.
Definition: gcs_logging_system.cc:339
size_t append_timestamp(char *buffer, size_t size)
Appends a timestamp, in UTC, to the buffer.
Definition: gcs_logging_system.h:711
size_t append_sufix(char *buffer, size_t size)
Append information into a message such as end of line.
Definition: gcs_logging_system.h:698
void log_event(const std::string &message)
Default debugger simply forwards the received message to a sink.
void log_event(const int64_t options, Args... args)
Asynchronously forwards the received message to a sink.
Definition: gcs_logging_system.h:634
Gcs_default_debugger(Gcs_default_debugger &d)
Gcs_log_event & get_entry()
Get a reference to the in-memory buffer where the message content will be copied to if there is any.
Definition: gcs_logging_system.h:582
void notify_entry(Gcs_log_event &entry)
Notify that the in-memory buffer were filled in and is ready to be consumed.
Definition: gcs_logging_system.h:589
Gcs_default_debugger(Gcs_async_buffer *sink, std::shared_ptr< Clock_timestamp_interface > clock_timestamp_provider)
Definition: gcs_logging_system.cc:334
virtual ~Gcs_default_debugger()=default
void log_event(const char *format, va_list args)
Asynchronously forwards the received message to a sink.
Definition: gcs_logging_system.h:552
std::shared_ptr< Clock_timestamp_interface > m_clock_timestamp_provider
The GCS TRACE file timestamp provider.
Definition: gcs_logging_system.h:671
Default logger which is internally used by GCS and XCOM if nothing else is injected by Group Replicat...
Definition: gcs_logging_system.h:452
void log_event(const gcs_log_level_t level, const std::string &message) override
Asynchronously forwards the received message to a sink.
Definition: gcs_logging_system.cc:327
enum_gcs_error initialize() override
Default logger initialization method.
Definition: gcs_logging_system.cc:323
Gcs_default_logger & operator=(const Gcs_default_logger &l)
~Gcs_default_logger() override=default
Gcs_async_buffer * m_sink
Reference to an asynchronous buffer that encapsulates a sink.
Definition: gcs_logging_system.h:498
Gcs_default_logger(Gcs_async_buffer *sink)
Definition: gcs_logging_system.cc:321
Gcs_default_logger(Gcs_default_logger &l)
enum_gcs_error finalize() override
Default logger finalization method.
Definition: gcs_logging_system.cc:325
Definition: gcs_logging_system.h:782
Gcs_file_sink & operator=(const Gcs_file_sink &d)
Gcs_file_sink(Gcs_file_sink &d)
void log_event(const std::string &message) override
Print the received message to a log file.
Definition: gcs_logging_system.cc:440
enum_gcs_error initialize() override
File sink initialization method.
Definition: gcs_logging_system.cc:378
Gcs_file_sink(const std::string &file_name, const std::string &dir_name)
Definition: gcs_logging_system.cc:351
enum_gcs_error get_file_name(char *file_name_buffer) const
Return the full path of the file that shall be created.
Definition: gcs_logging_system.cc:358
enum_gcs_error finalize() override
File sink finalization method.
Definition: gcs_logging_system.cc:429
std::string m_dir_name
Definition: gcs_logging_system.h:853
std::string m_file_name
Definition: gcs_logging_system.h:848
const std::string get_information() const override
The purpose of this method is to return information on the sink such as its location.
Definition: gcs_logging_system.cc:461
~Gcs_file_sink() override=default
File m_fd
Definition: gcs_logging_system.h:843
bool m_initialized
Definition: gcs_logging_system.h:858
Entry or element in the circular buffer maintained by the Gcs_async_buffer responsible for storing a ...
Definition: gcs_logging_system.h:77
Gcs_log_event()=default
size_t get_buffer_size() const
Get the content size provided it was already filled in.
Definition: gcs_logging_system.h:126
char * get_buffer()
Get a reference to a buffer entry that holds a message that will be eventually written to a sink.
Definition: gcs_logging_system.h:119
Gcs_log_event(const Gcs_log_event &other)
bool flush_event(Sink_interface &sink)
Write the current message into a sink.
Definition: gcs_logging_system.h:95
char m_message_buffer[GCS_MAX_LOG_BUFFER]
Buffer to hold a message that will eventually be written to a sink.
Definition: gcs_logging_system.h:146
std::atomic< bool > m_ready_flag
Flag used to indicate whether the message can be consumed or not.
Definition: gcs_logging_system.h:156
size_t m_message_size
Definition: gcs_logging_system.h:151
Gcs_log_event & operator=(const Gcs_log_event &e)
void set_event(bool ready)
Set whether the message is ready to be consumed or not.
Definition: gcs_logging_system.h:85
size_t get_max_buffer_size() const
Get the maximum buffer size.
Definition: gcs_logging_system.h:132
void set_buffer_size(size_t message_size)
Set the message's size.
Definition: gcs_logging_system.h:138
Standard output sink.
Definition: gcs_logging_system.h:389
const std::string get_information() const override
Return information on the sink such as its location.
Definition: gcs_logging_system.cc:317
enum_gcs_error finalize() override
Output sink finalization method.
Definition: gcs_logging_system.cc:306
enum_gcs_error initialize() override
Output sink initialization method.
Definition: gcs_logging_system.cc:284
void log_event(const std::string &message) override
Print the received message to the standard output stream.
Definition: gcs_logging_system.cc:308
~Gcs_output_sink() override=default
bool m_initialized
Definition: gcs_logging_system.h:439
Gcs_output_sink()
Definition: gcs_logging_system.cc:282
Gcs_output_sink(Gcs_output_sink &s)
Gcs_output_sink & operator=(const Gcs_output_sink &s)
Logger interface that must be used to define a logger object.
Definition: gcs_logging.h:160
Abstract class used to wrap condition for various implementations.
Definition: my_xp_cond.h:47
virtual int wait(mysql_mutex_t *mutex)=0
Wait for cond to be signaled to unlock mutex.
virtual int signal()=0
Signal cond.
Abstract class used to wrap mutex for various implementations.
Definition: my_xp_mutex.h:47
virtual mysql_mutex_t * get_native_mutex()=0
To get native mutex reference.
static void yield()
Causes the calling thread to relinquish the CPU, and to be moved to the end of the queue and another ...
Definition: my_xp_thread.cc:111
Abstract class used to wrap mutex for various platforms.
Definition: my_xp_thread.h:61
Common sink that may be shared by the logging and debugging systems.
Definition: gcs_logging.h:109
virtual void log_event(const std::string &message)=0
The purpose of this method is to effectively log the information.
gcs_log_level_t
Definition: gcs_logging.h:143
#define GCS_PREFIX_SIZE
Definition: gcs_logging_system.h:61
#define GCS_DEBUG_PREFIX
Definition: gcs_logging_system.h:62
#define GCS_MAX_LOG_BUFFER
Maximum size of a message stored in a single entry in the circular buffer.
Definition: gcs_logging_system.h:50
#define GCS_DEBUG_PREFIX_SIZE
Definition: gcs_logging_system.h:63
#define GCS_NEWLINE
Definition: gcs_logging_system.h:68
#define GCS_PREFIX
Definition: gcs_logging_system.h:60
#define DEFAULT_ASYNC_BUFFERS
Default number of circular buffer entries.
Definition: gcs_logging_system.h:55
#define GCS_NEWLINE_SIZE
Definition: gcs_logging_system.h:69
enum_gcs_error
This enumeration describes errors which can occur during group communication operations.
Definition: gcs_types.h:41
@ GCS_OK
Definition: gcs_types.h:43
@ GCS_NOK
Definition: gcs_types.h:45
constexpr bool unlikely(bool expr)
Definition: my_compiler.h:58
int File
Definition: my_io_bits.h:51
Common header for many mysys elements.
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1077
std::string format(const routing_guidelines::Session_info &session_info, bool extended_session_info)
Definition: dest_metadata_cache.cc:170
bool index(const std::string &value, const String &search_for, uint32_t *idx)
Definition: contains.h:76
std::string file_name(Log_file_id file_id)
Provides name of the log file with the given file id, e.g.
Definition: log0pre_8_0_30.cc:94
size_t size(const char *const c)
Definition: base64.h:46
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:418
size_t buffer_size(const ConstBufferSequence &buffers) noexcept
Definition: buffer.h:313
Definition: options.cc:57
required string event
Definition: replication_group_member_actions.proto:32
Definition: completion_hash.h:35