23#ifndef GCS_LOG_SYSTEM_INCLUDED
24#define GCS_LOG_SYSTEM_INCLUDED
43#ifndef XCOM_STANDALONE
50#define GCS_MAX_LOG_BUFFER 512
55#define DEFAULT_ASYNC_BUFFERS 4096
60#define GCS_PREFIX "[GCS] "
61#define GCS_PREFIX_SIZE 6
62#define GCS_DEBUG_PREFIX "[MYSQL_GCS_DEBUG] "
63#define GCS_DEBUG_PREFIX_SIZE 18
65#define GCS_NEWLINE "\r\n"
66#define GCS_NEWLINE_SIZE 2
68#define GCS_NEWLINE "\n"
69#define GCS_NEWLINE_SIZE 1
418 void log_event(
const std::string &message)
override;
427 void log_event(
const char *message,
size_t message_size)
override;
492 const std::string &message)
override;
515 std::shared_ptr<Clock_timestamp_interface> clock_timestamp_provider);
553 MY_ATTRIBUTE((
format(printf, 2, 0))) {
555 char *
buffer =
event.get_buffer();
561 fprintf(stderr,
"The following message was truncated: %s\n",
buffer);
562 size =
event.get_max_buffer_size();
565 event.set_buffer_size(
size);
633 template <
typename... Args>
637 char *
buffer =
event.get_buffer();
643 fprintf(stderr,
"The following message was truncated: %s\n",
buffer);
644 size =
event.get_max_buffer_size();
647 event.set_buffer_size(
size);
713 if (
size == 0)
return 0;
780#ifndef XCOM_STANDALONE
810 void log_event(
const std::string &message)
override;
819 void log_event(
const char *message,
size_t message_size)
override;
889#define MYSQL_GCS_LOG(l, x) \
891 if (Gcs_log_manager::get_logger() != NULL) { \
892 std::stringstream log; \
893 log << GCS_PREFIX << x; \
894 Gcs_log_manager::get_logger()->log_event(l, log.str()); \
898#define MYSQL_GCS_LOG_INFO(x) MYSQL_GCS_LOG(GCS_INFO, x)
899#define MYSQL_GCS_LOG_WARN(x) MYSQL_GCS_LOG(GCS_WARN, x)
900#define MYSQL_GCS_LOG_ERROR(x) MYSQL_GCS_LOG(GCS_ERROR, x)
901#define MYSQL_GCS_LOG_FATAL(x) MYSQL_GCS_LOG(GCS_FATAL, x)
903#define MYSQL_GCS_DEBUG_EXECUTE(x) \
904 MYSQL_GCS_DEBUG_EXECUTE_WITH_OPTION(GCS_DEBUG_BASIC | GCS_DEBUG_TRACE, x)
906#define MYSQL_GCS_TRACE_EXECUTE(x) \
907 MYSQL_GCS_DEBUG_EXECUTE_WITH_OPTION(GCS_DEBUG_TRACE, x)
909#define MYSQL_GCS_LOG_DEBUG(...) \
910 MYSQL_GCS_LOG_DEBUG_WITH_OPTION(GCS_DEBUG_BASIC | GCS_DEBUG_TRACE, \
913#define MYSQL_GCS_LOG_TRACE(...) \
914 MYSQL_GCS_LOG_DEBUG_WITH_OPTION(GCS_DEBUG_TRACE, __VA_ARGS__)
916#define MYSQL_GCS_DEBUG_EXECUTE_WITH_OPTION(option, x) \
918 if (Gcs_debug_manager::test_debug_options(option)) { \
923#define MYSQL_GCS_LOG_DEBUG_WITH_OPTION(options, ...) \
925 Gcs_default_debugger *debugger = Gcs_debug_manager::get_debugger(); \
926 debugger->log_event(options, __VA_ARGS__); \
This is the interface for the timestamp provider for entries that end up in the Debugger log.
Definition: gcs_logging.h:73
Circular buffer that can be used to asynchronously feed a sink.
Definition: gcs_logging_system.h:192
My_xp_thread * m_consumer
Consumer thread that is responsible for reading the entries in the circular buffer.
Definition: gcs_logging_system.h:239
bool m_terminated
Whether the asynchronous circular buffer has been stopped or not.
Definition: gcs_logging_system.h:223
Sink_interface * m_sink
Sink where the consumer will write messages to.
Definition: gcs_logging_system.h:233
int64_t m_read_index
Next entry in the buffer that will be read by the consumer.
Definition: gcs_logging_system.h:213
enum_gcs_error finalize()
Asynchronous circular buffer finalization method.
Definition: gcs_logging_system.cc:122
bool m_initialized
Whether the asynchronous circular buffer has been started or not.
Definition: gcs_logging_system.h:228
int64_t get_write_index()
Get an index entry to an in-memory buffer where a message content will be written to.
Definition: gcs_logging_system.cc:158
Sink_interface * get_sink() const
Definition: gcs_logging_system.cc:71
int m_buffer_size
Number of available slots in the buffer.
Definition: gcs_logging_system.h:203
void sleep_consumer() const
Make the consumer sleep while there is no entry to be consumed.
Definition: gcs_logging_system.h:367
void produce_events(const char *message, size_t message_size)
Producer threads invoke this method to log events (i.e.
Definition: gcs_logging_system.cc:196
int64_t m_write_index
Next entry in the buffer where producers will write their messages to.
Definition: gcs_logging_system.h:208
enum_gcs_error initialize()
Asynchronous circular buffer initialization method.
Definition: gcs_logging_system.cc:73
void consume_events()
Consumer thread invokes this method to process log events until it is terminated.
Definition: gcs_logging_system.cc:210
void notify_entry(Gcs_log_event &buffer_entry)
Notify that an in-memory buffer was filled in and is ready to be consumed.
Definition: gcs_logging_system.cc:186
uint64_t get_index(int64_t index) const
Get the correct index to an entry according to the buffer size.
Definition: gcs_logging_system.h:354
Gcs_async_buffer & operator=(const Gcs_async_buffer &l)
My_xp_cond * m_free_buffer_cond
Conditional variable that is used by the consumer to notify the producer that there are free slots.
Definition: gcs_logging_system.h:251
std::string get_information() const
The purpose of this method is to return information on the associated sink such as its location.
Definition: gcs_logging_system.cc:272
Gcs_async_buffer(Sink_interface *sink, const int buffer_size=DEFAULT_ASYNC_BUFFERS)
Definition: gcs_logging_system.cc:49
My_xp_cond * m_wait_for_events_cond
Conditional variable that is used by the producer to notify the consumer that it should wake up.
Definition: gcs_logging_system.h:245
std::vector< Gcs_log_event > m_buffer
Slots where messages will be copied to before a consumer thread writes them to a sink.
Definition: gcs_logging_system.h:198
Gcs_log_event & get_entry()
Get a reference to an in-memory buffer where a message content will be written to.
Definition: gcs_logging_system.cc:146
int64_t m_number_entries
Number of entries written by producers and not yet consumed.
Definition: gcs_logging_system.h:218
My_xp_mutex * m_free_buffer_mutex
Mutex variable that is used to synchronize access to the circular buffer in particular the m_number_e...
Definition: gcs_logging_system.h:258
Gcs_async_buffer(Gcs_async_buffer &l)
~Gcs_async_buffer()
Definition: gcs_logging_system.cc:63
void wake_up_consumer() const
Wake up the consumer thread so that it can write whatever was added to the asynchronous buffer to a s...
Definition: gcs_logging_system.h:376
Definition: gcs_logging_system.h:868
Gcs_clock_timestamp_provider(const Gcs_clock_timestamp_provider &other)=delete
void get_timestamp_as_string(std::string &str) override
Get the timestamp as std::string.
Definition: gcs_logging_system.cc:481
Gcs_clock_timestamp_provider(Gcs_clock_timestamp_provider &&other)=delete
~Gcs_clock_timestamp_provider() override=default
void get_timestamp_as_c_string(char *buffer, size_t *size) override
Get the timestamp as c string object.
Definition: gcs_logging_system.cc:472
Gcs_clock_timestamp_provider & operator=(const Gcs_clock_timestamp_provider &other)=delete
enum_gcs_error finalize() override
The purpose of this method is to free any resources used by the objects that implement this interface...
Definition: gcs_logging_system.h:883
Gcs_clock_timestamp_provider()=default
enum_gcs_error initialize() override
The purpose of this method is to initialize resources used by the objects that implement this interfa...
Definition: gcs_logging_system.h:882
Gcs_clock_timestamp_provider & operator=(Gcs_clock_timestamp_provider &&other)=delete
Definition: gcs_logging_system.h:726
static enum_gcs_error finalize()
Free any resource used in the debugging system.
Definition: gcs_logging_system.h:766
static Gcs_default_debugger * m_debugger
Reference to the default debugger which is used internally by GCS and XCOM.
Definition: gcs_logging_system.h:732
static Gcs_default_debugger * get_debugger()
Get a reference to the debugger object if there is any.
Definition: gcs_logging_system.h:757
static enum_gcs_error initialize(Gcs_default_debugger *debugger)
Set the debugger object and initialize it by invoking its initialization method.
Definition: gcs_logging_system.h:747
This class sets up and configures the debugging infrastructure, storing the debugger to be used by th...
Definition: gcs_logging.h:303
static bool test_debug_options(const int64_t debug_options)
Verify whether any of the debug options are defined.
Definition: gcs_logging.h:355
Default debugger which is used only by GCS and XCOM.
Definition: gcs_logging_system.h:511
Gcs_async_buffer * m_sink
Reference to an asynchronous buffer that encapsulates a sink.
Definition: gcs_logging_system.h:656
Gcs_default_debugger & operator=(const Gcs_default_debugger &d)
void log_event(int64_t options, const char *message)
Asynchronously forwards the received message to a sink.
Definition: gcs_logging_system.h:611
enum_gcs_error finalize()
Default debugger finalization method.
Definition: gcs_logging_system.cc:343
size_t append_prefix(char *buffer)
Add extra information as a message prefix.
Definition: gcs_logging_system.h:682
enum_gcs_error initialize()
Default debugger initialization method.
Definition: gcs_logging_system.cc:339
size_t append_timestamp(char *buffer, size_t size)
Appends a timestamp, in UTC, to the buffer.
Definition: gcs_logging_system.h:711
size_t append_sufix(char *buffer, size_t size)
Append information into a message such as end of line.
Definition: gcs_logging_system.h:698
void log_event(const std::string &message)
Default debugger simply forwards the received message to a sink.
void log_event(const int64_t options, Args... args)
Asynchronously forwards the received message to a sink.
Definition: gcs_logging_system.h:634
Gcs_default_debugger(Gcs_default_debugger &d)
Gcs_log_event & get_entry()
Get a reference to the in-memory buffer where the message content will be copied to if there is any.
Definition: gcs_logging_system.h:582
void notify_entry(Gcs_log_event &entry)
Notify that the in-memory buffer were filled in and is ready to be consumed.
Definition: gcs_logging_system.h:589
Gcs_default_debugger(Gcs_async_buffer *sink, std::shared_ptr< Clock_timestamp_interface > clock_timestamp_provider)
Definition: gcs_logging_system.cc:334
virtual ~Gcs_default_debugger()=default
void log_event(const char *format, va_list args)
Asynchronously forwards the received message to a sink.
Definition: gcs_logging_system.h:552
std::shared_ptr< Clock_timestamp_interface > m_clock_timestamp_provider
The GCS TRACE file timestamp provider.
Definition: gcs_logging_system.h:671
Default logger which is internally used by GCS and XCOM if nothing else is injected by Group Replicat...
Definition: gcs_logging_system.h:452
void log_event(const gcs_log_level_t level, const std::string &message) override
Asynchronously forwards the received message to a sink.
Definition: gcs_logging_system.cc:327
enum_gcs_error initialize() override
Default logger initialization method.
Definition: gcs_logging_system.cc:323
Gcs_default_logger & operator=(const Gcs_default_logger &l)
~Gcs_default_logger() override=default
Gcs_async_buffer * m_sink
Reference to an asynchronous buffer that encapsulates a sink.
Definition: gcs_logging_system.h:498
Gcs_default_logger(Gcs_async_buffer *sink)
Definition: gcs_logging_system.cc:321
Gcs_default_logger(Gcs_default_logger &l)
enum_gcs_error finalize() override
Default logger finalization method.
Definition: gcs_logging_system.cc:325
Definition: gcs_logging_system.h:782
Gcs_file_sink & operator=(const Gcs_file_sink &d)
Gcs_file_sink(Gcs_file_sink &d)
void log_event(const std::string &message) override
Print the received message to a log file.
Definition: gcs_logging_system.cc:440
enum_gcs_error initialize() override
File sink initialization method.
Definition: gcs_logging_system.cc:378
Gcs_file_sink(const std::string &file_name, const std::string &dir_name)
Definition: gcs_logging_system.cc:351
enum_gcs_error get_file_name(char *file_name_buffer) const
Return the full path of the file that shall be created.
Definition: gcs_logging_system.cc:358
enum_gcs_error finalize() override
File sink finalization method.
Definition: gcs_logging_system.cc:429
std::string m_dir_name
Definition: gcs_logging_system.h:853
std::string m_file_name
Definition: gcs_logging_system.h:848
const std::string get_information() const override
The purpose of this method is to return information on the sink such as its location.
Definition: gcs_logging_system.cc:461
~Gcs_file_sink() override=default
File m_fd
Definition: gcs_logging_system.h:843
bool m_initialized
Definition: gcs_logging_system.h:858
Entry or element in the circular buffer maintained by the Gcs_async_buffer responsible for storing a ...
Definition: gcs_logging_system.h:77
size_t get_buffer_size() const
Get the content size provided it was already filled in.
Definition: gcs_logging_system.h:126
char * get_buffer()
Get a reference to a buffer entry that holds a message that will be eventually written to a sink.
Definition: gcs_logging_system.h:119
Gcs_log_event(const Gcs_log_event &other)
bool flush_event(Sink_interface &sink)
Write the current message into a sink.
Definition: gcs_logging_system.h:95
char m_message_buffer[GCS_MAX_LOG_BUFFER]
Buffer to hold a message that will eventually be written to a sink.
Definition: gcs_logging_system.h:146
std::atomic< bool > m_ready_flag
Flag used to indicate whether the message can be consumed or not.
Definition: gcs_logging_system.h:156
size_t m_message_size
Definition: gcs_logging_system.h:151
Gcs_log_event & operator=(const Gcs_log_event &e)
void set_event(bool ready)
Set whether the message is ready to be consumed or not.
Definition: gcs_logging_system.h:85
size_t get_max_buffer_size() const
Get the maximum buffer size.
Definition: gcs_logging_system.h:132
void set_buffer_size(size_t message_size)
Set the message's size.
Definition: gcs_logging_system.h:138
Standard output sink.
Definition: gcs_logging_system.h:389
const std::string get_information() const override
Return information on the sink such as its location.
Definition: gcs_logging_system.cc:317
enum_gcs_error finalize() override
Output sink finalization method.
Definition: gcs_logging_system.cc:306
enum_gcs_error initialize() override
Output sink initialization method.
Definition: gcs_logging_system.cc:284
void log_event(const std::string &message) override
Print the received message to the standard output stream.
Definition: gcs_logging_system.cc:308
~Gcs_output_sink() override=default
bool m_initialized
Definition: gcs_logging_system.h:439
Gcs_output_sink()
Definition: gcs_logging_system.cc:282
Gcs_output_sink(Gcs_output_sink &s)
Gcs_output_sink & operator=(const Gcs_output_sink &s)
Logger interface that must be used to define a logger object.
Definition: gcs_logging.h:160
Abstract class used to wrap condition for various implementations.
Definition: my_xp_cond.h:47
virtual int wait(mysql_mutex_t *mutex)=0
Wait for cond to be signaled to unlock mutex.
virtual int signal()=0
Signal cond.
Abstract class used to wrap mutex for various implementations.
Definition: my_xp_mutex.h:47
virtual mysql_mutex_t * get_native_mutex()=0
To get native mutex reference.
static void yield()
Causes the calling thread to relinquish the CPU, and to be moved to the end of the queue and another ...
Definition: my_xp_thread.cc:111
Abstract class used to wrap mutex for various platforms.
Definition: my_xp_thread.h:61
Common sink that may be shared by the logging and debugging systems.
Definition: gcs_logging.h:109
virtual void log_event(const std::string &message)=0
The purpose of this method is to effectively log the information.
gcs_log_level_t
Definition: gcs_logging.h:143
#define GCS_PREFIX_SIZE
Definition: gcs_logging_system.h:61
#define GCS_DEBUG_PREFIX
Definition: gcs_logging_system.h:62
#define GCS_MAX_LOG_BUFFER
Maximum size of a message stored in a single entry in the circular buffer.
Definition: gcs_logging_system.h:50
#define GCS_DEBUG_PREFIX_SIZE
Definition: gcs_logging_system.h:63
#define GCS_NEWLINE
Definition: gcs_logging_system.h:68
#define GCS_PREFIX
Definition: gcs_logging_system.h:60
#define DEFAULT_ASYNC_BUFFERS
Default number of circular buffer entries.
Definition: gcs_logging_system.h:55
#define GCS_NEWLINE_SIZE
Definition: gcs_logging_system.h:69
enum_gcs_error
This enumeration describes errors which can occur during group communication operations.
Definition: gcs_types.h:41
@ GCS_OK
Definition: gcs_types.h:43
@ GCS_NOK
Definition: gcs_types.h:45
constexpr bool unlikely(bool expr)
Definition: my_compiler.h:58
int File
Definition: my_io_bits.h:51
Common header for many mysys elements.
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1077
bool index(const std::string &value, const String &search_for, uint32_t *idx)
Definition: contains.h:76
std::string file_name(Log_file_id file_id)
Provides name of the log file with the given file id, e.g.
Definition: log0pre_8_0_30.cc:94
size_t size(const char *const c)
Definition: base64.h:46
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:418
size_t buffer_size(const ConstBufferSequence &buffers) noexcept
Definition: buffer.h:313
Definition: options.cc:57
required string event
Definition: replication_group_member_actions.proto:32
Definition: completion_hash.h:35