Skip to content

Commit b698181

Browse files
committed
Merge branch 'mysql-8.0' into mysql-trunk
2 parents 993489e + 7878ee8 commit b698181

34 files changed

+1066
-268
lines changed

include/mysql/components/services/log_builtins.h

Lines changed: 164 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,17 @@
2828
#include <mysql/components/my_service.h>
2929
#include <mysql/components/service_implementation.h>
3030
#include <mysql/components/services/log_shared.h>
31+
#if defined(MYSQL_DYNAMIC_PLUGIN)
32+
#include <mysql/service_plugin_registry.h>
33+
#endif
3134
#include <stdarg.h>
35+
#include <stdio.h>
3236

33-
#include "my_compiler.h"
34-
#ifdef MYSQL_SERVER
37+
#include <my_compiler.h>
38+
#if defined(MYSQL_SERVER) && !defined(MYSQL_DYNAMIC_PLUGIN)
3539
#include "sql/log.h"
3640
#endif
3741

38-
3942
/**
4043
Primitives for services to interact with the structured logger:
4144
functions pertaining to log_line and log_item data
@@ -651,9 +654,9 @@ BEGIN_SERVICE_DEFINITION(log_builtins_syseventlog)
651654
END_SERVICE_DEFINITION(log_builtins_syseventlog)
652655

653656

654-
# ifdef __cplusplus
657+
#ifdef __cplusplus
655658

656-
# if !defined(LOG_H)
659+
#if !defined(LOG_H)
657660

658661
extern SERVICE_TYPE(log_builtins) *log_bi;
659662
extern SERVICE_TYPE(log_builtins_string) *log_bs;
@@ -686,7 +689,9 @@ extern SERVICE_TYPE(log_builtins_string) *log_bs;
686689
# define log_set_float log_item_set_float
687690
# define log_set_lexstring log_item_set_lexstring
688691
# define log_set_cstring log_item_set_cstring
689-
# endif
692+
#endif // LOG_H
693+
694+
#ifndef DISABLE_ERROR_LOGGING
690695

691696
#define LogErr(severity, ecode, ...) LogEvent().prio(severity)\
692697
.errcode(ecode)\
@@ -696,7 +701,43 @@ extern SERVICE_TYPE(log_builtins_string) *log_bs;
696701
.function(__FUNCTION__)\
697702
.lookup(ecode, ## __VA_ARGS__)
698703

704+
#define LogPluginErr(severity, ecode, ...) \
705+
LogEvent().prio(severity)\
706+
.errcode(ecode)\
707+
.subsys(LOG_SUBSYSTEM_TAG)\
708+
.source_line(__LINE__)\
709+
.source_file(MY_BASENAME)\
710+
.function(__FUNCTION__)\
711+
.lookup_quoted(ecode, "Plugin " LOG_SUBSYSTEM_TAG " reported",\
712+
## __VA_ARGS__)
713+
714+
#define LogPluginErrMsg(severity, ecode, ...) \
715+
LogEvent().prio(severity)\
716+
.errcode(ecode)\
717+
.subsys(LOG_SUBSYSTEM_TAG)\
718+
.source_line(__LINE__)\
719+
.source_file(MY_BASENAME)\
720+
.function(__FUNCTION__)\
721+
.message_quoted("Plugin " LOG_SUBSYSTEM_TAG " reported",\
722+
## __VA_ARGS__)
723+
724+
#else
725+
726+
inline void dummy_log_message(longlong severity MY_ATTRIBUTE((unused)),
727+
longlong ecode MY_ATTRIBUTE((unused)),
728+
...)
729+
{
730+
return;
731+
}
732+
733+
#define LogErr(severity, ecode, ...) \
734+
dummy_log_message(severity, ecode, ## __VA_ARGS__)
735+
#define LogPluginErr(severity, ecode, ...) \
736+
dummy_log_message(severity, ecode, ## __VA_ARGS__)
737+
#define LogPluginErrMsg(severity, ecode, ...) \
738+
dummy_log_message(severity, ecode, ## __VA_ARGS__)
699739

740+
#endif // DISABLE_ERROR_LOGGING
700741

701742
/**
702743
Modular logger: fluid API. Server-internal. Lets you use safe and
@@ -710,6 +751,7 @@ class LogEvent
710751
private:
711752
log_line *ll;
712753
char *msg;
754+
const char *msg_tag;
713755

714756
/**
715757
Set MySQL error-code if none has been set yet.
@@ -788,6 +830,7 @@ class LogEvent
788830
}
789831
else
790832
msg= nullptr;
833+
msg_tag= nullptr;
791834
}
792835

793836
/**
@@ -798,7 +841,7 @@ class LogEvent
798841
799842
@retval the LogEvent, for easy fluent-style chaining.
800843
*/
801-
LogEvent &type(log_type val)
844+
LogEvent &type(enum_log_type val)
802845
{
803846
log_set_int(log_line_item_set(this->ll, LOG_ITEM_LOG_TYPE), val);
804847
return *this;
@@ -1111,6 +1154,30 @@ class LogEvent
11111154
LogEvent &message(const char *fmt, ...)
11121155
MY_ATTRIBUTE((format(printf, 2, 3)));
11131156

1157+
/**
1158+
Fill in a format string by substituting the % with the given
1159+
arguments and tag, then add the result as the event's message.
1160+
1161+
@param tag Tag to prefix to message.
1162+
@param fmt message (treated as a printf-style format-string,
1163+
so % substitution will happen)
1164+
@param ... varargs to satisfy any % in the message
1165+
1166+
@retval the LogEvent, for easy fluent-style chaining.
1167+
*/
1168+
LogEvent &message_quoted(const char *tag, const char *fmt, ...)
1169+
MY_ATTRIBUTE((format(printf, 3, 4)))
1170+
{
1171+
msg_tag= tag;
1172+
1173+
va_list args;
1174+
va_start(args, fmt);
1175+
set_message(fmt, args);
1176+
va_end(args);
1177+
1178+
return *this;
1179+
}
1180+
11141181
/**
11151182
Find an error message by its MySQL error code.
11161183
Substitute the % in that message with the given
@@ -1132,6 +1199,18 @@ class LogEvent
11321199
return *this;
11331200
}
11341201

1202+
LogEvent &lookup_quoted(longlong errcode, const char *tag, ...)
1203+
{
1204+
msg_tag= tag;
1205+
1206+
va_list args;
1207+
va_start(args, tag);
1208+
set_message_by_errcode(errcode, args);
1209+
va_end(args);
1210+
1211+
return *this;
1212+
}
1213+
11351214
/**
11361215
Add a ad hoc integer value with the given key.
11371216
@@ -1217,6 +1296,12 @@ inline void LogEvent::set_message(const char *fmt, va_list ap)
12171296
{
12181297
if ((ll != nullptr) && (msg != nullptr))
12191298
{
1299+
char buf[LOG_BUFF_MAX];
1300+
if (msg_tag != nullptr)
1301+
{
1302+
snprintf(buf, LOG_BUFF_MAX - 1, "%s: \'%s\'", msg_tag, fmt);
1303+
fmt= buf;
1304+
}
12201305
size_t len= log_msg(msg, LOG_BUFF_MAX - 1, fmt, ap);
12211306
log_set_lexstring(log_line_item_set(this->ll, LOG_ITEM_LOG_MESSAGE),
12221307
msg, len);
@@ -1233,6 +1318,77 @@ inline LogEvent &LogEvent::message(const char *fmt, ...)
12331318
return *this;
12341319
}
12351320

1236-
# endif
1321+
// Methods initialize and de-initialize logging service for plugins.
1322+
#if defined(MYSQL_DYNAMIC_PLUGIN)
1323+
1324+
/**
1325+
Method to de-initialize logging service in plugin.
1326+
1327+
param[in] reg_srv Pluin registry service.
1328+
*/
1329+
inline void deinit_logging_service_for_plugin(SERVICE_TYPE(registry) **reg_srv)
1330+
{
1331+
if (log_bi)
1332+
(*reg_srv)->release((my_h_service)log_bi);
1333+
if (log_bs)
1334+
(*reg_srv)->release((my_h_service)log_bs);
1335+
mysql_plugin_registry_release(*reg_srv);
1336+
log_bi= nullptr;
1337+
log_bs= nullptr;
1338+
*reg_srv= nullptr;
1339+
}
1340+
1341+
/**
1342+
Method to de-initialize logging service in plugin.
1343+
1344+
param[out] reg_srv Pluin registry service.
1345+
1346+
@retval false Success.
1347+
@retval true Failed.
1348+
*/
1349+
inline bool init_logging_service_for_plugin(SERVICE_TYPE(registry) **reg_srv)
1350+
{
1351+
my_h_service log_srv= nullptr;
1352+
my_h_service log_str_srv= nullptr;
1353+
*reg_srv= mysql_plugin_registry_acquire();
1354+
if (!(*reg_srv)->acquire("log_builtins.mysql_server", &log_srv) &&
1355+
!(*reg_srv)->acquire("log_builtins_string.mysql_server", &log_str_srv))
1356+
{
1357+
log_bi= reinterpret_cast<SERVICE_TYPE(log_builtins) *>(log_srv);
1358+
log_bs= reinterpret_cast<SERVICE_TYPE(log_builtins_string) *>(log_str_srv);
1359+
}
1360+
else
1361+
{
1362+
deinit_logging_service_for_plugin(reg_srv);
1363+
return true;
1364+
}
1365+
return false;
1366+
}
1367+
1368+
#elif defined(EXTRA_CODE_FOR_UNIT_TESTING)
1369+
1370+
/**
1371+
Method is used by unit tests.
1372+
1373+
param[in] reg_srv Pluin registry service.
1374+
*/
1375+
inline bool init_logging_service_for_plugin(
1376+
SERVICE_TYPE(registry) **reg_srv MY_ATTRIBUTE((unused)))
1377+
{
1378+
return false;
1379+
}
1380+
1381+
/**
1382+
Method is used by unit tests.
1383+
1384+
param[in] reg_srv Pluin registry service.
1385+
*/
1386+
inline void deinit_logging_service_for_plugin(
1387+
SERVICE_TYPE(registry) **reg_srv MY_ATTRIBUTE((unused)))
1388+
{ }
1389+
1390+
#endif // MYSQL_DYNAMIC_PLUGIN
1391+
1392+
#endif // __cplusplus
12371393

12381394
#endif

include/mysql/components/services/log_shared.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ typedef struct MYSQL_LEX_CSTRING LEX_CSTRING;
6868
log_type -- which log to send data to
6969
check vs enum_log_table_type and LOG_FILE/LOG_TABLE/LOG_NONE
7070
*/
71-
typedef enum enum_log_type
71+
enum enum_log_type
7272
{
7373
LOG_TYPE_UNDEF = 0,
7474
LOG_TYPE_ERROR = 1,
7575
LOG_TYPE_GENERAL = 2,
7676
LOG_TYPE_SLOW = 4,
7777
LOG_TYPE_AUDIT = 8,
7878
LOG_TYPE_MISC = 16
79-
} log_type;
79+
};
8080

8181
/**
8282
item_type -- what to log

include/mysql/thread_pool_priv.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@
3737
#include "sql/conn_handler/connection_handler_manager.h"
3838
#include "sql/debug_sync.h"
3939
#include "sql/field.h"
40-
/*
41-
Print to the MySQL error log -- ultimately, this should possibly
42-
become a service calling another service.
43-
*/
44-
#include "sql/log.h"
4540
#include "sql/sql_profile.h"
4641
#include "sql/sql_thd_internal_api.h"
4742
#include "sql/table.h"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ SELECT search_error_log( '[Note]', '%Plugin Rewriter reported: ''Statement "SELE
5656
'WHERE a = "digest_collision.test"%' );
5757
search_error_log( '[Note]', '%Plugin Rewriter reported: ''Statement "SELECT * FROM test.t1 ' ||
5858
'WHERE a = "digest_collision.test"%' )
59-
[Note] [MY-000000] Plugin Rewriter reported: 'Statement "SELECT * FROM test.t1 WHERE a = "digest_collision.test" UNION SELECT * FROM test.t1 WHERE a = "diges..." with digest "3c579229047547d5b35dbb0f1f00f0d1ff521755e231f83952e6d51b2019818b" matched some rule but had different parse tree and/or literals.'
59+
[Note] [MY-004920] Plugin Rewriter reported: 'Statement "SELECT * FROM test.t1 WHERE a = "digest_collision.test" UNION SELECT * FROM test.t1 WHERE a = "diges..." with digest "3c579229047547d5b35dbb0f1f00f0d1ff521755e231f83952e6d51b2019818b" matched some rule but had different parse tree and/or literals.'
6060
DROP TABLE t1;
6161
Warnings:
6262
Warning 1620 Plugin is busy and will be uninstalled on shutdown

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-000000] Plugin Rewriter reported: 'Wrong column count or names when loading rules.'
50+
[ERROR] [MY-004920] 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-000000] Plugin Rewriter reported: 'Wrong column count or names when loading rules.'
73+
[ERROR] [MY-004920] 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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ SELECT search_error_log( '[Note]', "%Plugin Rewriter reported: " ||
3939
"'Statement \"SELECT 'nonrewritten'\"%" ) INTO @line;
4040
SELECT @line;
4141
@line
42-
[Note] [MY-000000] Plugin Rewriter reported: 'Statement "SELECT 'nonrewritten'" with digest "d1b44b0c19af710b5a679907e284acd2ddc285201794bc69a2389d77baedddae" did not match any rule.'
42+
[Note] [MY-004920] Plugin Rewriter reported: 'Statement "SELECT 'nonrewritten'" with digest "d1b44b0c19af710b5a679907e284acd2ddc285201794bc69a2389d77baedddae" did not match any rule.'
4343
SELECT digest INTO @pfs_digest
4444
FROM performance_schema.events_statements_history_long
4545
WHERE sql_text = "SELECT 'nonrewritten'"

plugin/connection_control/connection_control.cc

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
along with this program; if not, write to the Free Software
1414
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
1515

16+
#define LOG_SUBSYSTEM_TAG "CONNECTION_CONTROL"
17+
1618
#include "plugin/connection_control/connection_control.h"
1719

1820
#include <mysql/plugin_audit.h> /* mysql_event_connection */
@@ -22,9 +24,15 @@
2224
#include "my_dbug.h"
2325
#include "my_inttypes.h"
2426
#include "mysql_version.h"
27+
#include "mysqld_error.h"
28+
#include <mysql/components/services/log_builtins.h>
2529
#include "plugin/connection_control/connection_control_coordinator.h" /* g_connection_event_coordinator */
2630
#include "plugin/connection_control/connection_delay_api.h" /* connection_delay apis */
2731

32+
static SERVICE_TYPE(registry) *reg_srv= nullptr;
33+
SERVICE_TYPE(log_builtins) *log_bi= nullptr;
34+
SERVICE_TYPE(log_builtins_string) *log_bs= nullptr;
35+
2836
namespace connection_control
2937
{
3038
class Connection_control_error_handler : public Error_handler
@@ -36,9 +44,7 @@ namespace connection_control
3644

3745
void handle_error(const char * error_message)
3846
{
39-
my_plugin_log_message(&m_plugin_info,
40-
MY_ERROR_LEVEL,
41-
"%s", error_message);
47+
LogPluginErr(ERROR_LEVEL, ER_CONN_CONTROL_ERROR_MSG, error_message);
4248
}
4349
private:
4450
MYSQL_PLUGIN m_plugin_info;
@@ -111,12 +117,17 @@ connection_control_notify(MYSQL_THD thd,
111117
static int
112118
connection_control_init(MYSQL_PLUGIN plugin_info)
113119
{
120+
// Initialize error logging service.
121+
if (init_logging_service_for_plugin(&reg_srv))
122+
return 1;
123+
114124
connection_control_plugin_info= plugin_info;
115125
Connection_control_error_handler error_handler(connection_control_plugin_info);
116126
g_connection_event_coordinator= new Connection_event_coordinator();
117127
if (!g_connection_event_coordinator)
118128
{
119129
error_handler.handle_error("Failed to initialize Connection_event_coordinator");
130+
deinit_logging_service_for_plugin(&reg_srv);
120131
return 1;
121132
}
122133

@@ -125,8 +136,10 @@ connection_control_init(MYSQL_PLUGIN plugin_info)
125136
&error_handler))
126137
{
127138
delete g_connection_event_coordinator;
139+
deinit_logging_service_for_plugin(&reg_srv);
128140
return 1;
129141
}
142+
130143
return 0;
131144
}
132145

@@ -146,6 +159,8 @@ connection_control_deinit(void *arg MY_ATTRIBUTE((unused)))
146159
g_connection_event_coordinator= 0;
147160
connection_control::deinit_connection_delay_event();
148161
connection_control_plugin_info= 0;
162+
163+
deinit_logging_service_for_plugin(&reg_srv);
149164
return 0;
150165
}
151166

0 commit comments

Comments
 (0)