22#ifndef GCS_LOG_SYSTEM_INCLUDED
23#define GCS_LOG_SYSTEM_INCLUDED
41#ifndef XCOM_STANDALONE
48#define GCS_MAX_LOG_BUFFER 512
53#define DEFAULT_ASYNC_BUFFERS 4096
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
63#define GCS_NEWLINE "\r\n"
64#define GCS_NEWLINE_SIZE 2
66#define GCS_NEWLINE "\n"
67#define GCS_NEWLINE_SIZE 1
416 void log_event(
const std::string &message)
override;
425 void log_event(
const char *message,
size_t message_size)
override;
490 const std::string &message)
override;
549 MY_ATTRIBUTE((format(printf, 2, 0))) {
551 char *
buffer =
event.get_buffer();
553 size += vsnprintf(
buffer + size,
event.get_max_buffer_size() - size, format,
556 fprintf(stderr,
"The following message was truncated: %s\n",
buffer);
557 size =
event.get_max_buffer_size();
560 event.set_buffer_size(size);
628 template <
typename... Args>
632 char *
buffer =
event.get_buffer();
635 snprintf(
buffer + size,
event.get_max_buffer_size() - size, args...);
637 fprintf(stderr,
"The following message was truncated: %s\n",
buffer);
638 size =
event.get_max_buffer_size();
641 event.set_buffer_size(size);
745#ifndef XCOM_STANDALONE
775 void log_event(
const std::string &message)
override;
784 void log_event(
const char *message,
size_t message_size)
override;
833#define MYSQL_GCS_LOG(l, x) \
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()); \
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)
847#define MYSQL_GCS_DEBUG_EXECUTE(x) \
848 MYSQL_GCS_DEBUG_EXECUTE_WITH_OPTION(GCS_DEBUG_BASIC | GCS_DEBUG_TRACE, x)
850#define MYSQL_GCS_TRACE_EXECUTE(x) \
851 MYSQL_GCS_DEBUG_EXECUTE_WITH_OPTION(GCS_DEBUG_TRACE, x)
853#define MYSQL_GCS_LOG_DEBUG(...) \
854 MYSQL_GCS_LOG_DEBUG_WITH_OPTION(GCS_DEBUG_BASIC | GCS_DEBUG_TRACE, \
857#define MYSQL_GCS_LOG_TRACE(...) \
858 MYSQL_GCS_LOG_DEBUG_WITH_OPTION(GCS_DEBUG_TRACE, __VA_ARGS__)
860#define MYSQL_GCS_DEBUG_EXECUTE_WITH_OPTION(option, x) \
862 if (Gcs_debug_manager::test_debug_options(option)) { \
867#define MYSQL_GCS_LOG_DEBUG_WITH_OPTION(options, ...) \
869 Gcs_default_debugger *debugger = Gcs_debug_manager::get_debugger(); \
870 debugger->log_event(options, __VA_ARGS__); \
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
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:108
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:55
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:419
size_t buffer_size(const ConstBufferSequence &buffers) noexcept
Definition: buffer.h:314
Definition: options.cc:48
required string event
Definition: replication_group_member_actions.proto:31
Definition: completion_hash.h:34