diff options
-rw-r--r-- | include/mysql/plugin.h | 7 | ||||
-rw-r--r-- | include/mysql/plugin_audit.h.pp | 6 | ||||
-rw-r--r-- | include/mysql/plugin_auth.h.pp | 6 | ||||
-rw-r--r-- | include/mysql/plugin_ftparser.h.pp | 6 | ||||
-rw-r--r-- | include/mysql/plugin_password_validation.h.pp | 6 | ||||
-rw-r--r-- | sql/mysqld.cc | 165 | ||||
-rw-r--r-- | sql/mysqld.h | 6 | ||||
-rw-r--r-- | sql/sql_class.cc | 25 | ||||
-rw-r--r-- | sql/sql_class.h | 7 | ||||
-rw-r--r-- | sql/sql_priv.h | 5 | ||||
-rw-r--r-- | sql/sql_show.cc | 6 | ||||
-rw-r--r-- | sql/threadpool.h | 3 | ||||
-rw-r--r-- | sql/wsrep_mysqld.h | 3 | ||||
-rw-r--r-- | sql/wsrep_thd.cc | 11 | ||||
-rw-r--r-- | sql/wsrep_thd.h | 3 | ||||
-rw-r--r-- | sql/wsrep_var.cc | 4 | ||||
-rw-r--r-- | sql/wsrep_var.h | 3 |
17 files changed, 193 insertions, 79 deletions
diff --git a/include/mysql/plugin.h b/include/mysql/plugin.h index 16b0c6edc1f..640dc0725cc 100644 --- a/include/mysql/plugin.h +++ b/include/mysql/plugin.h @@ -182,6 +182,11 @@ enum enum_mysql_show_type #define SHOW_LONG SHOW_ULONG #define SHOW_LONGLONG SHOW_ULONGLONG +enum enum_var_type +{ + SHOW_OPT_DEFAULT= 0, SHOW_OPT_SESSION, SHOW_OPT_GLOBAL +}; + struct st_mysql_show_var { const char *name; char *value; @@ -189,7 +194,7 @@ struct st_mysql_show_var { }; #define SHOW_VAR_FUNC_BUFF_SIZE (256 * sizeof(void*)) -typedef int (*mysql_show_var_func)(MYSQL_THD, struct st_mysql_show_var*, char *); +typedef int (*mysql_show_var_func)(MYSQL_THD, struct st_mysql_show_var*, char *, enum enum_var_type); /* diff --git a/include/mysql/plugin_audit.h.pp b/include/mysql/plugin_audit.h.pp index 2d7bb6ee680..10c54eedda3 100644 --- a/include/mysql/plugin_audit.h.pp +++ b/include/mysql/plugin_audit.h.pp @@ -212,12 +212,16 @@ enum enum_mysql_show_type SHOW_SINT, SHOW_SLONG, SHOW_SLONGLONG, SHOW_SIMPLE_FUNC, SHOW_always_last }; +enum enum_var_type +{ + SHOW_OPT_DEFAULT= 0, SHOW_OPT_SESSION, SHOW_OPT_GLOBAL +}; struct st_mysql_show_var { const char *name; char *value; enum enum_mysql_show_type type; }; -typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *); +typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *, enum enum_var_type); struct st_mysql_sys_var; struct st_mysql_value; typedef int (*mysql_var_check_func)(void* thd, diff --git a/include/mysql/plugin_auth.h.pp b/include/mysql/plugin_auth.h.pp index f35d82648b6..062eb4e4ec5 100644 --- a/include/mysql/plugin_auth.h.pp +++ b/include/mysql/plugin_auth.h.pp @@ -212,12 +212,16 @@ enum enum_mysql_show_type SHOW_SINT, SHOW_SLONG, SHOW_SLONGLONG, SHOW_SIMPLE_FUNC, SHOW_always_last }; +enum enum_var_type +{ + SHOW_OPT_DEFAULT= 0, SHOW_OPT_SESSION, SHOW_OPT_GLOBAL +}; struct st_mysql_show_var { const char *name; char *value; enum enum_mysql_show_type type; }; -typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *); +typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *, enum enum_var_type); struct st_mysql_sys_var; struct st_mysql_value; typedef int (*mysql_var_check_func)(void* thd, diff --git a/include/mysql/plugin_ftparser.h.pp b/include/mysql/plugin_ftparser.h.pp index abf887c0b34..888a6bf8972 100644 --- a/include/mysql/plugin_ftparser.h.pp +++ b/include/mysql/plugin_ftparser.h.pp @@ -212,12 +212,16 @@ enum enum_mysql_show_type SHOW_SINT, SHOW_SLONG, SHOW_SLONGLONG, SHOW_SIMPLE_FUNC, SHOW_always_last }; +enum enum_var_type +{ + SHOW_OPT_DEFAULT= 0, SHOW_OPT_SESSION, SHOW_OPT_GLOBAL +}; struct st_mysql_show_var { const char *name; char *value; enum enum_mysql_show_type type; }; -typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *); +typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *, enum enum_var_type); struct st_mysql_sys_var; struct st_mysql_value; typedef int (*mysql_var_check_func)(void* thd, diff --git a/include/mysql/plugin_password_validation.h.pp b/include/mysql/plugin_password_validation.h.pp index 47ede7f8598..77782fb81ee 100644 --- a/include/mysql/plugin_password_validation.h.pp +++ b/include/mysql/plugin_password_validation.h.pp @@ -212,12 +212,16 @@ enum enum_mysql_show_type SHOW_SINT, SHOW_SLONG, SHOW_SLONGLONG, SHOW_SIMPLE_FUNC, SHOW_always_last }; +enum enum_var_type +{ + SHOW_OPT_DEFAULT= 0, SHOW_OPT_SESSION, SHOW_OPT_GLOBAL +}; struct st_mysql_show_var { const char *name; char *value; enum enum_mysql_show_type type; }; -typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *); +typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *, enum enum_var_type); struct st_mysql_sys_var; struct st_mysql_value; typedef int (*mysql_var_check_func)(void* thd, diff --git a/sql/mysqld.cc b/sql/mysqld.cc index a3df9d7bded..6597552a8c2 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -3956,10 +3956,10 @@ extern "C" my_thread_id mariadb_dbug_id() extern "C" { static void my_malloc_size_cb_func(long long size, my_bool is_thread_specific) { + THD *thd= current_thd; /* If thread specific memory */ - if (is_thread_specific) + if (likely(is_thread_specific)) { - THD *thd= current_thd; if (mysqld_server_initialized || thd) { /* @@ -3972,19 +3972,24 @@ static void my_malloc_size_cb_func(long long size, my_bool is_thread_specific) if (thd) { DBUG_PRINT("info", ("memory_used: %lld size: %lld", - (longlong) thd->status_var.memory_used, size)); - thd->status_var.memory_used+= size; - DBUG_ASSERT((longlong) thd->status_var.memory_used >= 0); + (longlong) thd->status_var.local_memory_used, + size)); + thd->status_var.local_memory_used+= size; + DBUG_ASSERT((longlong) thd->status_var.local_memory_used >= 0); } } } - // workaround for gcc 4.2.4-1ubuntu4 -fPIE (from DEB_BUILD_HARDENING=1) - int64 volatile * volatile ptr=&global_status_var.memory_used; - my_atomic_add64_explicit(ptr, size, MY_MEMORY_ORDER_RELAXED); + else if (likely(thd)) + thd->status_var.global_memory_used+= size; + else + { + // workaround for gcc 4.2.4-1ubuntu4 -fPIE (from DEB_BUILD_HARDENING=1) + int64 volatile * volatile ptr=&global_status_var.global_memory_used; + my_atomic_add64_explicit(ptr, size, MY_MEMORY_ORDER_RELAXED); + } } } - static int init_common_variables() { umask(((~my_umask) & 0666)); @@ -7469,7 +7474,8 @@ struct my_option my_long_options[]= MYSQL_TO_BE_IMPLEMENTED_OPTION("validate-user-plugins") // NO_EMBEDDED_ACCESS_CHECKS }; -static int show_queries(THD *thd, SHOW_VAR *var, char *buff) +static int show_queries(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { var->type= SHOW_LONGLONG; var->value= (char *)&thd->query_id; @@ -7477,14 +7483,16 @@ static int show_queries(THD *thd, SHOW_VAR *var, char *buff) } -static int show_net_compression(THD *thd, SHOW_VAR *var, char *buff) +static int show_net_compression(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { var->type= SHOW_MY_BOOL; var->value= (char *)&thd->net.compress; return 0; } -static int show_starttime(THD *thd, SHOW_VAR *var, char *buff) +static int show_starttime(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { var->type= SHOW_LONG; var->value= buff; @@ -7493,7 +7501,8 @@ static int show_starttime(THD *thd, SHOW_VAR *var, char *buff) } #ifdef ENABLED_PROFILING -static int show_flushstatustime(THD *thd, SHOW_VAR *var, char *buff) +static int show_flushstatustime(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { var->type= SHOW_LONG; var->value= buff; @@ -7503,14 +7512,16 @@ static int show_flushstatustime(THD *thd, SHOW_VAR *var, char *buff) #endif #ifdef HAVE_REPLICATION -static int show_rpl_status(THD *thd, SHOW_VAR *var, char *buff) +static int show_rpl_status(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { var->type= SHOW_CHAR; var->value= const_cast<char*>(rpl_status_type[(int)rpl_status]); return 0; } -static int show_slave_running(THD *thd, SHOW_VAR *var, char *buff) +static int show_slave_running(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { Master_info *mi= NULL; bool tmp; @@ -7537,7 +7548,8 @@ static int show_slave_running(THD *thd, SHOW_VAR *var, char *buff) } -static int show_slave_received_heartbeats(THD *thd, SHOW_VAR *var, char *buff) +static int show_slave_received_heartbeats(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { Master_info *mi= NULL; longlong tmp; @@ -7563,7 +7575,8 @@ static int show_slave_received_heartbeats(THD *thd, SHOW_VAR *var, char *buff) } -static int show_heartbeat_period(THD *thd, SHOW_VAR *var, char *buff) +static int show_heartbeat_period(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { Master_info *mi= NULL; float tmp; @@ -7591,7 +7604,8 @@ static int show_heartbeat_period(THD *thd, SHOW_VAR *var, char *buff) #endif /* HAVE_REPLICATION */ -static int show_open_tables(THD *thd, SHOW_VAR *var, char *buff) +static int show_open_tables(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { var->type= SHOW_LONG; var->value= buff; @@ -7599,7 +7613,8 @@ static int show_open_tables(THD *thd, SHOW_VAR *var, char *buff) return 0; } -static int show_prepared_stmt_count(THD *thd, SHOW_VAR *var, char *buff) +static int show_prepared_stmt_count(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { var->type= SHOW_LONG; var->value= buff; @@ -7609,7 +7624,8 @@ static int show_prepared_stmt_count(THD *thd, SHOW_VAR *var, char *buff) return 0; } -static int show_table_definitions(THD *thd, SHOW_VAR *var, char *buff) +static int show_table_definitions(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { var->type= SHOW_LONG; var->value= buff; @@ -7618,7 +7634,8 @@ static int show_table_definitions(THD *thd, SHOW_VAR *var, char *buff) } -static int show_flush_commands(THD *thd, SHOW_VAR *var, char *buff) +static int show_flush_commands(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { var->type= SHOW_LONG; var->value= buff; @@ -7629,7 +7646,8 @@ static int show_flush_commands(THD *thd, SHOW_VAR *var, char *buff) #if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) /* Functions relying on CTX */ -static int show_ssl_ctx_sess_accept(THD *thd, SHOW_VAR *var, char *buff) +static int show_ssl_ctx_sess_accept(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { var->type= SHOW_LONG; var->value= buff; @@ -7638,7 +7656,8 @@ static int show_ssl_ctx_sess_accept(THD *thd, SHOW_VAR *var, char *buff) return 0; } -static int show_ssl_ctx_sess_accept_good(THD *thd, SHOW_VAR *var, char *buff) +static int show_ssl_ctx_sess_accept_good(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { var->type= SHOW_LONG; var->value= buff; @@ -7647,7 +7666,8 @@ static int show_ssl_ctx_sess_accept_good(THD *thd, SHOW_VAR *var, char *buff) return 0; } -static int show_ssl_ctx_sess_connect_good(THD *thd, SHOW_VAR *var, char *buff) +static int show_ssl_ctx_sess_connect_good(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { var->type= SHOW_LONG; var->value= buff; @@ -7656,7 +7676,9 @@ static int show_ssl_ctx_sess_connect_good(THD *thd, SHOW_VAR *var, char *buff) return 0; } -static int show_ssl_ctx_sess_accept_renegotiate(THD *thd, SHOW_VAR *var, char *buff) +static int show_ssl_ctx_sess_accept_renegotiate(THD *thd, SHOW_VAR *var, + char *buff, + enum enum_var_type scope) { var->type= SHOW_LONG; var->value= buff; @@ -7665,7 +7687,9 @@ static int show_ssl_ctx_sess_accept_renegotiate(THD *thd, SHOW_VAR *var, char *b return 0; } -static int show_ssl_ctx_sess_connect_renegotiate(THD *thd, SHOW_VAR *var, char *buff) +static int show_ssl_ctx_sess_connect_renegotiate(THD *thd, SHOW_VAR *var, + char *buff, + enum enum_var_type scope) { var->type= SHOW_LONG; var->value= buff; @@ -7674,7 +7698,8 @@ static int show_ssl_ctx_sess_connect_renegotiate(THD *thd, SHOW_VAR *var, char * return 0; } -static int show_ssl_ctx_sess_cb_hits(THD *thd, SHOW_VAR *var, char *buff) +static int show_ssl_ctx_sess_cb_hits(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { var->type= SHOW_LONG; var->value= buff; @@ -7683,7 +7708,8 @@ static int show_ssl_ctx_sess_cb_hits(THD *thd, SHOW_VAR *var, char *buff) return 0; } -static int show_ssl_ctx_sess_hits(THD *thd, SHOW_VAR *var, char *buff) +static int show_ssl_ctx_sess_hits(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { var->type= SHOW_LONG; var->value= buff; @@ -7692,7 +7718,8 @@ static int show_ssl_ctx_sess_hits(THD *thd, SHOW_VAR *var, char *buff) return 0; } -static int show_ssl_ctx_sess_cache_full(THD *thd, SHOW_VAR *var, char *buff) +static int show_ssl_ctx_sess_cache_full(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { var->type= SHOW_LONG; var->value= buff; @@ -7701,7 +7728,8 @@ static int show_ssl_ctx_sess_cache_full(THD *thd, SHOW_VAR *var, char *buff) return 0; } -static int show_ssl_ctx_sess_misses(THD *thd, SHOW_VAR *var, char *buff) +static int show_ssl_ctx_sess_misses(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { var->type= SHOW_LONG; var->value= buff; @@ -7710,7 +7738,8 @@ static int show_ssl_ctx_sess_misses(THD *thd, SHOW_VAR *var, char *buff) return 0; } -static int show_ssl_ctx_sess_timeouts(THD *thd, SHOW_VAR *var, char *buff) +static int show_ssl_ctx_sess_timeouts(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { var->type= SHOW_LONG; var->value= buff; @@ -7719,7 +7748,8 @@ static int show_ssl_ctx_sess_timeouts(THD *thd, SHOW_VAR *var, char *buff) return 0; } -static int show_ssl_ctx_sess_number(THD *thd, SHOW_VAR *var, char *buff) +static int show_ssl_ctx_sess_number(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { var->type= SHOW_LONG; var->value= buff; @@ -7728,7 +7758,8 @@ static int show_ssl_ctx_sess_number(THD *thd, SHOW_VAR *var, char *buff) return 0; } -static int show_ssl_ctx_sess_connect(THD *thd, SHOW_VAR *var, char *buff) +static int show_ssl_ctx_sess_connect(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { var->type= SHOW_LONG; var->value= buff; @@ -7737,7 +7768,9 @@ static int show_ssl_ctx_sess_connect(THD *thd, SHOW_VAR *var, char *buff) return 0; } -static int show_ssl_ctx_sess_get_cache_size(THD *thd, SHOW_VAR *var, char *buff) +static int show_ssl_ctx_sess_get_cache_size(THD *thd, SHOW_VAR *var, + char *buff, + enum enum_var_type scope) { var->type= SHOW_LONG; var->value= buff; @@ -7746,7 +7779,8 @@ static int show_ssl_ctx_sess_get_cache_size(THD *thd, SHOW_VAR *var, char *buff) return 0; } -static int show_ssl_ctx_get_verify_mode(THD *thd, SHOW_VAR *var, char *buff) +static int show_ssl_ctx_get_verify_mode(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { var->type= SHOW_LONG; var->value= buff; @@ -7755,7 +7789,8 @@ static int show_ssl_ctx_get_verify_mode(THD *thd, SHOW_VAR *var, char *buff) return 0; } -static int show_ssl_ctx_get_verify_depth(THD *thd, SHOW_VAR *var, char *buff) +static int show_ssl_ctx_get_verify_depth(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { var->type= SHOW_LONG; var->value= buff; @@ -7764,7 +7799,9 @@ static int show_ssl_ctx_get_verify_depth(THD *thd, SHOW_VAR *var, char *buff) return 0; } -static int show_ssl_ctx_get_session_cache_mode(THD *thd, SHOW_VAR *var, char *buff) +static int show_ssl_ctx_get_session_cache_mode(THD *thd, SHOW_VAR *var, + char *buff, + enum enum_var_type scope) { var->type= SHOW_CHAR; if (!ssl_acceptor_fd) @@ -7797,7 +7834,9 @@ static int show_ssl_ctx_get_session_cache_mode(THD *thd, SHOW_VAR *var, char *bu when session_status or global_status is requested from inside an Event. */ -static int show_ssl_get_version(THD *thd, SHOW_VAR *var, char *buff) + +static int show_ssl_get_version(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { var->type= SHOW_CHAR; if( thd->vio_ok() && thd->net.vio->ssl_arg ) @@ -7807,7 +7846,8 @@ static int show_ssl_get_version(THD *thd, SHOW_VAR *var, char *buff) return 0; } -static int show_ssl_session_reused(THD *thd, SHOW_VAR *var, char *buff) +static int show_ssl_session_reused(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { var->type= SHOW_LONG; var->value= buff; @@ -7818,7 +7858,8 @@ static int show_ssl_session_reused(THD *thd, SHOW_VAR *var, char *buff) return 0; } -static int show_ssl_get_default_timeout(THD *thd, SHOW_VAR *var, char *buff) +static int show_ssl_get_default_timeout(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { var->type= SHOW_LONG; var->value= buff; @@ -7829,7 +7870,8 @@ static int show_ssl_get_default_timeout(THD *thd, SHOW_VAR *var, char *buff) return 0; } -static int show_ssl_get_verify_mode(THD *thd, SHOW_VAR *var, char *buff) +static int show_ssl_get_verify_mode(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { var->type= SHOW_LONG; var->value= buff; @@ -7840,7 +7882,8 @@ static int show_ssl_get_verify_mode(THD *thd, SHOW_VAR *var, char *buff) return 0; } -static int show_ssl_get_verify_depth(THD *thd, SHOW_VAR *var, char *buff) +static int show_ssl_get_verify_depth(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { var->type= SHOW_LONG; var->value= buff; @@ -7851,7 +7894,8 @@ static int show_ssl_get_verify_depth(THD *thd, SHOW_VAR *var, char *buff) return 0; } -static int show_ssl_get_cipher(THD *thd, SHOW_VAR *var, char *buff) +static int show_ssl_get_cipher(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { var->type= SHOW_CHAR; if( thd->vio_ok() && thd->net.vio->ssl_arg ) @@ -7861,7 +7905,8 @@ static int show_ssl_get_cipher(THD *thd, SHOW_VAR *var, char *buff) return 0; } -static int show_ssl_get_cipher_list(THD *thd, SHOW_VAR *var, char *buff) +static int show_ssl_get_cipher_list(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { var->type= SHOW_CHAR; var->value= buff; @@ -7935,7 +7980,8 @@ end: */ static int -show_ssl_get_server_not_before(THD *thd, SHOW_VAR *var, char *buff) +show_ssl_get_server_not_before(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { var->type= SHOW_CHAR; if(thd->vio_ok() && thd->net.vio->ssl_arg) @@ -7968,7 +8014,8 @@ show_ssl_get_server_not_before(THD *thd, SHOW_VAR *var, char *buff) */ static int -show_ssl_get_server_not_after(THD *thd, SHOW_VAR *var, char *buff) +show_ssl_get_server_not_after(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { var->type= SHOW_CHAR; if(thd->vio_ok() && thd->net.vio->ssl_arg) @@ -7989,7 +8036,8 @@ show_ssl_get_server_not_after(THD *thd, SHOW_VAR *var, char *buff) #endif /* HAVE_OPENSSL && !EMBEDDED_LIBRARY */ -static int show_default_keycache(THD *thd, SHOW_VAR *var, char *buff) +static int show_default_keycache(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { struct st_data { KEY_CACHE_STATISTICS stats; @@ -8029,8 +8077,24 @@ static int show_default_keycache(THD *thd, SHOW_VAR *var, char *buff) return 0; } + +static int show_memory_used(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) +{ + var->type= SHOW_LONGLONG; + var->value= buff; + if (scope == OPT_GLOBAL) + *(longlong*) buff= (global_status_var.local_memory_used + + global_status_var.global_memory_used); + else + *(longlong*) buff= thd->status_var.local_memory_used; + return 0; +} + + #ifndef DBUG_OFF -static int debug_status_func(THD *thd, SHOW_VAR *var, char *buff) +static int debug_status_func(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { #define add_var(X,Y,Z) \ v->name= X; \ @@ -8066,7 +8130,8 @@ static int debug_status_func(THD *thd, SHOW_VAR *var, char *buff) #endif #ifdef HAVE_POOL_OF_THREADS -int show_threadpool_idle_threads(THD *thd, SHOW_VAR *var, char *buff) +int show_threadpool_idle_threads(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { var->type= SHOW_INT; var->value= buff; @@ -8152,7 +8217,7 @@ SHOW_VAR status_vars[]= { {"Last_query_cost", (char*) offsetof(STATUS_VAR, last_query_cost), SHOW_DOUBLE_STATUS}, {"Max_statement_time_exceeded", (char*) offsetof(STATUS_VAR, max_statement_time_exceeded), SHOW_LONG_STATUS}, {"Max_used_connections", (char*) &max_used_connections, SHOW_LONG}, - {"Memory_used", (char*) offsetof(STATUS_VAR, memory_used), SHOW_LONGLONG_STATUS}, + {"Memory_used", (char*) &show_memory_used, SHOW_SIMPLE_FUNC}, {"Not_flushed_delayed_rows", (char*) &delayed_rows_in_use, SHOW_LONG_NOFLUSH}, {"Open_files", (char*) &my_file_opened, SHOW_LONG_NOFLUSH}, {"Open_streams", (char*) &my_stream_opened, SHOW_LONG_NOFLUSH}, diff --git a/sql/mysqld.h b/sql/mysqld.h index 94fd3e1b704..5d331fa4809 100644 --- a/sql/mysqld.h +++ b/sql/mysqld.h @@ -54,6 +54,12 @@ typedef Bitmap<((MAX_INDEXES+7)/8*8)> key_map; /* Used for finding keys */ #define TEST_SIGINT 1024 /**< Allow sigint on threads */ #define TEST_SYNCHRONIZATION 2048 /**< get server to do sleep in some places */ + +/* Keep things compatible */ +#define OPT_DEFAULT SHOW_OPT_DEFAULT +#define OPT_SESSION SHOW_OPT_SESSION +#define OPT_GLOBAL SHOW_OPT_GLOBAL + /* Function prototypes */ void kill_mysql(void); void close_connection(THD *thd, uint sql_errno= 0); diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 0d494073b3f..aaff36767da 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -67,6 +67,7 @@ #include "wsrep_mysqld.h" #include "wsrep_thd.h" #include "sql_connect.h" +#include "my_atomic.h" /* The following is used to initialise Table_ident with a internal @@ -934,7 +935,7 @@ THD::THD(bool is_wsrep_applier) */ THD *old_THR_THD= current_thd; set_current_thd(this); - status_var.memory_used= 0; + status_var.local_memory_used= status_var.global_memory_used= 0; main_da.init(); /* @@ -1703,11 +1704,12 @@ THD::~THD() main_da.free_memory(); if (tdc_hash_pins) lf_hash_put_pins(tdc_hash_pins); - if (status_var.memory_used != 0) + /* Ensure everything is freed */ + if (status_var.local_memory_used != 0) { - DBUG_PRINT("error", ("memory_used: %lld", status_var.memory_used)); + DBUG_PRINT("error", ("memory_used: %lld", status_var.local_memory_used)); SAFEMALLOC_REPORT_MEMORY(my_thread_dbug_id()); - DBUG_ASSERT(status_var.memory_used == 0); // Ensure everything is freed + DBUG_ASSERT(status_var.local_memory_used == 0); } set_current_thd(orig_thd); @@ -1747,6 +1749,16 @@ void add_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var) to_var->binlog_bytes_written+= from_var->binlog_bytes_written; to_var->cpu_time+= from_var->cpu_time; to_var->busy_time+= from_var->busy_time; + to_var->local_memory_used+= from_var->local_memory_used; + + /* + Update global_memory_used. We have to do this with atomic_add as the + global value can change outside of LOCK_status. + */ + // workaround for gcc 4.2.4-1ubuntu4 -fPIE (from DEB_BUILD_HARDENING=1) + int64 volatile * volatile ptr= &to_var->global_memory_used; + my_atomic_add64_explicit(ptr, from_var->global_memory_used, + MY_MEMORY_ORDER_RELAXED); } /* @@ -1784,6 +1796,11 @@ void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var, dec_var->binlog_bytes_written; to_var->cpu_time+= from_var->cpu_time - dec_var->cpu_time; to_var->busy_time+= from_var->busy_time - dec_var->busy_time; + + /* + We don't need to accumulate memory_used as these are not reset or used by + the calling functions. See execute_show_status(). + */ } #define SECONDS_TO_WAIT_FOR_KILL 2 diff --git a/sql/sql_class.h b/sql/sql_class.h index 16913fd50b5..1f80494c974 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -760,7 +760,10 @@ typedef struct system_status_var double last_query_cost; double cpu_time, busy_time; /* Don't initialize */ - volatile int64 memory_used; /* This shouldn't be accumulated */ + /* Memory used for thread local storage */ + volatile int64 local_memory_used; + /* Memory allocated for global usage */ + volatile int64 global_memory_used; } STATUS_VAR; /* @@ -770,7 +773,7 @@ typedef struct system_status_var */ #define last_system_status_var questions -#define last_cleared_system_status_var memory_used +#define last_cleared_system_status_var local_memory_used /* Global status variables diff --git a/sql/sql_priv.h b/sql/sql_priv.h index 49a69caad08..1389065873c 100644 --- a/sql/sql_priv.h +++ b/sql/sql_priv.h @@ -347,11 +347,6 @@ enum enum_parsing_place }; -enum enum_var_type -{ - OPT_DEFAULT= 0, OPT_SESSION, OPT_GLOBAL -}; - class sys_var; enum enum_yes_no_unknown diff --git a/sql/sql_show.cc b/sql/sql_show.cc index a43eae0d441..1efd5c15c4d 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -2822,7 +2822,7 @@ int fill_schema_processlist(THD* thd, TABLE_LIST* tables, COND* cond) thread in this thread. However it's better that we notice it eventually than hide it. */ - table->field[12]->store((longlong) (tmp->status_var.memory_used + + table->field[12]->store((longlong) (tmp->status_var.local_memory_used + sizeof(THD)), FALSE); table->field[12]->set_notnull(); @@ -3117,8 +3117,8 @@ static bool show_status_array(THD *thd, const char *wild, */ for (var=variables; var->type == SHOW_FUNC || var->type == SHOW_SIMPLE_FUNC; var= &tmp) - ((mysql_show_var_func)(var->value))(thd, &tmp, buff); - + ((mysql_show_var_func)(var->value))(thd, &tmp, buff, scope); + SHOW_TYPE show_type=var->type; if (show_type == SHOW_ARRAY) { diff --git a/sql/threadpool.h b/sql/threadpool.h index c080e5ba343..50dee35511b 100644 --- a/sql/threadpool.h +++ b/sql/threadpool.h @@ -67,4 +67,5 @@ extern void tp_set_threadpool_stall_limit(uint val); /* Activate threadpool scheduler */ extern void tp_scheduler(void); -extern int show_threadpool_idle_threads(THD *thd, SHOW_VAR *var, char *buff); +extern int show_threadpool_idle_threads(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope); diff --git a/sql/wsrep_mysqld.h b/sql/wsrep_mysqld.h index 22f62dca0e8..a6430560e3e 100644 --- a/sql/wsrep_mysqld.h +++ b/sql/wsrep_mysqld.h @@ -112,7 +112,8 @@ extern const char* wsrep_provider_name; extern const char* wsrep_provider_version; extern const char* wsrep_provider_vendor; -int wsrep_show_status(THD *thd, SHOW_VAR *var, char *buff); +int wsrep_show_status(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope); int wsrep_init(); void wsrep_deinit(bool free_options); void wsrep_recover(); diff --git a/sql/wsrep_thd.cc b/sql/wsrep_thd.cc index b65eead817d..2b4980ae05f 100644 --- a/sql/wsrep_thd.cc +++ b/sql/wsrep_thd.cc @@ -38,12 +38,13 @@ static volatile int32 wsrep_bf_aborts_counter(0); #define WSREP_ATOMIC_ADD_LONG my_atomic_add32 #endif -int wsrep_show_bf_aborts (THD *thd, SHOW_VAR *var, char *buff) +int wsrep_show_bf_aborts (THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { - wsrep_local_bf_aborts = WSREP_ATOMIC_LOAD_LONG(&wsrep_bf_aborts_counter); - var->type = SHOW_LONGLONG; - var->value = (char*)&wsrep_local_bf_aborts; - return 0; + wsrep_local_bf_aborts = WSREP_ATOMIC_LOAD_LONG(&wsrep_bf_aborts_counter); + var->type = SHOW_LONGLONG; + var->value = (char*)&wsrep_local_bf_aborts; + return 0; } /* must have (&thd->LOCK_wsrep_thd) */ diff --git a/sql/wsrep_thd.h b/sql/wsrep_thd.h index 0d01d28f01b..5900668f3fb 100644 --- a/sql/wsrep_thd.h +++ b/sql/wsrep_thd.h @@ -22,7 +22,8 @@ #include "sql_class.h" -int wsrep_show_bf_aborts (THD *thd, SHOW_VAR *var, char *buff); +int wsrep_show_bf_aborts (THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope); void wsrep_client_rollback(THD *thd); void wsrep_replay_transaction(THD *thd); void wsrep_create_appliers(long threads); diff --git a/sql/wsrep_var.cc b/sql/wsrep_var.cc index 8a4fa4cd14f..1c0e51e50ad 100644 --- a/sql/wsrep_var.cc +++ b/sql/wsrep_var.cc @@ -15,7 +15,6 @@ #include "wsrep_var.h" -#include <sql_plugin.h> #include <mysqld.h> #include <sql_class.h> #include <set_var.h> @@ -535,7 +534,8 @@ static int show_var_cmp(const void *var1, const void *var2) return strcasecmp(((SHOW_VAR*)var1)->name, ((SHOW_VAR*)var2)->name); } -int wsrep_show_status (THD *thd, SHOW_VAR *var, char *buff) +int wsrep_show_status (THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) { uint i, maxi= SHOW_VAR_FUNC_BUFF_SIZE / sizeof(*var) - 1; SHOW_VAR *v= (SHOW_VAR *)buff; diff --git a/sql/wsrep_var.h b/sql/wsrep_var.h index 6914204148d..377b54f2d18 100644 --- a/sql/wsrep_var.h +++ b/sql/wsrep_var.h @@ -27,6 +27,9 @@ // MySQL variables funcs #include "sql_priv.h" +#include <sql_plugin.h> +#include <mysql/plugin.h> + class sys_var; class set_var; class THD; |