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