MySQL  8.0.18
Source Code Documentation
rpl_reporting.h
Go to the documentation of this file.
1 /* Copyright (c) 2006, 2019, Oracle and/or its affiliates. All rights reserved.
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_loglevel.h"
34 #include "my_systime.h" //my_getsystime
36 #include "mysql/psi/mysql_mutex.h"
37 
38 /**
39  Maximum size of an error message from a slave thread.
40  */
41 #define MAX_SLAVE_ERRMSG 1024
42 
43 class THD;
44 
45 /**
46  Mix-in to handle the message logging and reporting for relay log
47  info and master log info structures.
48 
49  By inheriting from this class, the class is imbued with
50  capabilities to do slave reporting.
51  */
53  public:
54  /** lock used to synchronize m_last_error on 'SHOW SLAVE STATUS' **/
56  /**
57  Constructor.
58 
59  @param thread_name Printable name of the slave thread that is reporting.
60  */
61  Slave_reporting_capability(char const *thread_name);
62 
63  /**
64  Writes a message and, if it's an error message, to Last_Error
65  (which will be displayed by SHOW SLAVE STATUS).
66 
67  @param level The severity level
68  @param err_code The error code
69  @param msg The message (usually related to the error
70  code, but can contain more information), in
71  printf() format.
72  */
73  virtual void report(loglevel level, int err_code, const char *msg, ...) const
74  MY_ATTRIBUTE((format(printf, 4, 5)));
75  void va_report(loglevel level, int err_code, const char *prefix_msg,
76  const char *msg, va_list v_args) const
77  MY_ATTRIBUTE((format(printf, 5, 0)));
78 
79  /**
80  Clear errors. They will not show up under <code>SHOW SLAVE
81  STATUS</code>.
82  */
83  void clear_error() {
87  }
88 
89  /**
90  Check if the current error is of temporary nature or not.
91  */
92  int has_temporary_error(THD *thd, uint error_arg = 0,
93  bool *silent = nullptr) const;
94 
95  /**
96  Error information structure.
97  */
98  class Error {
100 
101  public:
102  Error() { clear(); }
103 
104  void clear() {
105  number = 0;
106  message[0] = '\0';
107  timestamp[0] = '\0';
108  }
109 
111  struct tm tm_tmp;
112  struct tm *start;
113  time_t tt_tmp;
114 
115  skr = my_getsystime() / 10;
116  tt_tmp = skr / 1000000;
117  localtime_r(&tt_tmp, &tm_tmp);
118  start = &tm_tmp;
119 
120  snprintf(timestamp, sizeof(timestamp), "%02d%02d%02d %02d:%02d:%02d",
121  start->tm_year % 100, start->tm_mon + 1, start->tm_mday,
122  start->tm_hour, start->tm_min, start->tm_sec);
123  timestamp[15] = '\0';
124  }
125 
126  /** Error code */
128  /** Error message */
130  /** Error timestamp as string */
131  char timestamp[64];
132  /** Error timestamp in microseconds. Used in performance_schema */
134  };
135 
136  Error const &last_error() const { return m_last_error; }
137  bool is_error() const { return last_error().number != 0; }
138 
139  /*
140  For MSR, there is a need to introduce error messages per channel.
141  Instead of changing the error messages in share/errmsg-utf8.txt to
142  introduce the clause, FOR CHANNEL "%s", we construct a string like this.
143  There might be problem with a client applications which could print
144  error messages and see no %s.
145  @TODO: fix this.
146  */
147  virtual const char *get_for_channel_str(bool upper_case) const = 0;
148 
149  virtual ~Slave_reporting_capability() = 0;
150 
151  protected:
152  virtual void do_report(loglevel level, int err_code, const char *msg,
153  va_list v_args) const
154  MY_ATTRIBUTE((format(printf, 4, 0)));
155 
156  /**
157  Last error produced by the I/O or SQL thread respectively.
158  */
160 
161  private:
162  char const *const m_thread_name;
163 
164  // not implemented
167 };
168 
169 inline void Slave_reporting_capability::do_report(loglevel level, int err_code,
170  const char *msg,
171  va_list v_args) const {
172  va_report(level, err_code, nullptr, msg, v_args);
173 }
174 
175 #endif // RPL_REPORTING_H
#define MAX_SLAVE_ERRMSG
Maximum size of an error message from a slave thread.
Definition: rpl_reporting.h:41
char message[MAX_SLAVE_ERRMSG]
Error message.
Definition: rpl_reporting.h:129
unsigned long long int ulonglong
Definition: my_inttypes.h:55
Instrumentation helpers for mutexes.
Defines for getting and processing the current system type programmatically.
uint32 number
Error code.
Definition: rpl_reporting.h:127
Include file for Sun RPC to compile out of the box.
Some integer typedefs for easier portability.
char const *const m_thread_name
Definition: rpl_reporting.h:162
Mix-in to handle the message logging and reporting for relay log info and master log info structures...
Definition: rpl_reporting.h:52
void clear()
Definition: rpl_reporting.h:104
Slave_reporting_capability & operator=(const Slave_reporting_capability &rhs)
Slave_reporting_capability(char const *thread_name)
Constructor.
Definition: rpl_reporting.cc:41
ulonglong skr
Error timestamp in microseconds.
Definition: rpl_reporting.h:133
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
mysql_mutex_t err_lock
lock used to synchronize m_last_error on &#39;SHOW SLAVE STATUS&#39;
Definition: rpl_reporting.h:55
virtual void report(loglevel level, int err_code, const char *msg,...) const
Writes a message and, if it&#39;s an error message, to Last_Error (which will be displayed by SHOW SLAVE ...
Definition: rpl_reporting.cc:115
Error()
Definition: rpl_reporting.h:102
Header for compiler-dependent features.
unsigned int uint
Definition: uca-dump.cc:29
Error information structure.
Definition: rpl_reporting.h:98
char timestamp[64]
Error timestamp as string.
Definition: rpl_reporting.h:131
unsigned long long int my_getsystime()
Get high-resolution time.
Definition: my_systime.h:100
uint32_t uint32
Definition: my_inttypes.h:66
bool is_error() const
Definition: rpl_reporting.h:137
void clear_error()
Clear errors.
Definition: rpl_reporting.h:83
char msg[1024]
Definition: test_sql_9_sessions.cc:281
static bool silent
Definition: mysqlimport.cc:65
Error const & last_error() const
Definition: rpl_reporting.h:136
Definition of the global "loglevel" enumeration.
Error m_last_error
Last error produced by the I/O or SQL thread respectively.
Definition: rpl_reporting.h:159
void update_timestamp()
Definition: rpl_reporting.h:110
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
ABI for instrumented mutexes.
loglevel
Definition: my_loglevel.h:32
#define mysql_mutex_unlock(M)
Definition: mysql_mutex.h:53
static void start(PluginFuncEnv *env)
Definition: http_server_plugin.cc:572
#define mysql_mutex_lock(M)
Definition: mysql_mutex.h:44
void va_report(loglevel level, int err_code, const char *prefix_msg, const char *msg, va_list v_args) const
Definition: rpl_reporting.cc:123
virtual const char * get_for_channel_str(bool upper_case) const =0
virtual void do_report(loglevel level, int err_code, const char *msg, va_list v_args) const
Definition: rpl_reporting.h:169
virtual ~Slave_reporting_capability()=0
Definition: rpl_reporting.cc:189
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:778