MySQL 8.4.2
Source Code Documentation
log_sink_perfschema.h File Reference

This file contains. More...

Go to the source code of this file.

Classes

struct  _log_sink_pfs_event
 

Macros

#define LOG_SINK_PFS_ERROR_CODE_LENGTH   10
 
#define LOG_SINK_PFS_SUBSYS_LENGTH   7
 

Typedefs

typedef struct _log_sink_pfs_event log_sink_pfs_event
 

Functions

void log_sink_pfs_read_start ()
 Acquire a read-lock on the ring-buffer. More...
 
void log_sink_pfs_read_end ()
 Release read-lock on ring-buffer. More...
 
size_t log_sink_pfs_event_count ()
 Get number of events currently in ring-buffer. More...
 
log_sink_pfs_eventlog_sink_pfs_event_first ()
 Get oldest event still in ring-buffer. More...
 
log_sink_pfs_eventlog_sink_pfs_event_next (log_sink_pfs_event *e)
 Get event following the supplied one. More...
 
log_sink_pfs_eventlog_sink_pfs_event_valid (log_sink_pfs_event *e, ulonglong logged)
 Use timestamp to check whether a given event-pointer still points to a valid event in the ring-buffer. More...
 
int log_error_read_log_init ()
 Set up ring-buffer for error-log. More...
 
int log_error_read_log_exit ()
 Release error log ring-buffer. More...
 
log_service_error log_error_read_log (const char *log_name)
 Restore error log messages from previous shutdown. More...
 
log_service_error log_sink_pfs_event_add (log_sink_pfs_event *e, const char *blob_src)
 Add a log-event to the ring buffer. More...
 
int log_sink_perfschema (void *instance, log_line *ll)
 services: log sinks: logging to performance_schema ring-buffer More...
 

Variables

ulong log_sink_pfs_buffered_bytes
 bytes in use (now) More...
 
ulong log_sink_pfs_buffered_events
 events in buffer (now) More...
 
ulong log_sink_pfs_expired_events
 number of expired entries (ever) More...
 
ulong log_sink_pfs_longest_event
 longest event seen (ever) More...
 
ulonglong log_sink_pfs_latest_timestamp
 timestamp of most recent write More...
 

Detailed Description

This file contains.

a) The API for the reading of previously written error logs. (These functions will in turn use a parse-function defined in a log-sink. Whichever log-sink that has a parse-function is listed first in @global.log_error_services will be used; that service will decide what log-file to read (i.e. its name) and how to parse it. We initially support the reading of JSON- formatted error log files and of the traditional MySQL error log files.) This lets us restore error log information from previous runs when the server starts. These functions are called from mysqld.cc at start-up.

b) The log-sink that adds errors logged at run-time to the ring-buffer (to be called from

See also
log_line_submit() during normal operation, i.e. when loadable log-components are available, connections are accepted, and so on).

Macro Definition Documentation

◆ LOG_SINK_PFS_ERROR_CODE_LENGTH

#define LOG_SINK_PFS_ERROR_CODE_LENGTH   10

◆ LOG_SINK_PFS_SUBSYS_LENGTH

#define LOG_SINK_PFS_SUBSYS_LENGTH   7

Typedef Documentation

◆ log_sink_pfs_event

Function Documentation

◆ log_error_read_log()

log_service_error log_error_read_log ( const char *  log_name)

Restore error log messages from previous shutdown.

We try restoring from the first (leftmost) of those services listed in @global.log_error_services that have the LOG_SERVICE_LOG_PARSER characteristic.

It is assumed that the last run's log file name is the same as the current one's. That is to say, we check whether the file supplied to –log-error already exists.

Once we have determined what file to read from, we'll call

See also
log_error_read_loop() to do the actual reading and parsing.

It should be noted that at the point this function is normally called, buffered error logging will not have flushed yet.

a) If we are using the built-in "trad" sink/reader, the start-up messages are usually not buffered, and have already been written to the error log. In this case, they will be restored from the log (and flushing won't add another event to the ring-buffer).

b) If we are using a reader in a loadable log-service,

Parameters
log_nameThe log file to read (log_error_dest).
Return values
LOG_SERVICE_SUCCESSSuccess (log read and parsed)
LOG_SERVICE_UNABLE_TO_READCould not read/access() file
LOG_SERVICE_INVALID_ARGUMENTInvalid file-name (no '.')
LOG_SERVICE_NOT_AVAILABLENo log_component active that can parse log-files
LOG_SERVICE_ARGUMENT_TOO_LONGFile-name too long
LOG_SERVICE_COULD_NOT_MAKE_LOG_NAMECould not determine file extension
otherwiseReturn value from reader

◆ log_error_read_log_exit()

int log_error_read_log_exit ( )

Release error log ring-buffer.

Returns
0 Success - buffer was released, or did not exist in the first place.
Return values
0Success - buffer was released, or did not exist in the first place.

◆ log_error_read_log_init()

int log_error_read_log_init ( )

Set up ring-buffer for error-log.

Returns
0 Success - buffer was allocated.
!=0 Failure - buffer was not allocated.
Return values
0Success - buffer was allocated.
!=0Failure - buffer was not allocated.

◆ log_sink_perfschema()

int log_sink_perfschema ( void *  instance,
log_line ll 
)

services: log sinks: logging to performance_schema ring-buffer

Will write timestamp, label, thread-ID, and message to stderr/file. If you should not be able to specify a label, one will be generated for you from the line's priority field.

Parameters
instanceinstance handle
llthe log line to write
Return values
intnumber of added fields, if any

◆ log_sink_pfs_event_add()

log_service_error log_sink_pfs_event_add ( log_sink_pfs_event e,
const char *  blob_src 
)

Add a log-event to the ring buffer.

In the ring-buffer, each event exists as a header and a blob. The header is a log_sink_pfs_event struct containing the traditional error-log columns. It is followed by a variable-length blob that contains just the message string in traditional log mode, and the complete event as JSON in JSON log format. The length of the event will be align to the correct boundary.

If writing the event would go past the end of the ring-buffer, we wrap around to the beginning of the buffer.

After the function success, ring_buffer_read will be set to a valid, non-zero value.

Parameters
efilled-in event struct to copy into the ring-buffer
blob_srcvariable-length part of the event to add to the ring-buffer
Return values
LOG_SERVICE_SUCCESSevent was added
LOG_SERVICE_NOT_AVAILABLEring-buffer not available
LOG_SERVICE_INVALID_ARGUMENTevent has no message
LOG_SERVICE_ARGUMENT_TOO_LONGevent is larger than buffer(!)

◆ log_sink_pfs_event_count()

size_t log_sink_pfs_event_count ( )

Get number of events currently in ring-buffer.

Caller should hold THR_LOCK_log_perschema when reading this.

Returns
number of events current in ring-buffer (0..)

◆ log_sink_pfs_event_first()

log_sink_pfs_event * log_sink_pfs_event_first ( )

Get oldest event still in ring-buffer.

Caller should hold read-lock on THR_LOCK_log_perfschema when calling this.

Returns
nullptr No events in buffer
otherwise Address of oldest event in ring-buffer

Caller should hold read-lock on THR_LOCK_log_perfschema when calling this.

Return values
nullptrNo events in buffer
otherwiseAddress of oldest event in ring-buffer

◆ log_sink_pfs_event_next()

log_sink_pfs_event * log_sink_pfs_event_next ( log_sink_pfs_event e)

Get event following the supplied one.

Caller should hold read-lock on THR_LOCK_log_perfschema when calling this.

If advancing the read position puts the read-pointer beyond the highest-address event in the ring-buffer (which isn't necessarily the latest event, which is defined as the last event before catching up with the write-pointer), i.e. at a position where either a wrap- around marker exists, or there is not enough space for a header, we wrap around to the start of the ring-buffer.

Parameters
eLast event the caller was processing. This event should be valid, non-NULL, and should not be a wrap-around marker (m_messages_length == 0).
Return values
nullptrNo more events in ring-buffer (caught up with writer)
otherwiseAddress of the next event in the ring-buffer

◆ log_sink_pfs_event_valid()

log_sink_pfs_event * log_sink_pfs_event_valid ( log_sink_pfs_event e,
ulonglong  logged 
)

Use timestamp to check whether a given event-pointer still points to a valid event in the ring-buffer.

Caller should hold read-lock on THR_LOCK_log_perfschema when calling this.

Parameters
eAddress of event
loggedunique timestamp of event
Return values
nullptrEvent no longer exists in ring-buffer
otherwiseAddress of the event in the ring-buffer

◆ log_sink_pfs_read_end()

void log_sink_pfs_read_end ( )

Release read-lock on ring-buffer.

◆ log_sink_pfs_read_start()

void log_sink_pfs_read_start ( )

Acquire a read-lock on the ring-buffer.

Variable Documentation

◆ log_sink_pfs_buffered_bytes

ulong log_sink_pfs_buffered_bytes
extern

bytes in use (now)

◆ log_sink_pfs_buffered_events

ulong log_sink_pfs_buffered_events
extern

events in buffer (now)

◆ log_sink_pfs_expired_events

ulong log_sink_pfs_expired_events
extern

number of expired entries (ever)

◆ log_sink_pfs_latest_timestamp

ulonglong log_sink_pfs_latest_timestamp
extern

timestamp of most recent write

◆ log_sink_pfs_longest_event

ulong log_sink_pfs_longest_event
extern

longest event seen (ever)