MySQL 8.0.40
Source Code Documentation
rpl_reporting.h
Go to the documentation of this file.
1/* Copyright (c) 2006, 2024, 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 designed to work 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 either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef RPL_REPORTING_H
25#define RPL_REPORTING_H
26
27#include <stdarg.h>
28#include <stdio.h>
29#include <sys/types.h>
30#include <time.h>
31
32#include "my_compiler.h"
33#include "my_inttypes.h"
34#include "my_loglevel.h"
35#include "my_systime.h" //my_getsystime
38
39/**
40 Maximum size of an error message from a slave thread.
41 */
42#define MAX_SLAVE_ERRMSG 1024
43
44class 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 void va_report(loglevel level, int err_code, const char *prefix_msg,
77 const char *msg, va_list v_args) const
78 MY_ATTRIBUTE((format(printf, 5, 0)));
79
80 /**
81 Clear errors. They will not show up under <code>SHOW SLAVE
82 STATUS</code>.
83 */
84 void clear_error() {
88 }
89
90 /**
91 Check if the current error is of temporary nature or not.
92 */
93 int has_temporary_error(THD *thd, uint error_arg = 0,
94 bool *silent = nullptr) const;
95
96 /**
97 Error information structure.
98 */
99 class Error {
101
102 public:
103 Error() { clear(); }
104
105 void clear() {
106 number = 0;
107 message[0] = '\0';
108 timestamp[0] = '\0';
109 }
110
112 struct tm tm_tmp;
113 struct tm *start;
114 time_t tt_tmp;
115
116 skr = my_getsystime() / 10;
117 tt_tmp = skr / 1000000;
118 localtime_r(&tt_tmp, &tm_tmp);
119 start = &tm_tmp;
120
121 snprintf(timestamp, sizeof(timestamp), "%02d%02d%02d %02d:%02d:%02d",
122 start->tm_year % 100, start->tm_mon + 1, start->tm_mday,
123 start->tm_hour, start->tm_min, start->tm_sec);
124 timestamp[15] = '\0';
125 }
126
127 /** Error code */
129 /** Error message */
131 /** Error timestamp as string */
132 char timestamp[64];
133 /** Error timestamp in microseconds. Used in performance_schema */
135 };
136
137 Error const &last_error() const { return m_last_error; }
138 bool is_error() const { return last_error().number != 0; }
139
140 /*
141 For MSR, there is a need to introduce error messages per channel.
142 Instead of changing the error messages in share/messages_to_error_log.txt
143 to introduce the clause, FOR CHANNEL "%s", we construct a string like this.
144 There might be problem with a client applications which could print
145 error messages and see no %s.
146 @TODO: fix this.
147 */
148 virtual const char *get_for_channel_str(bool upper_case) const = 0;
149
150 virtual ~Slave_reporting_capability() = 0;
151
152 protected:
153 virtual void do_report(loglevel level, int err_code, const char *msg,
154 va_list v_args) const
155 MY_ATTRIBUTE((format(printf, 4, 0)));
156
157 /**
158 Last error produced by the I/O or SQL thread respectively.
159 */
161
162 private:
163 char const *const m_thread_name;
164
165 // not implemented
168};
169
170inline void Slave_reporting_capability::do_report(loglevel level, int err_code,
171 const char *msg,
172 va_list v_args) const {
173 va_report(level, err_code, nullptr, msg, v_args);
174}
175
176#endif // RPL_REPORTING_H
Error information structure.
Definition: rpl_reporting.h:99
char message[MAX_SLAVE_ERRMSG]
Error message.
Definition: rpl_reporting.h:130
char timestamp[64]
Error timestamp as string.
Definition: rpl_reporting.h:132
Error()
Definition: rpl_reporting.h:103
void clear()
Definition: rpl_reporting.h:105
void update_timestamp()
Definition: rpl_reporting.h:111
ulonglong skr
Error timestamp in microseconds.
Definition: rpl_reporting.h:134
uint32 number
Error code.
Definition: rpl_reporting.h:128
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:137
virtual void do_report(loglevel level, int err_code, const char *msg, va_list v_args) const
Definition: rpl_reporting.h:170
Slave_reporting_capability(char const *thread_name)
Constructor.
Definition: rpl_reporting.cc:42
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:125
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:117
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:67
void clear_error()
Clear errors.
Definition: rpl_reporting.h:84
bool is_error() const
Definition: rpl_reporting.h:138
virtual ~Slave_reporting_capability()=0
Definition: rpl_reporting.cc:191
Error m_last_error
Last error produced by the I/O or SQL thread respectively.
Definition: rpl_reporting.h:160
char const *const m_thread_name
Definition: rpl_reporting.h:163
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:34
#define mysql_mutex_lock(M)
Definition: mysql_mutex.h:50
#define mysql_mutex_unlock(M)
Definition: mysql_mutex.h:57
static void start(mysql_harness::PluginFuncEnv *env)
Definition: http_auth_backend_plugin.cc:177
Header for compiler-dependent features.
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
uint32_t uint32
Definition: my_inttypes.h:67
Definition of the global "loglevel" enumeration.
loglevel
Definition: my_loglevel.h:41
Defines for getting and processing the current system type programmatically.
unsigned long long int my_getsystime()
Get high-resolution time.
Definition: my_systime.h:102
ABI for instrumented mutexes.
static bool silent
Definition: mysqlimport.cc:66
Instrumentation helpers for mutexes.
#define MAX_SLAVE_ERRMSG
Maximum size of an error message from a slave thread.
Definition: rpl_reporting.h:42
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50
Include file for Sun RPC to compile out of the box.
unsigned int uint
Definition: uca9-dump.cc:75