diff options
author | Sergei Golubchik <sergii@pisem.net> | 2011-07-02 22:08:51 +0200 |
---|---|---|
committer | Sergei Golubchik <sergii@pisem.net> | 2011-07-02 22:08:51 +0200 |
commit | 9809f05199aeb0b67991fac41bd86f38730768dc (patch) | |
tree | fa2792ff86d0da014b535d743759810612338042 /include/mysql | |
parent | 0accbd0364e0333e0b119aa9ce93e34ded9df6cb (diff) | |
parent | 5a0e7394a5ae0c7b6a1ea35b7ea3a8985325987a (diff) | |
download | mariadb-git-9809f05199aeb0b67991fac41bd86f38730768dc.tar.gz |
5.5-merge
Diffstat (limited to 'include/mysql')
-rw-r--r-- | include/mysql/client_plugin.h | 30 | ||||
-rw-r--r-- | include/mysql/client_plugin.h.pp | 8 | ||||
-rw-r--r-- | include/mysql/innodb_priv.h | 1 | ||||
-rw-r--r-- | include/mysql/plugin_audit.h | 59 | ||||
-rw-r--r-- | include/mysql/plugin_audit.h.pp | 44 | ||||
-rw-r--r-- | include/mysql/plugin_auth.h | 47 | ||||
-rw-r--r-- | include/mysql/plugin_auth.h.pp | 53 | ||||
-rw-r--r-- | include/mysql/plugin_auth_common.h | 1 | ||||
-rw-r--r-- | include/mysql/plugin_ftparser.h.pp | 17 | ||||
-rw-r--r-- | include/mysql/psi/mysql_file.h | 2 | ||||
-rw-r--r-- | include/mysql/psi/mysql_thread.h | 88 | ||||
-rw-r--r-- | include/mysql/service_thd_wait.h | 30 | ||||
-rw-r--r-- | include/mysql/thread_pool_priv.h | 121 |
13 files changed, 333 insertions, 168 deletions
diff --git a/include/mysql/client_plugin.h b/include/mysql/client_plugin.h index 9c7b1aee9f9..6af0d226ea2 100644 --- a/include/mysql/client_plugin.h +++ b/include/mysql/client_plugin.h @@ -38,7 +38,7 @@ #define MYSQL_CLIENT_MAX_PLUGINS 3 #define mysql_declare_client_plugin(X) \ - struct st_mysql_client_plugin_ ## X \ + MYSQL_PLUGIN_EXPORT struct st_mysql_client_plugin_ ## X \ _mysql_client_plugin_declaration_ = { \ MYSQL_CLIENT_ ## X ## _PLUGIN, \ MYSQL_CLIENT_ ## X ## _PLUGIN_INTERFACE_VERSION, @@ -52,8 +52,11 @@ const char *author; \ const char *desc; \ unsigned int version[3]; \ + const char *license; \ + void *mysql_api; \ int (*init)(char *, size_t, int, va_list); \ - int (*deinit)(); + int (*deinit)(); \ + int (*options)(const char *option, const void *); struct st_mysql_client_plugin { @@ -94,8 +97,7 @@ typedef char *(*mysql_authentication_dialog_ask_t)(struct st_mysql *mysql, /** loads a plugin and initializes it - @param mysql MYSQL structure. only MYSQL_PLUGIN_DIR option value is used, - and last_errno/last_error, for error reporting + @param mysql MYSQL structure. @param name a name of the plugin to load @param type type of plugin that should be loaded, -1 to disable type check @param argc number of arguments to pass to the plugin initialization @@ -115,8 +117,7 @@ mysql_load_plugin(struct st_mysql *mysql, const char *name, int type, This is the same as mysql_load_plugin, but take va_list instead of a list of arguments. - @param mysql MYSQL structure. only MYSQL_PLUGIN_DIR option value is used, - and last_errno/last_error, for error reporting + @param mysql MYSQL structure. @param name a name of the plugin to load @param type type of plugin that should be loaded, -1 to disable type check @param argc number of arguments to pass to the plugin initialization @@ -133,8 +134,7 @@ mysql_load_plugin_v(struct st_mysql *mysql, const char *name, int type, /** finds an already loaded plugin by name, or loads it, if necessary - @param mysql MYSQL structure. only MYSQL_PLUGIN_DIR option value is used, - and last_errno/last_error, for error reporting + @param mysql MYSQL structure. @param name a name of the plugin to load @param type type of plugin that should be loaded @@ -162,5 +162,19 @@ struct st_mysql_client_plugin * mysql_client_register_plugin(struct st_mysql *mysql, struct st_mysql_client_plugin *plugin); +/** + set plugin options + + Can be used to set extra options and affect behavior for a plugin. + This function may be called multiple times to set several options + + @param plugin an st_mysql_client_plugin structure + @param option a string which specifies the option to set + @param value value for the option. + + @retval 0 on success, 1 in case of failure +**/ +int mysql_plugin_options(struct st_mysql_client_plugin *plugin, + const char *option, const void *value); #endif diff --git a/include/mysql/client_plugin.h.pp b/include/mysql/client_plugin.h.pp index ca477d83bb2..93eaff7501e 100644 --- a/include/mysql/client_plugin.h.pp +++ b/include/mysql/client_plugin.h.pp @@ -1,6 +1,6 @@ struct st_mysql_client_plugin { - int type; unsigned int interface_version; const char *name; const char *author; const char *desc; unsigned int version[3]; int (*init)(char *, size_t, int, va_list); int (*deinit)(); + int type; unsigned int interface_version; const char *name; const char *author; const char *desc; unsigned int version[3]; const char *license; void *mysql_api; int (*init)(char *, size_t, int, va_list); int (*deinit)(); int (*options)(const char *option, const void *); }; struct st_mysql; #include <mysql/plugin_auth_common.h> @@ -21,11 +21,9 @@ typedef struct st_plugin_vio } MYSQL_PLUGIN_VIO; struct st_mysql_client_plugin_AUTHENTICATION { - int type; unsigned int interface_version; const char *name; const char *author; const char *desc; unsigned int version[3]; int (*init)(char *, size_t, int, va_list); int (*deinit)(); + int type; unsigned int interface_version; const char *name; const char *author; const char *desc; unsigned int version[3]; const char *license; void *mysql_api; int (*init)(char *, size_t, int, va_list); int (*deinit)(); int (*options)(const char *option, const void *); int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, struct st_mysql *mysql); }; -typedef char *(*mysql_authentication_dialog_ask_t)(struct st_mysql *mysql, - int type, const char *prompt, char *buf, int buf_len); struct st_mysql_client_plugin * mysql_load_plugin(struct st_mysql *mysql, const char *name, int type, int argc, ...); @@ -37,3 +35,5 @@ mysql_client_find_plugin(struct st_mysql *mysql, const char *name, int type); struct st_mysql_client_plugin * mysql_client_register_plugin(struct st_mysql *mysql, struct st_mysql_client_plugin *plugin); +int mysql_plugin_options(struct st_mysql_client_plugin *plugin, + const char *option, const void *value); diff --git a/include/mysql/innodb_priv.h b/include/mysql/innodb_priv.h index 993dad7cf99..5406c292b18 100644 --- a/include/mysql/innodb_priv.h +++ b/include/mysql/innodb_priv.h @@ -22,7 +22,6 @@ class THD; -uint filename_to_tablename(const char *from, char *to, uint to_length); int get_quote_char_for_identifier(THD *thd, const char *name, uint length); bool schema_table_store_record(THD *thd, TABLE *table); void localtime_to_TIME(MYSQL_TIME *to, struct tm *from); diff --git a/include/mysql/plugin_audit.h b/include/mysql/plugin_audit.h index 41505da64af..5072ad2b44c 100644 --- a/include/mysql/plugin_audit.h +++ b/include/mysql/plugin_audit.h @@ -24,16 +24,7 @@ #define MYSQL_AUDIT_CLASS_MASK_SIZE 1 -#define MYSQL_AUDIT_INTERFACE_VERSION 0x0200 - -/* - The first word in every event class struct indicates the specific - class of the event. -*/ -struct mysql_event -{ - unsigned int event_class; -}; +#define MYSQL_AUDIT_INTERFACE_VERSION 0x0300 /************************************************************************* @@ -42,6 +33,8 @@ struct mysql_event LOG events occurs before emitting to the general query log. ERROR events occur before transmitting errors to the user. RESULT events occur after transmitting a resultset to the user. + STATUS events occur after transmitting a resultset or errors + to the user. */ #define MYSQL_AUDIT_GENERAL_CLASS 0 @@ -49,10 +42,10 @@ struct mysql_event #define MYSQL_AUDIT_GENERAL_LOG 0 #define MYSQL_AUDIT_GENERAL_ERROR 1 #define MYSQL_AUDIT_GENERAL_RESULT 2 +#define MYSQL_AUDIT_GENERAL_STATUS 3 struct mysql_event_general { - unsigned int event_class; unsigned int event_subclass; int general_error_code; unsigned long general_thread_id; @@ -68,6 +61,42 @@ struct mysql_event_general }; +/* + AUDIT CLASS : CONNECTION + + CONNECT occurs after authentication phase is completed. + DISCONNECT occurs after connection is terminated. + CHANGE_USER occurs after COM_CHANGE_USER RPC is completed. +*/ + +#define MYSQL_AUDIT_CONNECTION_CLASS 1 +#define MYSQL_AUDIT_CONNECTION_CLASSMASK (1 << MYSQL_AUDIT_CONNECTION_CLASS) +#define MYSQL_AUDIT_CONNECTION_CONNECT 0 +#define MYSQL_AUDIT_CONNECTION_DISCONNECT 1 +#define MYSQL_AUDIT_CONNECTION_CHANGE_USER 2 + +struct mysql_event_connection +{ + unsigned int event_subclass; + int status; + unsigned long thread_id; + const char *user; + unsigned int user_length; + const char *priv_user; + unsigned int priv_user_length; + const char *external_user; + unsigned int external_user_length; + const char *proxy_user; + unsigned int proxy_user_length; + const char *host; + unsigned int host_length; + const char *ip; + unsigned int ip_length; + const char *database; + unsigned int database_length; +}; + + /************************************************************************* Here we define the descriptor structure, that is referred from st_mysql_plugin. @@ -78,9 +107,9 @@ struct mysql_event_general waiting for the next query from the client. event_notify() is invoked whenever an event occurs which is of any - class for which the plugin has interest. The first word of the - mysql_event argument indicates the specific event class and the - remainder of the structure is as required for that class. + class for which the plugin has interest. The second argument + indicates the specific event class and the third argument is data + as required for that class. class_mask is an array of bits used to indicate what event classes that this plugin wants to receive. @@ -90,7 +119,7 @@ struct st_mysql_audit { int interface_version; void (*release_thd)(MYSQL_THD); - void (*event_notify)(MYSQL_THD, const struct mysql_event *); + void (*event_notify)(MYSQL_THD, unsigned int, const void *); unsigned long class_mask[MYSQL_AUDIT_CLASS_MASK_SIZE]; }; diff --git a/include/mysql/plugin_audit.h.pp b/include/mysql/plugin_audit.h.pp index ad8ca389d34..42d44b9dae0 100644 --- a/include/mysql/plugin_audit.h.pp +++ b/include/mysql/plugin_audit.h.pp @@ -33,16 +33,23 @@ MYSQL_LEX_STRING *thd_make_lex_string(void* thd, MYSQL_LEX_STRING *lex_str, int allocate_lex_string); #include <mysql/service_thd_wait.h> typedef enum _thd_wait_type_e { - THD_WAIT_MUTEX= 1, + THD_WAIT_SLEEP= 1, THD_WAIT_DISKIO= 2, - THD_WAIT_ROW_TABLE_LOCK= 3, - THD_WAIT_GLOBAL_LOCK= 4 + THD_WAIT_ROW_LOCK= 3, + THD_WAIT_GLOBAL_LOCK= 4, + THD_WAIT_META_DATA_LOCK= 5, + THD_WAIT_TABLE_LOCK= 6, + THD_WAIT_USER_LOCK= 7, + THD_WAIT_BINLOG= 8, + THD_WAIT_GROUP_COMMIT= 9, + THD_WAIT_SYNC= 10, + THD_WAIT_LAST= 11 } thd_wait_type; extern struct thd_wait_service_st { - void (*thd_wait_begin_func)(void*, thd_wait_type); + void (*thd_wait_begin_func)(void*, int); void (*thd_wait_end_func)(void*); } *thd_wait_service; -void thd_wait_begin(void* thd, thd_wait_type wait_type); +void thd_wait_begin(void* thd, int wait_type); void thd_wait_end(void* thd); #include <mysql/service_thread_scheduler.h> struct scheduler_functions; @@ -205,13 +212,8 @@ void mysql_query_cache_invalidate4(void* thd, void *thd_get_ha_data(const void* thd, const struct handlerton *hton); void thd_set_ha_data(void* thd, const struct handlerton *hton, const void *ha_data); -struct mysql_event -{ - unsigned int event_class; -}; struct mysql_event_general { - unsigned int event_class; unsigned int event_subclass; int general_error_code; unsigned long general_thread_id; @@ -225,10 +227,30 @@ struct mysql_event_general unsigned long long general_time; unsigned long long general_rows; }; +struct mysql_event_connection +{ + unsigned int event_subclass; + int status; + unsigned long thread_id; + const char *user; + unsigned int user_length; + const char *priv_user; + unsigned int priv_user_length; + const char *external_user; + unsigned int external_user_length; + const char *proxy_user; + unsigned int proxy_user_length; + const char *host; + unsigned int host_length; + const char *ip; + unsigned int ip_length; + const char *database; + unsigned int database_length; +}; struct st_mysql_audit { int interface_version; void (*release_thd)(void*); - void (*event_notify)(void*, const struct mysql_event *); + void (*event_notify)(void*, unsigned int, const void *); unsigned long class_mask[1]; }; diff --git a/include/mysql/plugin_auth.h b/include/mysql/plugin_auth.h index 2b84a6c73af..fcfd1bc6f0b 100644 --- a/include/mysql/plugin_auth.h +++ b/include/mysql/plugin_auth.h @@ -1,5 +1,6 @@ #ifndef MYSQL_PLUGIN_AUTH_INCLUDED /* Copyright (C) 2010 Sergei Golubchik and Monty Program Ab + Copyright (C) 2010 Sun Microsystems, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -30,6 +31,13 @@ #include <mysql/plugin_auth_common.h> +/* defines for MYSQL_SERVER_AUTH_INFO.password_used */ + +#define PASSWORD_USED_NO 0 +#define PASSWORD_USED_YES 1 +#define PASSWORD_USED_NO_MENTION 2 + + /** Provides server plugin access to authentication information */ @@ -39,7 +47,13 @@ typedef struct st_mysql_server_auth_info User name as sent by the client and shown in USER(). NULL if the client packet with the user name was not received yet. */ - const char *user_name; + char *user_name; + + /** + Length of user_name + */ + unsigned int user_name_length; + /** A corresponding column value from the mysql.user table for the matching account name @@ -47,17 +61,46 @@ typedef struct st_mysql_server_auth_info const char *auth_string; /** + Length of auth_string + */ + unsigned long auth_string_length; + + /** Matching account name as found in the mysql.user table. A plugin can override it with another name that will be used by MySQL for authorization, and shown in CURRENT_USER() */ char authenticated_as[MYSQL_USERNAME_LENGTH+1]; + + + /** + The unique user name that was used by the plugin to authenticate. + Not used by the server. + Available through the @@EXTERNAL_USER variable. + */ + char external_user[512]; + /** This only affects the "Authentication failed. Password used: %s" - error message. If set, %s will be YES, otherwise - NO. + error message. has the following values : + 0 : %s will be NO. + 1 : %s will be YES. + 2 : there will be no %s. Set it as appropriate or ignore at will. */ int password_used; + + /** + Set to the name of the connected client host, if it can be resolved, + or to its IP address otherwise. + */ + const char *host_or_ip; + + /** + Length of host_or_ip + */ + unsigned int host_or_ip_length; + } MYSQL_SERVER_AUTH_INFO; /** diff --git a/include/mysql/plugin_auth.h.pp b/include/mysql/plugin_auth.h.pp index bbd91a84f33..e65278c518e 100644 --- a/include/mysql/plugin_auth.h.pp +++ b/include/mysql/plugin_auth.h.pp @@ -33,16 +33,23 @@ MYSQL_LEX_STRING *thd_make_lex_string(void* thd, MYSQL_LEX_STRING *lex_str, int allocate_lex_string); #include <mysql/service_thd_wait.h> typedef enum _thd_wait_type_e { - THD_WAIT_MUTEX= 1, + THD_WAIT_SLEEP= 1, THD_WAIT_DISKIO= 2, - THD_WAIT_ROW_TABLE_LOCK= 3, - THD_WAIT_GLOBAL_LOCK= 4 + THD_WAIT_ROW_LOCK= 3, + THD_WAIT_GLOBAL_LOCK= 4, + THD_WAIT_META_DATA_LOCK= 5, + THD_WAIT_TABLE_LOCK= 6, + THD_WAIT_USER_LOCK= 7, + THD_WAIT_BINLOG= 8, + THD_WAIT_GROUP_COMMIT= 9, + THD_WAIT_SYNC= 10, + THD_WAIT_LAST= 11 } thd_wait_type; extern struct thd_wait_service_st { - void (*thd_wait_begin_func)(void*, thd_wait_type); + void (*thd_wait_begin_func)(void*, int); void (*thd_wait_end_func)(void*); } *thd_wait_service; -void thd_wait_begin(void* thd, thd_wait_type wait_type); +void thd_wait_begin(void* thd, int wait_type); void thd_wait_end(void* thd); #include <mysql/service_thread_scheduler.h> struct scheduler_functions; @@ -95,22 +102,6 @@ struct st_mysql_plugin struct st_mysql_sys_var **system_vars; void * __reserved1; }; -struct st_maria_plugin -{ - int type; - void *info; - const char *name; - const char *author; - const char *descr; - int license; - int (*init)(void *); - int (*deinit)(void *); - unsigned int version; - struct st_mysql_show_var *status_vars; - struct st_mysql_sys_var **system_vars; - const char *version_info; - unsigned int maturity; -}; #include "plugin_ftparser.h" #include "plugin.h" enum enum_ftparser_mode @@ -140,16 +131,16 @@ typedef struct st_mysql_ftparser_boolean_info typedef struct st_mysql_ftparser_param { int (*mysql_parse)(struct st_mysql_ftparser_param *, - const char *doc, int doc_len); + char *doc, int doc_len); int (*mysql_add_word)(struct st_mysql_ftparser_param *, - const char *word, int word_len, + char *word, int word_len, MYSQL_FTPARSER_BOOLEAN_INFO *boolean_info); void *ftparser_state; void *mysql_ftparam; - const struct charset_info_st *cs; - const char *doc; + struct charset_info_st *cs; + char *doc; int length; - unsigned int flags; + int flags; enum enum_ftparser_mode mode; } MYSQL_FTPARSER_PARAM; struct st_mysql_ftparser @@ -187,14 +178,13 @@ int thd_in_lock_tables(const void* thd); int thd_tablespace_op(const void* thd); long long thd_test_options(const void* thd, long long test_options); int thd_sql_command(const void* thd); +const char *thd_proc_info(void* thd, const char *info); void **thd_ha_data(const void* thd, const struct handlerton *hton); void thd_storage_lock_wait(void* thd, long long value); int thd_tx_isolation(const void* thd); char *thd_security_context(void* thd, char *buffer, unsigned int length, unsigned int max_query_len); void thd_inc_row_count(void* thd); -const char *set_thd_proc_info(void*, const char * info, const char *func, - const char *file, const unsigned int line); int mysql_tmpfile(const char *prefix); int thd_killed(const void* thd); unsigned long thd_get_thread_id(const void* thd); @@ -223,10 +213,15 @@ typedef struct st_plugin_vio } MYSQL_PLUGIN_VIO; typedef struct st_mysql_server_auth_info { - const char *user_name; + char *user_name; + unsigned int user_name_length; const char *auth_string; + unsigned long auth_string_length; char authenticated_as[48 +1]; + char external_user[512]; int password_used; + const char *host_or_ip; + unsigned int host_or_ip_length; } MYSQL_SERVER_AUTH_INFO; struct st_mysql_auth { diff --git a/include/mysql/plugin_auth_common.h b/include/mysql/plugin_auth_common.h index b71591d6eb6..3c87fe7e094 100644 --- a/include/mysql/plugin_auth_common.h +++ b/include/mysql/plugin_auth_common.h @@ -1,5 +1,6 @@ #ifndef MYSQL_PLUGIN_AUTH_COMMON_INCLUDED /* Copyright (C) 2010 Sergei Golubchik and Monty Program Ab + Copyright (C) 2010 Sun Microsystems, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/include/mysql/plugin_ftparser.h.pp b/include/mysql/plugin_ftparser.h.pp index 0d6a70ec19c..0067732d4fc 100644 --- a/include/mysql/plugin_ftparser.h.pp +++ b/include/mysql/plugin_ftparser.h.pp @@ -33,16 +33,23 @@ MYSQL_LEX_STRING *thd_make_lex_string(void* thd, MYSQL_LEX_STRING *lex_str, int allocate_lex_string); #include <mysql/service_thd_wait.h> typedef enum _thd_wait_type_e { - THD_WAIT_MUTEX= 1, + THD_WAIT_SLEEP= 1, THD_WAIT_DISKIO= 2, - THD_WAIT_ROW_TABLE_LOCK= 3, - THD_WAIT_GLOBAL_LOCK= 4 + THD_WAIT_ROW_LOCK= 3, + THD_WAIT_GLOBAL_LOCK= 4, + THD_WAIT_META_DATA_LOCK= 5, + THD_WAIT_TABLE_LOCK= 6, + THD_WAIT_USER_LOCK= 7, + THD_WAIT_BINLOG= 8, + THD_WAIT_GROUP_COMMIT= 9, + THD_WAIT_SYNC= 10, + THD_WAIT_LAST= 11 } thd_wait_type; extern struct thd_wait_service_st { - void (*thd_wait_begin_func)(void*, thd_wait_type); + void (*thd_wait_begin_func)(void*, int); void (*thd_wait_end_func)(void*); } *thd_wait_service; -void thd_wait_begin(void* thd, thd_wait_type wait_type); +void thd_wait_begin(void* thd, int wait_type); void thd_wait_end(void* thd); #include <mysql/service_thread_scheduler.h> struct scheduler_functions; diff --git a/include/mysql/psi/mysql_file.h b/include/mysql/psi/mysql_file.h index de145f642e1..6fc6689c47d 100644 --- a/include/mysql/psi/mysql_file.h +++ b/include/mysql/psi/mysql_file.h @@ -16,6 +16,8 @@ #ifndef MYSQL_FILE_H #define MYSQL_FILE_H +#include <my_global.h> + /* For strlen() */ #include <string.h> /* For MY_STAT */ diff --git a/include/mysql/psi/mysql_thread.h b/include/mysql/psi/mysql_thread.h index 389c73d09e9..d20e89a26fd 100644 --- a/include/mysql/psi/mysql_thread.h +++ b/include/mysql/psi/mysql_thread.h @@ -141,9 +141,7 @@ typedef struct st_mysql_rwlock mysql_rwlock_t; @c mysql_prlock_t is a drop-in replacement for @c rw_pr_lock_t. @sa mysql_prlock_init @sa mysql_prlock_rdlock - @sa mysql_prlock_tryrdlock @sa mysql_prlock_wrlock - @sa mysql_prlock_trywrlock @sa mysql_prlock_unlock @sa mysql_prlock_destroy */ @@ -421,20 +419,6 @@ typedef struct st_mysql_cond mysql_cond_t; #endif /** - @def mysql_prlock_tryrdlock(RW) - Instrumented rw_pr_tryrdlock. - @c mysql_prlock_tryrdlock is a drop-in replacement - for @c rw_pr_tryrdlock. -*/ -#ifdef HAVE_PSI_INTERFACE - #define mysql_prlock_tryrdlock(RW) \ - inline_mysql_prlock_tryrdlock(RW, __FILE__, __LINE__) -#else - #define mysql_prlock_tryrdlock(RW) \ - inline_mysql_prlock_tryrdlock(RW) -#endif - -/** @def mysql_rwlock_trywrlock(RW) Instrumented rwlock_trywrlock. @c mysql_rwlock_trywrlock is a drop-in replacement @@ -449,20 +433,6 @@ typedef struct st_mysql_cond mysql_cond_t; #endif /** - @def mysql_prlock_trywrlock(RW) - Instrumented rw_pr_trywrlock. - @c mysql_prlock_trywrlock is a drop-in replacement - for @c rw_pr_trywrlock. -*/ -#ifdef HAVE_PSI_INTERFACE - #define mysql_prlock_trywrlock(RW) \ - inline_mysql_prlock_trywrlock(RW, __FILE__, __LINE__) -#else - #define mysql_prlock_trywrlock(RW) \ - inline_mysql_prlock_trywrlock(RW) -#endif - -/** @def mysql_rwlock_unlock(RW) Instrumented rwlock_unlock. @c mysql_rwlock_unlock is a drop-in replacement @@ -905,35 +875,6 @@ static inline int inline_mysql_rwlock_tryrdlock( return result; } -#ifndef DISABLE_MYSQL_PRLOCK_H -static inline int inline_mysql_prlock_tryrdlock( - mysql_prlock_t *that -#ifdef HAVE_PSI_INTERFACE - , const char *src_file, uint src_line -#endif - ) -{ - int result; -#ifdef HAVE_PSI_INTERFACE - struct PSI_rwlock_locker *locker= NULL; - PSI_rwlock_locker_state state; - if (likely(PSI_server && that->m_psi)) - { - locker= PSI_server->get_thread_rwlock_locker(&state, that->m_psi, - PSI_RWLOCK_TRYREADLOCK); - if (likely(locker != NULL)) - PSI_server->start_rwlock_rdwait(locker, src_file, src_line); - } -#endif - result= rw_pr_tryrdlock(&that->m_prlock); -#ifdef HAVE_PSI_INTERFACE - if (likely(locker != NULL)) - PSI_server->end_rwlock_rdwait(locker, result); -#endif - return result; -} -#endif - static inline int inline_mysql_rwlock_trywrlock( mysql_rwlock_t *that #ifdef HAVE_PSI_INTERFACE @@ -961,35 +902,6 @@ static inline int inline_mysql_rwlock_trywrlock( return result; } -#ifndef DISABLE_MYSQL_PRLOCK_H -static inline int inline_mysql_prlock_trywrlock( - mysql_prlock_t *that -#ifdef HAVE_PSI_INTERFACE - , const char *src_file, uint src_line -#endif - ) -{ - int result; -#ifdef HAVE_PSI_INTERFACE - struct PSI_rwlock_locker *locker= NULL; - PSI_rwlock_locker_state state; - if (likely(PSI_server && that->m_psi)) - { - locker= PSI_server->get_thread_rwlock_locker(&state, that->m_psi, - PSI_RWLOCK_TRYWRITELOCK); - if (likely(locker != NULL)) - PSI_server->start_rwlock_wrwait(locker, src_file, src_line); - } -#endif - result= rw_pr_trywrlock(&that->m_prlock); -#ifdef HAVE_PSI_INTERFACE - if (likely(locker != NULL)) - PSI_server->end_rwlock_wrwait(locker, result); -#endif - return result; -} -#endif - static inline int inline_mysql_rwlock_unlock( mysql_rwlock_t *that) { diff --git a/include/mysql/service_thd_wait.h b/include/mysql/service_thd_wait.h index 2a8f5e610a3..f5d2a75f5fc 100644 --- a/include/mysql/service_thd_wait.h +++ b/include/mysql/service_thd_wait.h @@ -50,15 +50,35 @@ extern "C" { #endif +/* + One should only report wait events that could potentially block for a + long time. A mutex wait is too short of an event to report. The reason + is that an event which is reported leads to a new thread starts + executing a query and this has a negative impact of usage of CPU caches + and thus the expected gain of starting a new thread must be higher than + the expected cost of lost performance due to starting a new thread. + + Good examples of events that should be reported are waiting for row locks + that could easily be for many milliseconds or even seconds and the same + holds true for global read locks, table locks and other meta data locks. + Another event of interest is going to sleep for an extended time. +*/ typedef enum _thd_wait_type_e { - THD_WAIT_MUTEX= 1, + THD_WAIT_SLEEP= 1, THD_WAIT_DISKIO= 2, - THD_WAIT_ROW_TABLE_LOCK= 3, - THD_WAIT_GLOBAL_LOCK= 4 + THD_WAIT_ROW_LOCK= 3, + THD_WAIT_GLOBAL_LOCK= 4, + THD_WAIT_META_DATA_LOCK= 5, + THD_WAIT_TABLE_LOCK= 6, + THD_WAIT_USER_LOCK= 7, + THD_WAIT_BINLOG= 8, + THD_WAIT_GROUP_COMMIT= 9, + THD_WAIT_SYNC= 10, + THD_WAIT_LAST= 11 } thd_wait_type; extern struct thd_wait_service_st { - void (*thd_wait_begin_func)(MYSQL_THD, thd_wait_type); + void (*thd_wait_begin_func)(MYSQL_THD, int); void (*thd_wait_end_func)(MYSQL_THD); } *thd_wait_service; @@ -70,7 +90,7 @@ extern struct thd_wait_service_st { #else -void thd_wait_begin(MYSQL_THD thd, thd_wait_type wait_type); +void thd_wait_begin(MYSQL_THD thd, int wait_type); void thd_wait_end(MYSQL_THD thd); #endif diff --git a/include/mysql/thread_pool_priv.h b/include/mysql/thread_pool_priv.h new file mode 100644 index 00000000000..fc9a2bc6424 --- /dev/null +++ b/include/mysql/thread_pool_priv.h @@ -0,0 +1,121 @@ +/* + Copyright (C) 2010, 2011 Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef THREAD_POOL_PRIV_INCLUDED +#define THREAD_POOL_PRIV_INCLUDED + +/* + The thread pool requires access to some MySQL server error codes, this is + accessed from mysqld_error.h. + We need access to the struct that defines the thread pool plugin interface + which is accessed through scheduler.h. + All accesses to THD variables and functions are defined in this header file. + A thread pool can also use DEBUG_SYNC and must thus include + debug_sync.h + To handle definitions of Information Schema plugins it is also required + to include sql_profile.h and table.h. +*/ +#include <mysqld_error.h> /* To get ER_ERROR_ON_READ */ +#define MYSQL_SERVER 1 +#include <scheduler.h> +#include <debug_sync.h> +#include <sql_profile.h> +#include <table.h> + +/* Needed to get access to scheduler variables */ +void* thd_get_scheduler_data(THD *thd); +void thd_set_scheduler_data(THD *thd, void *data); +PSI_thread* thd_get_psi(THD *thd); +void thd_set_psi(THD *thd, PSI_thread *psi); + +/* Interface to THD variables and functions */ +void thd_set_killed(THD *thd); +void thd_clear_errors(THD *thd); +void thd_set_thread_stack(THD *thd, char *stack_start); +void thd_lock_thread_count(THD *thd); +void thd_unlock_thread_count(THD *thd); +void thd_close_connection(THD *thd); +THD *thd_get_current_thd(); +void thd_new_connection_setup(THD *thd, char *stack_start); +void thd_lock_data(THD *thd); +void thd_unlock_data(THD *thd); +bool thd_is_transaction_active(THD *thd); +int thd_connection_has_data(THD *thd); +void thd_set_net_read_write(THD *thd, uint val); +void thd_set_mysys_var(THD *thd, st_my_thread_var *mysys_var); +my_socket thd_get_fd(THD *thd); + +/* Print to the MySQL error log */ +void sql_print_error(const char *format, ...); + +/* Store a table record */ +bool schema_table_store_record(THD *thd, TABLE *table); + +/* + The thread pool must be able to execute statements using the connection + state in THD object. This is the main objective of the thread pool to + schedule the start of these commands. +*/ +bool do_command(THD *thd); + +/* + The thread pool requires an interface to the connection logic in the + MySQL Server since the thread pool will maintain the event logic on + the TCP connection of the MySQL Server. Thus new connections, dropped + connections will be discovered by the thread pool and it needs to + ensure that the proper MySQL Server logic attached to these events is + executed. +*/ +/* Initialise a new connection handler thread */ +bool init_new_connection_handler_thread(); +/* Set up connection thread before use as execution thread */ +bool setup_connection_thread_globals(THD *thd); +/* Prepare connection as part of connection set-up */ +bool thd_prepare_connection(THD *thd); +/* Release auditing before executing statement */ +void mysql_audit_release(THD *thd); +/* Check if connection is still alive */ +bool thd_is_connection_alive(THD *thd); +/* Close connection with possible error code */ +void close_connection(THD *thd, uint errcode); +/* End the connection before closing it */ +void end_connection(THD *thd); +/* Cleanup the THD object */ +void thd_cleanup(THD *thd); +/* Decrement connection counter */ +void dec_connection_count(); +/* Destroy THD object */ +void delete_thd(THD *thd); + +/* + thread_created is maintained by thread pool when activated since + user threads are created by the thread pool (and also special + threads to maintain the thread pool). This is done through + inc_thread_created. + + max_connections is needed to calculate the maximum number of threads + that is allowed to be started by the thread pool. The method + get_max_connections() gets reference to this variable. + + connection_attrib is the thread attributes for connection threads, + the method get_connection_attrib provides a reference to these + attributes. +*/ +void inc_thread_created(void); +ulong get_max_connections(void); +pthread_attr_t *get_connection_attrib(void); +#endif |