Skip to content

Commit cb8240c

Browse files
committed
WL#11009 - Logging services: log writers: add error ID to traditional error log
Follow-up patch to add error ID to the error messages logged from the plugins. As part of this patch, error logging is changed in the following plugins to log error message with the new error IDs introduced: Rewriter connection_control Xplugin Keyring plugins Group Replication authentication_ldap RB: 18531
1 parent 8542a72 commit cb8240c

File tree

114 files changed

+2612
-1504
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+2612
-1504
lines changed

include/mysql/components/services/log_builtins.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -713,6 +713,15 @@ extern SERVICE_TYPE(log_builtins_string) *log_bs;
713713
.lookup_quoted(ecode, "Plugin " LOG_SUBSYSTEM_TAG " reported",\
714714
## __VA_ARGS__)
715715

716+
#define LogPluginErrV(severity, ecode, vl) \
717+
LogEvent().prio(severity)\
718+
.errcode(ecode)\
719+
.subsys(LOG_SUBSYSTEM_TAG)\
720+
.source_line(__LINE__)\
721+
.source_file(MY_BASENAME)\
722+
.function(__FUNCTION__)\
723+
.lookup_quotedv(ecode, "Plugin " LOG_SUBSYSTEM_TAG " reported", vl)
724+
716725
#define LogPluginErrMsg(severity, ecode, ...) \
717726
LogEvent().prio(severity)\
718727
.errcode(ecode)\
@@ -736,6 +745,8 @@ inline void dummy_log_message(longlong severity MY_ATTRIBUTE((unused)),
736745
dummy_log_message(severity, ecode, ## __VA_ARGS__)
737746
#define LogPluginErr(severity, ecode, ...) \
738747
dummy_log_message(severity, ecode, ## __VA_ARGS__)
748+
#define LogPluginErrV(severity, ecode, ...) \
749+
dummy_log_message(severity, ecode, ## __VA_ARGS__)
739750
#define LogPluginErrMsg(severity, ecode, ...) \
740751
dummy_log_message(severity, ecode, ## __VA_ARGS__)
741752

@@ -1242,6 +1253,14 @@ class LogEvent
12421253
return *this;
12431254
}
12441255

1256+
LogEvent &lookup_quotedv(longlong errcode, const char *tag, va_list vl)
1257+
{
1258+
msg_tag= tag;
1259+
set_message_by_errcode(errcode, vl);
1260+
1261+
return *this;
1262+
}
1263+
12451264
/**
12461265
Add a ad hoc integer value with the given key.
12471266

mysql-test/suite/query_rewrite_plugins/r/errors.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ UPDATE error_log SET line = replace ( line, '\r', '' );
4747
# Avoid seeing any other error that might be there.
4848
SELECT search_error_log( '[Error]', "%Plugin Rewriter reported: 'Wrong%" );
4949
search_error_log( '[Error]', "%Plugin Rewriter reported: 'Wrong%" )
50-
[ERROR] [MY-011235] Plugin Rewriter reported: 'Wrong column count or names when loading rules.'
50+
[ERROR] [MY-011274] Plugin Rewriter reported: 'Wrong column count or names when loading rules.'
5151
SHOW STATUS LIKE 'Rewriter_number_reloads';
5252
Variable_name Value
5353
Rewriter_number_reloads 1
@@ -70,7 +70,7 @@ UPDATE error_log SET line = replace ( line, '\r', '' );
7070
# Avoid seeing any other error that might be there.
7171
SELECT search_error_log( '[Error]', "%Plugin Rewriter reported: 'Wrong%" );
7272
search_error_log( '[Error]', "%Plugin Rewriter reported: 'Wrong%" )
73-
[ERROR] [MY-011235] Plugin Rewriter reported: 'Wrong column count or names when loading rules.'
73+
[ERROR] [MY-011274] Plugin Rewriter reported: 'Wrong column count or names when loading rules.'
7474
SHOW STATUS LIKE 'Rewriter_number_reloads';
7575
Variable_name Value
7676
Rewriter_number_reloads 1

plugin/connection_control/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0,
@@ -28,3 +28,4 @@ MYSQL_ADD_PLUGIN(connection_control
2828
MODULE_ONLY)
2929

3030
ADD_DEFINITIONS(-DMYSQL_SERVER)
31+
ADD_DEFINITIONS(-DLOG_SUBSYSTEM_TAG="CONNECTION_CONTROL")

plugin/connection_control/connection_control.cc

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -20,8 +20,6 @@
2020
along with this program; if not, write to the Free Software
2121
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
2222

23-
#define LOG_SUBSYSTEM_TAG "CONNECTION_CONTROL"
24-
2523
#include "plugin/connection_control/connection_control.h"
2624

2725
#include <mysql/plugin_audit.h> /* mysql_event_connection */
@@ -45,16 +43,13 @@ namespace connection_control
4543
class Connection_control_error_handler : public Error_handler
4644
{
4745
public:
48-
Connection_control_error_handler(MYSQL_PLUGIN plugin_info)
49-
: m_plugin_info(plugin_info)
50-
{}
51-
52-
void handle_error(const char * error_message)
46+
void handle_error(longlong errcode, ...)
5347
{
54-
LogPluginErr(ERROR_LEVEL, ER_CONN_CONTROL_ERROR_MSG, error_message);
48+
va_list vl;
49+
va_start(vl, errcode);
50+
LogPluginErrV(ERROR_LEVEL, errcode, vl);
51+
va_end(vl);
5552
}
56-
private:
57-
MYSQL_PLUGIN m_plugin_info;
5853
};
5954
}
6055

@@ -96,7 +91,7 @@ connection_control_notify(MYSQL_THD thd,
9691
{
9792
const struct mysql_event_connection *connection_event=
9893
(const struct mysql_event_connection *) event;
99-
Connection_control_error_handler error_handler(connection_control_plugin_info);
94+
Connection_control_error_handler error_handler;
10095
/** Notify event coordinator */
10196
g_connection_event_coordinator->notify_event(thd, &error_handler,
10297
connection_event);
@@ -129,11 +124,11 @@ connection_control_init(MYSQL_PLUGIN plugin_info)
129124
return 1;
130125

131126
connection_control_plugin_info= plugin_info;
132-
Connection_control_error_handler error_handler(connection_control_plugin_info);
127+
Connection_control_error_handler error_handler;
133128
g_connection_event_coordinator= new Connection_event_coordinator();
134129
if (!g_connection_event_coordinator)
135130
{
136-
error_handler.handle_error("Failed to initialize Connection_event_coordinator");
131+
error_handler.handle_error(ER_CONN_CONTROL_EVENT_COORDINATOR_INIT_FAILED);
137132
deinit_logging_service_for_plugin(&reg_srv, &log_bi, &log_bs);
138133
return 1;
139134
}
@@ -254,7 +249,7 @@ update_failed_connections_threshold(MYSQL_THD thd MY_ATTRIBUTE((unused)),
254249
*/
255250
longlong new_value= *(reinterpret_cast<const longlong *>(save));
256251
g_variables.failed_connections_threshold= (int64)new_value;
257-
Connection_control_error_handler error_handler(connection_control_plugin_info);
252+
Connection_control_error_handler error_handler;
258253
g_connection_event_coordinator->notify_sys_var(&error_handler,
259254
OPT_FAILED_CONNECTIONS_THRESHOLD,
260255
&new_value);
@@ -334,7 +329,7 @@ update_min_connection_delay(MYSQL_THD thd MY_ATTRIBUTE((unused)),
334329
{
335330
longlong new_value= *(reinterpret_cast<const longlong *>(save));
336331
g_variables.min_connection_delay= (int64)new_value;
337-
Connection_control_error_handler error_handler(connection_control_plugin_info);
332+
Connection_control_error_handler error_handler;
338333
g_connection_event_coordinator->notify_sys_var(&error_handler,
339334
OPT_MIN_CONNECTION_DELAY,
340335
&new_value);
@@ -414,7 +409,7 @@ update_max_connection_delay(MYSQL_THD thd MY_ATTRIBUTE((unused)),
414409
{
415410
longlong new_value= *(reinterpret_cast<const longlong *>(save));
416411
g_variables.max_connection_delay= (int64)new_value;
417-
Connection_control_error_handler error_handler(connection_control_plugin_info);
412+
Connection_control_error_handler error_handler;
418413
g_connection_event_coordinator->notify_sys_var(&error_handler,
419414
OPT_MAX_CONNECTION_DELAY,
420415
&new_value);

plugin/connection_control/connection_control_interfaces.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -40,7 +40,7 @@ namespace connection_control
4040
class Error_handler
4141
{
4242
public:
43-
virtual void handle_error(const char * error_message)= 0;
43+
virtual void handle_error(longlong errcode, ...)= 0;
4444
virtual ~Error_handler() {}
4545
};
4646

plugin/connection_control/connection_delay.cc

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "my_compiler.h"
3131
#include "my_dbug.h"
3232
#include "my_systime.h"
33+
#include "mysqld_error.h"
3334
#include "plugin/connection_control/connection_control.h"
3435
#include "plugin/connection_control/security_context_wrapper.h"
3536
#include "sql/current_thd.h" /* current_thd */
@@ -666,7 +667,8 @@ namespace connection_control
666667
if ((error= coordinator->notify_status_var(
667668
&self, STAT_CONNECTION_DELAY_TRIGGERED, ACTION_INC)))
668669
{
669-
error_handler->handle_error("Failed to update connection delay triggered stats");
670+
error_handler->handle_error(
671+
ER_CONN_CONTROL_STAT_CONN_DELAY_TRIGGERED_UPDATE_FAILED);
670672
}
671673
/*
672674
Invoking sleep while holding read lock on Connection_delay_action
@@ -686,12 +688,9 @@ namespace connection_control
686688
*/
687689
if (m_userhost_hash.create_or_update_entry(userhost))
688690
{
689-
char error_buffer[512];
690-
memset(error_buffer, 0, sizeof(error_buffer));
691-
my_snprintf(error_buffer, sizeof(error_buffer)-1,
692-
"Failed to update connection delay hash for account : %s",
693-
userhost.c_str());
694-
error_handler->handle_error(error_buffer);
691+
error_handler->handle_error(
692+
ER_CONN_CONTROL_FAILED_TO_UPDATE_CONN_DELAY_HASH,
693+
userhost.c_str());
695694
error= true;
696695
}
697696
}
@@ -750,7 +749,8 @@ namespace connection_control
750749
STAT_CONNECTION_DELAY_TRIGGERED,
751750
ACTION_RESET)))
752751
{
753-
error_handler->handle_error("Failed to reset connection delay triggered stats");
752+
error_handler->handle_error(
753+
ER_CONN_CONTROL_STAT_CONN_DELAY_TRIGGERED_RESET_FAILED);
754754
}
755755
break;
756756
}
@@ -761,19 +761,16 @@ namespace connection_control
761761
if ((error= set_delay(new_delay,
762762
(variable == OPT_MIN_CONNECTION_DELAY))))
763763
{
764-
char error_buffer[512];
765-
memset(error_buffer, 0, sizeof(error_buffer));
766-
my_snprintf(error_buffer, sizeof(error_buffer) - 1,
767-
"Could not set %s delay for connection delay.",
768-
(variable == OPT_MIN_CONNECTION_DELAY) ? "min" : "max");
769-
error_handler->handle_error(error_buffer);
764+
error_handler->handle_error(
765+
ER_CONN_CONTROL_FAILED_TO_SET_CONN_DELAY,
766+
(variable == OPT_MIN_CONNECTION_DELAY) ? "min" : "max");
770767
}
771768
break;
772769
}
773770
default:
774771
/* Should never reach here. */
775772
DBUG_ASSERT(FALSE);
776-
error_handler->handle_error("Unexpected option type for connection delay.");
773+
error_handler->handle_error(ER_CONN_CONTROL_INVALID_CONN_DELAY_TYPE);
777774
};
778775
DBUG_RETURN(error);
779776
}
@@ -942,7 +939,7 @@ namespace connection_control
942939
&connection_event_delay_lock);
943940
if (!g_max_failed_connection_handler)
944941
{
945-
error_handler->handle_error("Failed to initialization Connection_delay_action");
942+
error_handler->handle_error(ER_CONN_CONTROL_DELAY_ACTION_INIT_FAILED);
946943
return true;
947944
}
948945
g_max_failed_connection_handler->init(coordinator);

plugin/connection_control/connection_delay_api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,

plugin/keyring/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0,
@@ -77,6 +77,8 @@ ELSE()
7777
MODULE_OUTPUT_NAME "keyring_file")
7878
ENDIF()
7979

80+
ADD_DEFINITIONS(-DLOG_SUBSYSTEM_TAG="keyring_file")
81+
8082
IF(SSL_DEFINES)
8183
ADD_DEFINITIONS(${SSL_DEFINES})
8284
ENDIF()

plugin/keyring/buffered_file_io.cc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -30,6 +30,7 @@
3030

3131
#include "my_compiler.h"
3232
#include "my_dbug.h"
33+
#include "mysqld_error.h"
3334

3435
namespace keyring {
3536

@@ -105,7 +106,7 @@ bool Buffered_file_io::check_file_structure(File file, size_t file_size)
105106
return checker->check_file_structure(file, file_size, &digest) == FALSE;
106107
}) == checkers.end())
107108
{
108-
logger->log(MY_ERROR_LEVEL, "Incorrect Keyring file");
109+
logger->log(ERROR_LEVEL, ER_KEYRING_INCORRECT_FILE);
109110
return TRUE;
110111
}
111112
return FALSE;
@@ -155,8 +156,7 @@ bool Buffered_file_io::recreate_keyring_from_backup_if_backup_exists()
155156
return FALSE; //no backup file to recover from
156157
if (load_file_into_buffer(backup_file, &buffer))
157158
{
158-
logger->log(MY_WARNING_LEVEL, "Found malformed keyring backup file - "
159-
"removing it");
159+
logger->log(WARNING_LEVEL, ER_KEYRING_FOUND_MALFORMED_BACKUP_FILE);
160160
file_io.close(backup_file, MYF(0));
161161
// if backup file was successfully removed then we have one keyring file
162162
return remove_backup(MYF(MY_WME));
@@ -171,8 +171,7 @@ bool Buffered_file_io::recreate_keyring_from_backup_if_backup_exists()
171171
file_io.close(keyring_file, MYF(MY_WME)) < 0)
172172

173173
{
174-
logger->log(MY_ERROR_LEVEL, "Error while restoring keyring from backup file"
175-
" cannot overwrite keyring with backup");
174+
logger->log(ERROR_LEVEL, ER_KEYRING_FAILED_TO_RESTORE_FROM_BACKUP_FILE);
176175
return TRUE;
177176
}
178177
return remove_backup(MYF(MY_WME));
@@ -222,8 +221,7 @@ bool Buffered_file_io::flush_buffer_to_file(Buffer *buffer,
222221
SHA256_DIGEST_LENGTH, MYF(0)) == SHA256_DIGEST_LENGTH)
223222
return FALSE;
224223

225-
logger->log(MY_ERROR_LEVEL, "Error while flushing in-memory keyring into "
226-
"keyring file");
224+
logger->log(ERROR_LEVEL, ER_KEYRING_FAILED_TO_FLUSH_KEYRING_TO_FILE);
227225
return TRUE;
228226
}
229227

0 commit comments

Comments
 (0)