MySQL 8.3.0
Source Code Documentation
rpl_reporting.h
Go to the documentation of this file.
1/* Copyright (c) 2006, 2023, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef RPL_REPORTING_H
24#define RPL_REPORTING_H
25
26#include <stdarg.h>
27#include <stdio.h>
28#include <sys/types.h>
29#include <time.h>
30
31#include "my_compiler.h"
32#include "my_inttypes.h"
33#include "my_systime.h" //my_getsystime
35#include "mysql/my_loglevel.h"
37
38/**
39 Maximum size of an error message from a slave thread.
40 */
41#define MAX_SLAVE_ERRMSG 1024
42
43class THD;
45
46/**
47 Mix-in to handle the message logging and reporting for relay log
48 info and master log info structures.
49
50 By inheriting from this class, the class is imbued with
51 capabilities to do slave reporting.
52 */
54 public:
55 /** lock used to synchronize m_last_error on 'SHOW SLAVE STATUS' **/
57 /**
58 Constructor.
59
60 @param thread_name Printable name of the slave thread that is reporting.
61 */
62 Slave_reporting_capability(char const *thread_name);
63
64 /**
65 Writes a message and, if it's an error message, to Last_Error
66 (which will be displayed by SHOW SLAVE STATUS).
67
68 @param level The severity level
69 @param err_code The error code
70 @param msg The message (usually related to the error
71 code, but can contain more information), in
72 printf() format.
73 */
74 virtual void report(loglevel level, int err_code, const char *msg, ...) const
75 MY_ATTRIBUTE((format(printf, 4, 5)));
76
77 virtual void report(loglevel level, int err_code,
78 const Gtid_specification *gtid_next, const char *msg,
79 ...) const MY_ATTRIBUTE((format(printf, 5, 6)));
80
81 void va_report(loglevel level, int err_code, const char *prefix_msg,
82 const char *msg, va_list v_args) const
83 MY_ATTRIBUTE((format(printf, 5, 0)));
84
85 /**
86 Clear errors. They will not show up under <code>SHOW SLAVE
87 STATUS</code>.
88 */
89 void clear_error() {
93 }
94
95 /**
96 Check if the current error is of temporary nature or not.
97 */
98 int has_temporary_error(THD *thd, uint error_arg = 0,
99 bool *silent = nullptr) const;
100
101 /**
102 Error information structure.
103 */
104 class Error {
106
107 public:
108 Error() { clear(); }
109
110 void clear() {
111 number = 0;
112 message[0] = '\0';
113 timestamp[0] = '\0';
114 }
115
117 struct tm tm_tmp;
118 struct tm *start;
119 time_t tt_tmp;
120
121 skr = my_getsystime() / 10;
122 tt_tmp = skr / 1000000;
123 localtime_r(&tt_tmp, &tm_tmp);
124 start = &tm_tmp;
125
126 snprintf(timestamp, sizeof(timestamp), "%02d%02d%02d %02d:%02d:%02d",
127 start->tm_year % 100, start->tm_mon + 1, start->tm_mday,
128 start->tm_hour, start->tm_min, start->tm_sec);
129 timestamp[15] = '\0';
130 }
131
132 /** Error code */
134 /** Error message */
136 /** Error timestamp as string */
137 char timestamp[64];
138 /** Error timestamp in microseconds. Used in performance_schema */
140 };
141
142 Error const &last_error() const { return m_last_error; }
143 bool is_error() const { return last_error().number != 0; }
144
145 /*
146 For MSR, there is a need to introduce error messages per channel.
147 Instead of changing the error messages in share/messages_to_error_log.txt
148 to introduce the clause, FOR CHANNEL "%s", we construct a string like this.
149 There might be problem with a client applications which could print
150 error messages and see no %s.
151 @TODO: fix this.
152 */
153 virtual const char *get_for_channel_str(bool upper_case) const = 0;
154
155 virtual ~Slave_reporting_capability() = 0;
156
157 protected:
158 virtual void do_report(loglevel level, int err_code, const char *msg,
159 va_list v_args) const
160 MY_ATTRIBUTE((format(printf, 4, 0)));
161
162 virtual void do_report(loglevel level, int err_code,
163 const Gtid_specification *gtid_next, const char *msg,
164 va_list v_args) const
165 MY_ATTRIBUTE((format(printf, 5, 0)));
166
167 /**
168 Last error produced by the I/O or SQL thread respectively.
169 */
171
172 private:
173 char const *const m_thread_name;
174
175 // not implemented
178};
179
180inline void Slave_reporting_capability::do_report(loglevel level, int err_code,
181 const char *msg,
182 va_list v_args) const {
183 va_report(level, err_code, nullptr, msg, v_args);
184}
185
186inline void Slave_reporting_capability::do_report(loglevel level, int err_code,
187 const Gtid_specification *,
188 const char *msg,
189 va_list v_args) const {
190 va_report(level, err_code, nullptr, msg, v_args);
191}
192
193#endif // RPL_REPORTING_H
Error information structure.
Definition: rpl_reporting.h:104
char message[MAX_SLAVE_ERRMSG]
Error message.
Definition: rpl_reporting.h:135
char timestamp[64]
Error timestamp as string.
Definition: rpl_reporting.h:137
Error()
Definition: rpl_reporting.h:108
void clear()
Definition: rpl_reporting.h:110
void update_timestamp()
Definition: rpl_reporting.h:116
ulonglong skr
Error timestamp in microseconds.
Definition: rpl_reporting.h:139
uint32 number
Error code.
Definition: rpl_reporting.h:133
Mix-in to handle the message logging and reporting for relay log info and master log info structures.
Definition: rpl_reporting.h:53
Error const & last_error() const
Definition: rpl_reporting.h:142
virtual void do_report(loglevel level, int err_code, const char *msg, va_list v_args) const
Definition: rpl_reporting.h:180
Slave_reporting_capability(char const *thread_name)
Constructor.
Definition: rpl_reporting.cc:41
Slave_reporting_capability(const Slave_reporting_capability &rhs)
Slave_reporting_capability & operator=(const Slave_reporting_capability &rhs)
virtual const char * get_for_channel_str(bool upper_case) const =0
mysql_mutex_t err_lock
lock used to synchronize m_last_error on 'SHOW SLAVE STATUS'
Definition: rpl_reporting.h:56
void va_report(loglevel level, int err_code, const char *prefix_msg, const char *msg, va_list v_args) const
Definition: rpl_reporting.cc:132
virtual void report(loglevel level, int err_code, const char *msg,...) const
Writes a message and, if it's an error message, to Last_Error (which will be displayed by SHOW SLAVE ...
Definition: rpl_reporting.cc:115
int has_temporary_error(THD *thd, uint error_arg=0, bool *silent=nullptr) const
Check if the current error is of temporary nature or not.
Definition: rpl_reporting.cc:63
void clear_error()
Clear errors.
Definition: rpl_reporting.h:89
bool is_error() const
Definition: rpl_reporting.h:143
virtual ~Slave_reporting_capability()=0
Definition: rpl_reporting.cc:198
Error m_last_error
Last error produced by the I/O or SQL thread respectively.
Definition: rpl_reporting.h:170
char const *const m_thread_name
Definition: rpl_reporting.h:173
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:35
#define mysql_mutex_lock(M)
Definition: mysql_mutex.h:49
#define mysql_mutex_unlock(M)
Definition: mysql_mutex.h:56
static void start(mysql_harness::PluginFuncEnv *env)
Definition: http_auth_backend_plugin.cc:176
Header for compiler-dependent features.
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
uint32_t uint32
Definition: my_inttypes.h:66
Definition of the global "loglevel" enumeration.
loglevel
Definition: my_loglevel.h:40
Defines for getting and processing the current system type programmatically.
unsigned long long int my_getsystime()
Get high-resolution time.
Definition: my_systime.h:101
ABI for instrumented mutexes.
static bool silent
Definition: mysqlimport.cc:69
Instrumentation helpers for mutexes.
#define MAX_SLAVE_ERRMSG
Maximum size of an error message from a slave thread.
Definition: rpl_reporting.h:41
This struct represents a specification of a GTID for a statement to be executed: either "AUTOMATIC",...
Definition: rpl_gtid.h:3971
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
Include file for Sun RPC to compile out of the box.