1 | /* Copyright (c) 2006, 2010, 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 as published by |
5 | the Free Software Foundation; version 2 of the License. |
6 | |
7 | This program is distributed in the hope that it will be useful, |
8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 | GNU General Public License for more details. |
11 | |
12 | You should have received a copy of the GNU General Public License |
13 | along with this program; if not, write to the Free Software |
14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
15 | |
16 | #ifndef RPL_REPORTING_H |
17 | #define RPL_REPORTING_H |
18 | |
19 | #include <my_sys.h> /* loglevel */ |
20 | |
21 | /** |
22 | Maximum size of an error message from a slave thread. |
23 | */ |
24 | #define MAX_SLAVE_ERRMSG 1024 |
25 | |
26 | /** |
27 | Mix-in to handle the message logging and reporting for relay log |
28 | info and master log info structures. |
29 | |
30 | By inheriting from this class, the class is imbued with |
31 | capabilities to do slave reporting. |
32 | */ |
33 | class Slave_reporting_capability |
34 | { |
35 | public: |
36 | /** lock used to synchronize m_last_error on 'SHOW SLAVE STATUS' **/ |
37 | mutable mysql_mutex_t err_lock; |
38 | /** |
39 | Constructor. |
40 | |
41 | @param thread_name Printable name of the slave thread that is reporting. |
42 | */ |
43 | Slave_reporting_capability(char const *thread_name); |
44 | |
45 | /** |
46 | Writes a message and, if it's an error message, to Last_Error |
47 | (which will be displayed by SHOW SLAVE STATUS). |
48 | |
49 | @param level The severity level |
50 | @param err_code The error code |
51 | @param msg The message (usually related to the error |
52 | code, but can contain more information), in |
53 | printf() format. |
54 | */ |
55 | void report(loglevel level, int err_code, const char *, |
56 | const char *msg, ...) const |
57 | ATTRIBUTE_FORMAT(printf, 5, 6); |
58 | |
59 | /** |
60 | Clear errors. They will not show up under <code>SHOW SLAVE |
61 | STATUS</code>. |
62 | */ |
63 | void clear_error() { |
64 | mysql_mutex_lock(&err_lock); |
65 | m_last_error.clear(); |
66 | mysql_mutex_unlock(&err_lock); |
67 | } |
68 | |
69 | /** |
70 | Error information structure. |
71 | */ |
72 | class Error { |
73 | friend class Slave_reporting_capability; |
74 | public: |
75 | Error() |
76 | { |
77 | clear(); |
78 | } |
79 | |
80 | void clear() |
81 | { |
82 | number= 0; |
83 | message[0]= '\0'; |
84 | } |
85 | |
86 | /** Error code */ |
87 | uint32 number; |
88 | /** Error message */ |
89 | char message[MAX_SLAVE_ERRMSG]; |
90 | }; |
91 | |
92 | Error const& last_error() const { return m_last_error; } |
93 | |
94 | virtual ~Slave_reporting_capability()= 0; |
95 | private: |
96 | /** |
97 | Last error produced by the I/O or SQL thread respectively. |
98 | */ |
99 | mutable Error m_last_error; |
100 | |
101 | char const *const m_thread_name; |
102 | |
103 | // not implemented |
104 | Slave_reporting_capability(const Slave_reporting_capability& rhs); |
105 | Slave_reporting_capability& operator=(const Slave_reporting_capability& rhs); |
106 | }; |
107 | |
108 | #endif // RPL_REPORTING_H |
109 | |
110 | |