1
2/* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; version 2 of the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
17#include "mariadb.h"
18#include "sql_priv.h"
19#include "rpl_reporting.h"
20#include "log.h" // sql_print_error, sql_print_warning,
21 // sql_print_information
22
23Slave_reporting_capability::Slave_reporting_capability(char const *thread_name)
24 : m_thread_name(thread_name)
25{
26 mysql_mutex_init(key_mutex_slave_reporting_capability_err_lock,
27 &err_lock, MY_MUTEX_INIT_FAST);
28}
29
30void
31Slave_reporting_capability::report(loglevel level, int err_code,
32 const char *extra_info,
33 const char *msg, ...) const
34{
35 void (*report_function)(const char *, ...);
36 char buff[MAX_SLAVE_ERRMSG];
37 char *pbuff= buff;
38 uint pbuffsize= sizeof(buff);
39 va_list args;
40 va_start(args, msg);
41
42 mysql_mutex_lock(&err_lock);
43 switch (level)
44 {
45 case ERROR_LEVEL:
46 /*
47 It's an error, it must be reported in Last_error and Last_errno in SHOW
48 SLAVE STATUS.
49 */
50 pbuff= m_last_error.message;
51 pbuffsize= sizeof(m_last_error.message);
52 m_last_error.number = err_code;
53 report_function= sql_print_error;
54 break;
55 case WARNING_LEVEL:
56 report_function= sql_print_warning;
57 break;
58 case INFORMATION_LEVEL:
59 report_function= sql_print_information;
60 break;
61 default:
62 va_end(args);
63 DBUG_ASSERT(0); // should not come here
64 return; // don't crash production builds, just do nothing
65 }
66
67 my_vsnprintf(pbuff, pbuffsize, msg, args);
68
69 mysql_mutex_unlock(&err_lock);
70 va_end(args);
71
72 /* If the msg string ends with '.', do not add a ',' it would be ugly */
73 report_function("Slave %s: %s%s %s%sInternal MariaDB error code: %d",
74 m_thread_name, pbuff,
75 (pbuff[0] && *(strend(pbuff)-1) == '.') ? "" : ",",
76 (extra_info ? extra_info : ""), (extra_info ? ", " : ""),
77 err_code);
78}
79
80Slave_reporting_capability::~Slave_reporting_capability()
81{
82 mysql_mutex_destroy(&err_lock);
83}
84