summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Botchkov <holyfoot@askmonty.org>2012-03-24 11:24:20 +0100
committerAlexey Botchkov <holyfoot@askmonty.org>2012-03-24 11:24:20 +0100
commit5c01f1ac1498a9b32bdccb817cdbc0b3ca3687d6 (patch)
treefe8eb54f1eaff9a41fe617b35356f5bd3e35746b
parent619f67b1b4694add244377a0cb2507a035ebd306 (diff)
downloadmariadb-git-5c01f1ac1498a9b32bdccb817cdbc0b3ca3687d6.tar.gz
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.
-rw-r--r--include/mysql/plugin_audit.h.pp18
-rw-r--r--include/mysql/plugin_auth.h.pp18
-rw-r--r--include/mysql/plugin_ftparser.h.pp18
-rw-r--r--include/mysql/services.h1
-rw-r--r--include/service_versions.h1
-rw-r--r--libmysqld/CMakeLists.txt1
-rw-r--r--libservices/CMakeLists.txt3
-rw-r--r--plugin/sql_errlog/CMakeLists.txt2
-rw-r--r--plugin/sql_errlog/logger_service.c (renamed from libservices/logger_service.c)1
-rw-r--r--plugin/sql_errlog/service_logger.h (renamed from include/mysql/service_logger.h)4
-rw-r--r--plugin/sql_errlog/sql_errlog.c27
-rw-r--r--plugin/sql_errlog/sql_logger.cc (renamed from sql/sql_logger.cc)17
-rw-r--r--sql/CMakeLists.txt1
-rw-r--r--sql/mysqld.cc3
-rw-r--r--sql/sql_plugin_services.h9
15 files changed, 45 insertions, 79 deletions
diff --git a/include/mysql/plugin_audit.h.pp b/include/mysql/plugin_audit.h.pp
index dd7dde7973c..cdd9324a5f7 100644
--- a/include/mysql/plugin_audit.h.pp
+++ b/include/mysql/plugin_audit.h.pp
@@ -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;
diff --git a/include/mysql/plugin_auth.h.pp b/include/mysql/plugin_auth.h.pp
index cf3b60d128b..e06494746dd 100644
--- a/include/mysql/plugin_auth.h.pp
+++ b/include/mysql/plugin_auth.h.pp
@@ -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;
diff --git a/include/mysql/plugin_ftparser.h.pp b/include/mysql/plugin_ftparser.h.pp
index 14129aec85e..a990c62e8e9 100644
--- a/include/mysql/plugin_ftparser.h.pp
+++ b/include/mysql/plugin_ftparser.h.pp
@@ -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;
diff --git a/include/mysql/services.h b/include/mysql/services.h
index 258f7b90658..dd0fa58db89 100644
--- a/include/mysql/services.h
+++ b/include/mysql/services.h
@@ -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
diff --git a/include/service_versions.h b/include/service_versions.h
index 8a397d71b12..ee50d4856e9 100644
--- a/include/service_versions.h
+++ b/include/service_versions.h
@@ -24,4 +24,3 @@
#define VERSION_thd_wait 0x0100
#define VERSION_my_thread_scheduler 0x0100
#define VERSION_progress_report 0x0100
-#define VERSION_logger 0x0100
diff --git a/libmysqld/CMakeLists.txt b/libmysqld/CMakeLists.txt
index 6603983e69b..14db8327897 100644
--- a/libmysqld/CMakeLists.txt
+++ b/libmysqld/CMakeLists.txt
@@ -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}
)
diff --git a/libservices/CMakeLists.txt b/libservices/CMakeLists.txt
index dd16558ef9c..ee6a7c73abe 100644
--- a/libservices/CMakeLists.txt
+++ b/libservices/CMakeLists.txt
@@ -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)
diff --git a/plugin/sql_errlog/CMakeLists.txt b/plugin/sql_errlog/CMakeLists.txt
index 18fb9f5421d..50c4b7d806d 100644
--- a/plugin/sql_errlog/CMakeLists.txt
+++ b/plugin/sql_errlog/CMakeLists.txt
@@ -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)
diff --git a/libservices/logger_service.c b/plugin/sql_errlog/logger_service.c
index 896b0714293..c45e978413c 100644
--- a/libservices/logger_service.c
+++ b/plugin/sql_errlog/logger_service.c
@@ -16,5 +16,6 @@
#include <service_versions.h>
+/* file reserved for the future use */
SERVICE_VERSION *logger_service= (void *) VERSION_logger;
diff --git a/include/mysql/service_logger.h b/plugin/sql_errlog/service_logger.h
index 47a478ef5b4..2aa4d94f010 100644
--- a/include/mysql/service_logger.h
+++ b/plugin/sql_errlog/service_logger.h
@@ -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
diff --git a/plugin/sql_errlog/sql_errlog.c b/plugin/sql_errlog/sql_errlog.c
index ee2765a7143..ce383916621 100644
--- a/plugin/sql_errlog/sql_errlog.c
+++ b/plugin/sql_errlog/sql_errlog.c
@@ -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,
diff --git a/sql/sql_logger.cc b/plugin/sql_errlog/sql_logger.cc
index fe3c9a87d20..8bf757f2fd7 100644
--- a/sql/sql_logger.cc
+++ b/plugin/sql_errlog/sql_logger.cc
@@ -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);
+}
+
diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt
index 22c51f3ce23..446db5d128a 100644
--- a/sql/CMakeLists.txt
+++ b/sql/CMakeLists.txt
@@ -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}
)
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 21653e96854..a73177f9fea 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -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}
};
diff --git a/sql/sql_plugin_services.h b/sql/sql_plugin_services.h
index bd6d136585a..e6302f6d345 100644
--- a/sql/sql_plugin_services.h
+++ b/sql/sql_plugin_services.h
@@ -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 },
};