23#ifndef GCS_LOG_SYSTEM_INCLUDED
24#define GCS_LOG_SYSTEM_INCLUDED
42#ifndef XCOM_STANDALONE
49#define GCS_MAX_LOG_BUFFER 512
54#define DEFAULT_ASYNC_BUFFERS 4096
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
64#define GCS_NEWLINE "\r\n"
65#define GCS_NEWLINE_SIZE 2
67#define GCS_NEWLINE "\n"
68#define GCS_NEWLINE_SIZE 1
417 void log_event(
const std::string &message)
override;
426 void log_event(
const char *message,
size_t message_size)
override;
491 const std::string &message)
override;
550 MY_ATTRIBUTE((format(printf, 2, 0))) {
552 char *
buffer =
event.get_buffer();
557 fprintf(stderr,
"The following message was truncated: %s\n",
buffer);
558 size =
event.get_max_buffer_size();
561 event.set_buffer_size(
size);
629 template <
typename... Args>
633 char *
buffer =
event.get_buffer();
638 fprintf(stderr,
"The following message was truncated: %s\n",
buffer);
639 size =
event.get_max_buffer_size();
642 event.set_buffer_size(
size);
746#ifndef XCOM_STANDALONE
776 void log_event(
const std::string &message)
override;
785 void log_event(
const char *message,
size_t message_size)
override;
834#define MYSQL_GCS_LOG(l, x) \
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()); \
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)
848#define MYSQL_GCS_DEBUG_EXECUTE(x) \
849 MYSQL_GCS_DEBUG_EXECUTE_WITH_OPTION(GCS_DEBUG_BASIC | GCS_DEBUG_TRACE, x)
851#define MYSQL_GCS_TRACE_EXECUTE(x) \
852 MYSQL_GCS_DEBUG_EXECUTE_WITH_OPTION(GCS_DEBUG_TRACE, x)
854#define MYSQL_GCS_LOG_DEBUG(...) \
855 MYSQL_GCS_LOG_DEBUG_WITH_OPTION(GCS_DEBUG_BASIC | GCS_DEBUG_TRACE, \
858#define MYSQL_GCS_LOG_TRACE(...) \
859 MYSQL_GCS_LOG_DEBUG_WITH_OPTION(GCS_DEBUG_TRACE, __VA_ARGS__)
861#define MYSQL_GCS_DEBUG_EXECUTE_WITH_OPTION(option, x) \
863 if (Gcs_debug_manager::test_debug_options(option)) { \
868#define MYSQL_GCS_LOG_DEBUG_WITH_OPTION(options, ...) \
870 Gcs_default_debugger *debugger = Gcs_debug_manager::get_debugger(); \
871 debugger->log_event(options, __VA_ARGS__); \
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
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