mirror of
https://github.com/MariaDB/server.git
synced 2025-01-15 19:42:28 +01:00
MDEV-15 Log all sql errors.
modified for MySQL 5.5. Logger service moved to the plugin/sql_errlog directory to be properly used later. plugin/sql_errlog/sql_errlog.c: Fixes for bugs #956427 (SQL_ERROR_LOG plugin produces bogus warnings about sql-error-log-size-limit value) and #956463 (Server crashes if SQL_ERROR_LOG fails to initialize) they're also MDEV-184 and MDEV-183 The sql_error_log_deinit() should be prepared for the logger_file to be NULL. The logger_file_size_limit upper limit wasn't properly set.
This commit is contained in:
parent
619f67b1b4
commit
5c01f1ac14
15 changed files with 45 additions and 79 deletions
|
@ -80,24 +80,6 @@ void thd_progress_next_stage(void* thd);
|
|||
void thd_progress_end(void* thd);
|
||||
const char *set_thd_proc_info(void*, const char * info, const char *func,
|
||||
const char *file, unsigned int line);
|
||||
#include <mysql/service_logger.h>
|
||||
typedef struct logger_handle_st LOGGER_HANDLE;
|
||||
extern struct logger_service_st {
|
||||
LOGGER_HANDLE* (*open)(const char *path,
|
||||
unsigned long long size_limit,
|
||||
unsigned int rotations);
|
||||
int (*close)(LOGGER_HANDLE *log);
|
||||
int (*vprintf)(LOGGER_HANDLE *log, const char *fmt, va_list argptr);
|
||||
int (*printf)(LOGGER_HANDLE *log, const char *fmt, ...);
|
||||
int (*rotate)(LOGGER_HANDLE *log);
|
||||
} *logger_service;
|
||||
LOGGER_HANDLE *logger_open(const char *path,
|
||||
unsigned long long size_limit,
|
||||
unsigned int rotations);
|
||||
int logger_close(LOGGER_HANDLE *log);
|
||||
int logger_vprintf(LOGGER_HANDLE *log, const char *fmt, va_list argptr);
|
||||
int logger_rotate(LOGGER_HANDLE *log);
|
||||
int logger_printf(LOGGER_HANDLE *log, const char *fmt, ...);
|
||||
struct st_mysql_xid {
|
||||
long formatID;
|
||||
long gtrid_length;
|
||||
|
|
|
@ -80,24 +80,6 @@ void thd_progress_next_stage(void* thd);
|
|||
void thd_progress_end(void* thd);
|
||||
const char *set_thd_proc_info(void*, const char * info, const char *func,
|
||||
const char *file, unsigned int line);
|
||||
#include <mysql/service_logger.h>
|
||||
typedef struct logger_handle_st LOGGER_HANDLE;
|
||||
extern struct logger_service_st {
|
||||
LOGGER_HANDLE* (*open)(const char *path,
|
||||
unsigned long long size_limit,
|
||||
unsigned int rotations);
|
||||
int (*close)(LOGGER_HANDLE *log);
|
||||
int (*vprintf)(LOGGER_HANDLE *log, const char *fmt, va_list argptr);
|
||||
int (*printf)(LOGGER_HANDLE *log, const char *fmt, ...);
|
||||
int (*rotate)(LOGGER_HANDLE *log);
|
||||
} *logger_service;
|
||||
LOGGER_HANDLE *logger_open(const char *path,
|
||||
unsigned long long size_limit,
|
||||
unsigned int rotations);
|
||||
int logger_close(LOGGER_HANDLE *log);
|
||||
int logger_vprintf(LOGGER_HANDLE *log, const char *fmt, va_list argptr);
|
||||
int logger_rotate(LOGGER_HANDLE *log);
|
||||
int logger_printf(LOGGER_HANDLE *log, const char *fmt, ...);
|
||||
struct st_mysql_xid {
|
||||
long formatID;
|
||||
long gtrid_length;
|
||||
|
|
|
@ -80,24 +80,6 @@ void thd_progress_next_stage(void* thd);
|
|||
void thd_progress_end(void* thd);
|
||||
const char *set_thd_proc_info(void*, const char * info, const char *func,
|
||||
const char *file, unsigned int line);
|
||||
#include <mysql/service_logger.h>
|
||||
typedef struct logger_handle_st LOGGER_HANDLE;
|
||||
extern struct logger_service_st {
|
||||
LOGGER_HANDLE* (*open)(const char *path,
|
||||
unsigned long long size_limit,
|
||||
unsigned int rotations);
|
||||
int (*close)(LOGGER_HANDLE *log);
|
||||
int (*vprintf)(LOGGER_HANDLE *log, const char *fmt, va_list argptr);
|
||||
int (*printf)(LOGGER_HANDLE *log, const char *fmt, ...);
|
||||
int (*rotate)(LOGGER_HANDLE *log);
|
||||
} *logger_service;
|
||||
LOGGER_HANDLE *logger_open(const char *path,
|
||||
unsigned long long size_limit,
|
||||
unsigned int rotations);
|
||||
int logger_close(LOGGER_HANDLE *log);
|
||||
int logger_vprintf(LOGGER_HANDLE *log, const char *fmt, va_list argptr);
|
||||
int logger_rotate(LOGGER_HANDLE *log);
|
||||
int logger_printf(LOGGER_HANDLE *log, const char *fmt, ...);
|
||||
struct st_mysql_xid {
|
||||
long formatID;
|
||||
long gtrid_length;
|
||||
|
|
|
@ -23,7 +23,6 @@ extern "C" {
|
|||
#include <mysql/service_thd_wait.h>
|
||||
#include <mysql/service_thread_scheduler.h>
|
||||
#include <mysql/service_progress_report.h>
|
||||
#include <mysql/service_logger.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -24,4 +24,3 @@
|
|||
#define VERSION_thd_wait 0x0100
|
||||
#define VERSION_my_thread_scheduler 0x0100
|
||||
#define VERSION_progress_report 0x0100
|
||||
#define VERSION_logger 0x0100
|
||||
|
|
|
@ -95,7 +95,6 @@ SET(SQL_EMBEDDED_SOURCES emb_qcache.cc libmysqld.c lib_sql.cc
|
|||
../sql/create_options.cc ../sql/rpl_utility.cc
|
||||
../sql/rpl_reporting.cc
|
||||
../sql/sql_expression_cache.cc
|
||||
../sql/sql_logger.cc
|
||||
${GEN_SOURCES}
|
||||
${MYSYS_LIBWRAP_SOURCE}
|
||||
)
|
||||
|
|
|
@ -20,8 +20,7 @@ SET(MYSQLSERVICES_SOURCES
|
|||
thd_alloc_service.c
|
||||
thd_wait_service.c
|
||||
my_thread_scheduler_service.c
|
||||
progress_report_service.c
|
||||
logger_service.c)
|
||||
progress_report_service.c)
|
||||
|
||||
ADD_CONVENIENCE_LIBRARY(mysqlservices ${MYSQLSERVICES_SOURCES})
|
||||
INSTALL(TARGETS mysqlservices DESTINATION ${INSTALL_LIBDIR} COMPONENT Development)
|
||||
|
|
|
@ -13,4 +13,4 @@
|
|||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
MYSQL_ADD_PLUGIN(sql_errlog sql_errlog.c MODULE_ONLY)
|
||||
MYSQL_ADD_PLUGIN(sql_errlog sql_errlog.c sql_logger.cc service_logger.h MODULE_ONLY)
|
||||
|
|
|
@ -16,5 +16,6 @@
|
|||
#include <service_versions.h>
|
||||
|
||||
|
||||
/* file reserved for the future use */
|
||||
SERVICE_VERSION *logger_service= (void *) VERSION_logger;
|
||||
|
|
@ -69,7 +69,7 @@ extern struct logger_service_st {
|
|||
int (*rotate)(LOGGER_HANDLE *log);
|
||||
} *logger_service;
|
||||
|
||||
#ifdef MYSQL_DYNAMIC_PLUGIN
|
||||
#if 0 /*MYSQL_DYNAMIC_PLUGIN*/
|
||||
|
||||
#define logger_open(path, size_limit, rotations) \
|
||||
(logger_service->open(path, size_limit, rotations))
|
||||
|
@ -87,6 +87,8 @@ extern struct logger_service_st {
|
|||
int logger_vprintf(LOGGER_HANDLE *log, const char *fmt, va_list argptr);
|
||||
int logger_rotate(LOGGER_HANDLE *log);
|
||||
int logger_printf(LOGGER_HANDLE *log, const char *fmt, ...);
|
||||
|
||||
void init_logger_mutexes();
|
||||
#endif
|
||||
|
||||
|
|
@ -16,6 +16,7 @@
|
|||
#include <mysql/plugin_audit.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include "service_logger.h"
|
||||
|
||||
/*
|
||||
Disable __attribute__() on non-gcc compilers.
|
||||
|
@ -32,6 +33,7 @@
|
|||
rate 0 means the logging was disabled.
|
||||
*/
|
||||
|
||||
|
||||
static char *filename;
|
||||
static unsigned int rate;
|
||||
static unsigned long long size_limit;
|
||||
|
@ -50,7 +52,7 @@ static MYSQL_SYSVAR_UINT(rate, rate, PLUGIN_VAR_RQCMDARG,
|
|||
|
||||
static MYSQL_SYSVAR_ULONGLONG(size_limit, size_limit,
|
||||
PLUGIN_VAR_READONLY, "Log file size limit", NULL, NULL,
|
||||
1000000, 100, 0, 1);
|
||||
1000000, 100, ((long long) 0x7FFFFFFFFFFFFFFFLL), 1);
|
||||
|
||||
static MYSQL_SYSVAR_UINT(rotations, rotations,
|
||||
PLUGIN_VAR_READONLY, "Number of rotations before log is removed.",
|
||||
|
@ -104,6 +106,8 @@ static void log_sql_errors(MYSQL_THD thd __attribute__((unused)),
|
|||
|
||||
static int sql_error_log_init(void *p __attribute__((unused)))
|
||||
{
|
||||
init_logger_mutexes();
|
||||
|
||||
logfile= logger_open(filename, size_limit, rotations);
|
||||
if (logfile == NULL) {
|
||||
fprintf(stderr, "Could not create file '%s'\n",
|
||||
|
@ -117,7 +121,8 @@ static int sql_error_log_init(void *p __attribute__((unused)))
|
|||
|
||||
static int sql_error_log_deinit(void *p __attribute__((unused)))
|
||||
{
|
||||
logger_close(logfile);
|
||||
if (logfile)
|
||||
logger_close(logfile);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -139,6 +144,24 @@ static struct st_mysql_audit descriptor =
|
|||
{ MYSQL_AUDIT_GENERAL_CLASSMASK }
|
||||
};
|
||||
|
||||
mysql_declare_plugin(sql_errlog)
|
||||
{
|
||||
MYSQL_AUDIT_PLUGIN,
|
||||
&descriptor,
|
||||
"SQL_ERROR_LOG",
|
||||
"Alexey Botchkov",
|
||||
"Log SQL level errors to a file with rotation",
|
||||
PLUGIN_LICENSE_GPL,
|
||||
sql_error_log_init,
|
||||
sql_error_log_deinit,
|
||||
0x0100,
|
||||
NULL,
|
||||
vars,
|
||||
NULL,
|
||||
0
|
||||
}
|
||||
mysql_declare_plugin_end;
|
||||
|
||||
maria_declare_plugin(sql_errlog)
|
||||
{
|
||||
MYSQL_AUDIT_PLUGIN,
|
||||
|
|
|
@ -16,10 +16,15 @@
|
|||
|
||||
#include "my_global.h"
|
||||
#include <my_sys.h>
|
||||
#include <mysql/service_logger.h>
|
||||
#include "service_logger.h"
|
||||
#include <my_pthread.h>
|
||||
|
||||
extern char *mysql_data_home;
|
||||
extern PSI_mutex_key key_LOCK_logger_service;
|
||||
extern MYSQL_PLUGIN_IMPORT char *mysql_data_home;
|
||||
|
||||
/* These belong to the service initialization */
|
||||
static PSI_mutex_key key_LOCK_logger_service;
|
||||
static PSI_mutex_info mutex_list[]=
|
||||
{{ &key_LOCK_logger_service, "logger_service_file_st::lock", PSI_FLAG_GLOBAL}};
|
||||
|
||||
typedef struct logger_handle_st {
|
||||
File file;
|
||||
|
@ -181,3 +186,9 @@ int logger_printf(LOGGER_HANDLE *log, const char *fmt, ...)
|
|||
return result;
|
||||
}
|
||||
|
||||
void init_logger_mutexes()
|
||||
{
|
||||
if (PSI_server)
|
||||
PSI_server->register_mutex("sql_logger", mutex_list, 1);
|
||||
}
|
||||
|
|
@ -85,7 +85,6 @@ SET (SQL_SOURCE
|
|||
gcalc_slicescan.cc gcalc_tools.cc
|
||||
threadpool_common.cc
|
||||
../sql-common/mysql_async.c
|
||||
sql_logger.cc
|
||||
${GEN_SOURCES}
|
||||
${MYSYS_LIBWRAP_SOURCE}
|
||||
)
|
||||
|
|
|
@ -748,7 +748,6 @@ PSI_mutex_key key_LOCK_stats,
|
|||
key_LOCK_wakeup_ready;
|
||||
|
||||
PSI_mutex_key key_LOCK_prepare_ordered, key_LOCK_commit_ordered;
|
||||
PSI_mutex_key key_LOCK_logger_service;
|
||||
|
||||
static PSI_mutex_info all_server_mutexes[]=
|
||||
{
|
||||
|
@ -808,8 +807,6 @@ static PSI_mutex_info all_server_mutexes[]=
|
|||
{ &key_LOCK_commit_ordered, "LOCK_commit_ordered", PSI_FLAG_GLOBAL},
|
||||
{ &key_LOG_INFO_lock, "LOG_INFO::lock", 0},
|
||||
{ &key_LOCK_thread_count, "LOCK_thread_count", PSI_FLAG_GLOBAL},
|
||||
{ &key_LOCK_logger_service, "logger_service_file_st::lock",
|
||||
PSI_FLAG_GLOBAL},
|
||||
{ &key_PARTITION_LOCK_auto_inc, "HA_DATA_PARTITION::LOCK_auto_inc", 0}
|
||||
};
|
||||
|
||||
|
|
|
@ -54,14 +54,6 @@ static struct progress_report_service_st progress_report_handler= {
|
|||
set_thd_proc_info
|
||||
};
|
||||
|
||||
static struct logger_service_st logger_handler= {
|
||||
logger_open,
|
||||
logger_close,
|
||||
logger_vprintf,
|
||||
logger_printf,
|
||||
logger_rotate
|
||||
};
|
||||
|
||||
static struct st_service_ref list_of_services[]=
|
||||
{
|
||||
{ "my_snprintf_service", VERSION_my_snprintf, &my_snprintf_handler },
|
||||
|
@ -69,6 +61,5 @@ static struct st_service_ref list_of_services[]=
|
|||
{ "thd_wait_service", VERSION_thd_wait, &thd_wait_handler },
|
||||
{ "my_thread_scheduler_service", VERSION_my_thread_scheduler, &my_thread_scheduler_handler },
|
||||
{ "progress_report_service", VERSION_progress_report, &progress_report_handler },
|
||||
{ "logger_service", VERSION_logger, &logger_handler },
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue