MySQL 8.0.40
Source Code Documentation
log_sink_perfschema.h
Go to the documentation of this file.
1/* Copyright (c) 2020, 2024, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License, version 2.0,
5as published by the Free Software Foundation.
6
7This program is designed to work with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have either included with
13the program or referenced in the documentation.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License, version 2.0, for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24/**
25 @file sql/server_component/log_sink_perfschema.h
26
27 This file contains
28
29 a) The API for the reading of previously written error logs.
30 (These functions will in turn use a parse-function defined
31 in a log-sink. Whichever log-sink that has a parse-function
32 is listed first in @@global.log_error_services will be used;
33 that service will decide what log-file to read (i.e. its name)
34 and how to parse it. We initially support the reading of JSON-
35 formatted error log files and of the traditional MySQL error
36 log files.)
37 This lets us restore error log information from previous runs
38 when the server starts.
39 These functions are called from mysqld.cc at start-up.
40
41 b) The log-sink that adds errors logged at run-time to the ring-buffer
42 (to be called from @see log_line_submit() during normal operation, i.e.
43 when loadable log-components are available, connections are accepted,
44 and so on).
45*/
46
47#ifndef LOG_SINK_PERFSCHEMA_H
48#define LOG_SINK_PERFSCHEMA_H
49
51#include "my_thread_local.h" // my_thread_id
52
53/* "MY-123456" - 6 digits, "MY-", '\0' */
54#define LOG_SINK_PFS_ERROR_CODE_LENGTH 10
55
56/* Currently one of "Repl"/"InnoDB"/"Server" + '\0' */
57#define LOG_SINK_PFS_SUBSYS_LENGTH 7
58
59typedef struct _log_sink_pfs_event {
60 /** Column ERROR_LOG_TIMESTAMP. Logger should forcibly make these unique. */
62
63 /** Column ERROR_LOG_THREAD. */
64 ulonglong m_thread_id; // PFS_key_thread_id uses ulonglong, not my_thread_id
65
66 /** Column ERROR_LOG_PRIO. */
67 ulong m_prio;
68
69 /** Column ERROR_LOG_ERROR_CODE. */
72
73 /** Column ERROR_LOG_SUBSYS. */
76
77 /** Column ERROR_LOG_MESSAGE. */
78 uint m_message_length; ///< actual length, not counting trailing '\0'
80
81/*
82 We make these public for SHOW STATUS.
83 Everybody else should use the getter functions.
84
85 The timestamp is made available to allow for
86 easy checks whether log entries were added since
87 the interested part last polled.
88 The timestamp is provided as a unique value with
89 microsecond precision for that use; to view it in
90 a more human-friendly format, use
91
92 SELECT FROM_UNIXTIME(variable_value/1000000)
93 FROM global_status WHERE variable_name="Error_log_latest_write";
94
95 Thus if you expect to check for new events with some
96 regularity, you could start off with
97
98 SELECT 0 INTO @error_log_last_poll;
99
100 and then poll using something like
101
102 SELECT logged,prio,error_code,subsystem,data
103 FROM performance_schema.error_log
104 WHERE logged>@error_log_last_poll;
105
106 SELECT FROM_UNIXTIME(variable_value/1000000)
107 FROM global_status WHERE variable_name="Error_log_latest_write"
108 INTO @error_log_last_poll;
109
110 (Ideally though you'd update @error_log_last_poll from the 'logged'
111 field (that is, the timestamp) of the last new row you received.)
112*/
113extern ulong log_sink_pfs_buffered_bytes; ///< bytes in use (now)
114extern ulong log_sink_pfs_buffered_events; ///< events in buffer (now)
115extern ulong log_sink_pfs_expired_events; ///< number of expired entries (ever)
116extern ulong log_sink_pfs_longest_event; ///< longest event seen (ever)
117extern ulonglong
118 log_sink_pfs_latest_timestamp; ///< timestamp of most recent write
119
120// The public interface to reading the error-log from the ring-buffer:
121
122/// Acquire a read-lock on the ring-buffer.
124
125/// Release read-lock on ring-buffer.
127
128/**
129 Get number of events currently in ring-buffer.
130 Caller should hold THR_LOCK_log_perschema when reading this.
131
132 @returns number of events current in ring-buffer (0..)
133*/
135
136/**
137 Get oldest event still in ring-buffer.
138 Caller should hold read-lock on THR_LOCK_log_perfschema when calling this.
139
140 @returns nullptr No events in buffer
141 @returns otherwise Address of oldest event in ring-buffer
142*/
144
146
148 ulonglong logged);
149
150// The public interface to restoring the error-log to the ring-buffer:
151
152/**
153 Set up ring-buffer for error-log.
154
155 @returns 0 Success - buffer was allocated.
156 @returns !=0 Failure - buffer was not allocated.
157*/
159
160/**
161 Release error log ring-buffer.
162
163 @returns 0 Success - buffer was released, or did not exist in the first
164 place.
165*/
167
168log_service_error log_error_read_log(const char *log_name);
169
171 const char *blob_src);
172
173int log_sink_perfschema(void *instance [[maybe_unused]], log_line *ll);
174
175#endif /* LOG_SINK_PERFSCHEMA_H */
enum enum_log_service_error log_service_error
Error codes.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
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.
Definition: log_sink_perfschema.cc:384
ulonglong log_sink_pfs_latest_timestamp
timestamp of most recent write
Definition: log_sink_perfschema.cc:85
log_service_error log_error_read_log(const char *log_name)
Restore error log messages from previous shutdown.
Definition: log_sink_perfschema.cc:687
ulong log_sink_pfs_buffered_bytes
bytes in use (now)
Definition: log_sink_perfschema.cc:81
int log_error_read_log_init()
Set up ring-buffer for error-log.
Definition: log_sink_perfschema.cc:776
ulong log_sink_pfs_expired_events
number of expired entries (ever)
Definition: log_sink_perfschema.cc:83
void log_sink_pfs_read_end()
Release read-lock on ring-buffer.
Definition: log_sink_perfschema.cc:143
#define LOG_SINK_PFS_SUBSYS_LENGTH
Definition: log_sink_perfschema.h:57
int log_error_read_log_exit()
Release error log ring-buffer.
Definition: log_sink_perfschema.cc:750
log_sink_pfs_event * log_sink_pfs_event_first()
Get oldest event still in ring-buffer.
Definition: log_sink_perfschema.cc:160
void log_sink_pfs_read_start()
Acquire a read-lock on the ring-buffer.
Definition: log_sink_perfschema.cc:136
size_t log_sink_pfs_event_count()
Get number of events currently in ring-buffer.
Definition: log_sink_perfschema.cc:151
ulong log_sink_pfs_longest_event
longest event seen (ever)
Definition: log_sink_perfschema.cc:84
struct _log_sink_pfs_event log_sink_pfs_event
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...
Definition: log_sink_perfschema.cc:235
ulong log_sink_pfs_buffered_events
events in buffer (now)
Definition: log_sink_perfschema.cc:82
int log_sink_perfschema(void *instance, log_line *ll)
services: log sinks: logging to performance_schema ring-buffer
Definition: log_sink_perfschema.cc:814
log_sink_pfs_event * log_sink_pfs_event_next(log_sink_pfs_event *e)
Get event following the supplied one.
Definition: log_sink_perfschema.cc:184
#define LOG_SINK_PFS_ERROR_CODE_LENGTH
Definition: log_sink_perfschema.h:54
log_line ("log event")
Definition: keyring_log_builtins_definition.cc:72
Definition: log_sink_perfschema.h:59
ulonglong m_thread_id
Column ERROR_LOG_THREAD.
Definition: log_sink_perfschema.h:64
char m_error_code[LOG_SINK_PFS_ERROR_CODE_LENGTH]
Column ERROR_LOG_ERROR_CODE.
Definition: log_sink_perfschema.h:70
uint m_message_length
Column ERROR_LOG_MESSAGE.
Definition: log_sink_perfschema.h:78
ulonglong m_timestamp
Column ERROR_LOG_TIMESTAMP.
Definition: log_sink_perfschema.h:61
uint m_subsys_length
Definition: log_sink_perfschema.h:75
char m_subsys[LOG_SINK_PFS_SUBSYS_LENGTH]
Column ERROR_LOG_SUBSYS.
Definition: log_sink_perfschema.h:74
ulong m_prio
Column ERROR_LOG_PRIO.
Definition: log_sink_perfschema.h:67
uint m_error_code_length
Definition: log_sink_perfschema.h:71
unsigned int uint
Definition: uca9-dump.cc:75