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