Commit 636bb590 authored by Monty's avatar Monty

Final fixes for Memory_used

- Change some static variables to dynamic to ensure that we don't do any memory
  allocations before server starts or stops
- Print more memory information on SIGHUP. Fixed output.
- Write out if memory was lost if run with --debug-at-exit
- Fixed wrong #ifdef in sql_cache.cc
parent 32d3d9f7
...@@ -120,10 +120,10 @@ static int wsrep_memb_fill_table(THD *thd, TABLE_LIST *tables, COND *cond) ...@@ -120,10 +120,10 @@ static int wsrep_memb_fill_table(THD *thd, TABLE_LIST *tables, COND *cond)
if (check_global_access(thd, SUPER_ACL, true)) if (check_global_access(thd, SUPER_ACL, true))
return rc; return rc;
wsrep_config_state.lock(); wsrep_config_state->lock();
Dynamic_array<wsrep_member_info_t> *memb_arr= Dynamic_array<wsrep_member_info_t> *memb_arr=
wsrep_config_state.get_member_info(); wsrep_config_state->get_member_info();
TABLE *table= tables->table; TABLE *table= tables->table;
...@@ -151,7 +151,7 @@ static int wsrep_memb_fill_table(THD *thd, TABLE_LIST *tables, COND *cond) ...@@ -151,7 +151,7 @@ static int wsrep_memb_fill_table(THD *thd, TABLE_LIST *tables, COND *cond)
} }
end: end:
wsrep_config_state.unlock(); wsrep_config_state->unlock();
return rc; return rc;
} }
...@@ -175,10 +175,10 @@ static int wsrep_status_fill_table(THD *thd, TABLE_LIST *tables, COND *cond) ...@@ -175,10 +175,10 @@ static int wsrep_status_fill_table(THD *thd, TABLE_LIST *tables, COND *cond)
if (check_global_access(thd, SUPER_ACL, true)) if (check_global_access(thd, SUPER_ACL, true))
return rc; return rc;
wsrep_config_state.lock(); wsrep_config_state->lock();
wsrep_view_info_t view= wsrep_config_state.get_view_info(); wsrep_view_info_t view= wsrep_config_state->get_view_info();
wsrep_member_status_t status= wsrep_config_state.get_status(); wsrep_member_status_t status= wsrep_config_state->get_status();
TABLE *table= tables->table; TABLE *table= tables->table;
...@@ -210,7 +210,7 @@ static int wsrep_status_fill_table(THD *thd, TABLE_LIST *tables, COND *cond) ...@@ -210,7 +210,7 @@ static int wsrep_status_fill_table(THD *thd, TABLE_LIST *tables, COND *cond)
if (schema_table_store_record(thd, table)) if (schema_table_store_record(thd, table))
rc= 1; rc= 1;
wsrep_config_state.unlock(); wsrep_config_state->unlock();
return rc; return rc;
} }
......
...@@ -139,6 +139,12 @@ static bool start_binlog_background_thread(); ...@@ -139,6 +139,12 @@ static bool start_binlog_background_thread();
static rpl_binlog_state rpl_global_gtid_binlog_state; static rpl_binlog_state rpl_global_gtid_binlog_state;
void setup_log_handling()
{
rpl_global_gtid_binlog_state.init();
}
/** /**
purge logs, master and slave sides both, related error code purge logs, master and slave sides both, related error code
convertor. convertor.
......
...@@ -26,6 +26,7 @@ class Relay_log_info; ...@@ -26,6 +26,7 @@ class Relay_log_info;
class Format_description_log_event; class Format_description_log_event;
void setup_log_handling();
bool trans_has_updated_trans_table(const THD* thd); bool trans_has_updated_trans_table(const THD* thd);
bool stmt_has_updated_trans_table(const THD *thd); bool stmt_has_updated_trans_table(const THD *thd);
bool use_trans_cache(const THD* thd, bool is_transactional); bool use_trans_cache(const THD* thd, bool is_transactional);
......
...@@ -367,7 +367,7 @@ static my_bool opt_short_log_format= 0, opt_silent_startup= 0; ...@@ -367,7 +367,7 @@ static my_bool opt_short_log_format= 0, opt_silent_startup= 0;
uint kill_cached_threads; uint kill_cached_threads;
static uint wake_thread; static uint wake_thread;
ulong max_used_connections; ulong max_used_connections;
static volatile ulong cached_thread_count= 0; volatile ulong cached_thread_count= 0;
static char *mysqld_user, *mysqld_chroot; static char *mysqld_user, *mysqld_chroot;
static char *default_character_set_name; static char *default_character_set_name;
static char *character_set_filesystem_name; static char *character_set_filesystem_name;
...@@ -1987,8 +1987,6 @@ static void __cdecl kill_server(int sig_ptr) ...@@ -1987,8 +1987,6 @@ static void __cdecl kill_server(int sig_ptr)
if (wsrep_inited == 1) if (wsrep_inited == 1)
wsrep_deinit(true); wsrep_deinit(true);
wsrep_thr_deinit();
if (sig != MYSQL_KILL_SIGNAL && if (sig != MYSQL_KILL_SIGNAL &&
sig != 0) sig != 0)
unireg_abort(1); /* purecov: inspected */ unireg_abort(1); /* purecov: inspected */
...@@ -2144,6 +2142,9 @@ static void mysqld_exit(int exit_code) ...@@ -2144,6 +2142,9 @@ static void mysqld_exit(int exit_code)
set_malloc_size_cb(NULL); set_malloc_size_cb(NULL);
cleanup_tls(); cleanup_tls();
DBUG_LEAVE; DBUG_LEAVE;
if (opt_endinfo && global_status_var.global_memory_used)
fprintf(stderr, "Warning: Memory not freed: %ld\n",
(long) global_status_var.global_memory_used);
sd_notify(0, "STATUS=MariaDB server is down"); sd_notify(0, "STATUS=MariaDB server is down");
exit(exit_code); /* purecov: inspected */ exit(exit_code); /* purecov: inspected */
} }
...@@ -2213,11 +2214,12 @@ void clean_up(bool print_message) ...@@ -2213,11 +2214,12 @@ void clean_up(bool print_message)
free_global_client_stats(); free_global_client_stats();
free_global_table_stats(); free_global_table_stats();
free_global_index_stats(); free_global_index_stats();
delete_dynamic(&all_options); delete_dynamic(&all_options); // This should be empty
free_all_rpl_filters(); free_all_rpl_filters();
#ifdef HAVE_REPLICATION #ifdef HAVE_REPLICATION
end_slave_list(); end_slave_list();
#endif #endif
wsrep_thr_deinit();
my_uuid_end(); my_uuid_end();
delete binlog_filter; delete binlog_filter;
delete global_rpl_filter; delete global_rpl_filter;
...@@ -5032,6 +5034,8 @@ static int init_server_components() ...@@ -5032,6 +5034,8 @@ static int init_server_components()
/* Setup logs */ /* Setup logs */
setup_log_handling();
/* /*
Enable old-fashioned error log, except when the user has requested Enable old-fashioned error log, except when the user has requested
help information. Since the implementation of plugin server help information. Since the implementation of plugin server
...@@ -5202,7 +5206,9 @@ static int init_server_components() ...@@ -5202,7 +5206,9 @@ static int init_server_components()
/* It's now safe to use thread specific memory */ /* It's now safe to use thread specific memory */
mysqld_server_initialized= 1; mysqld_server_initialized= 1;
#ifndef EMBEDDED_LIBRARY
wsrep_thr_init(); wsrep_thr_init();
#endif
if (WSREP_ON && !wsrep_recovery && !opt_abort) /* WSREP BEFORE SE */ if (WSREP_ON && !wsrep_recovery && !opt_abort) /* WSREP BEFORE SE */
{ {
......
...@@ -203,6 +203,7 @@ extern LEX_CSTRING reason_slave_blocked; ...@@ -203,6 +203,7 @@ extern LEX_CSTRING reason_slave_blocked;
extern ulong slave_trans_retries; extern ulong slave_trans_retries;
extern uint slave_net_timeout; extern uint slave_net_timeout;
extern int max_user_connections; extern int max_user_connections;
extern volatile ulong cached_thread_count;
extern ulong what_to_log,flush_time; extern ulong what_to_log,flush_time;
extern ulong max_prepared_stmt_count, prepared_stmt_count; extern ulong max_prepared_stmt_count, prepared_stmt_count;
extern ulong open_files_limit; extern ulong open_files_limit;
......
...@@ -1127,7 +1127,7 @@ rpl_slave_state::is_empty() ...@@ -1127,7 +1127,7 @@ rpl_slave_state::is_empty()
} }
rpl_binlog_state::rpl_binlog_state() void rpl_binlog_state::init()
{ {
my_hash_init(&hash, &my_charset_bin, 32, offsetof(element, domain_id), my_hash_init(&hash, &my_charset_bin, 32, offsetof(element, domain_id),
sizeof(uint32), NULL, my_free, HASH_UNIQUE); sizeof(uint32), NULL, my_free, HASH_UNIQUE);
...@@ -1137,7 +1137,6 @@ rpl_binlog_state::rpl_binlog_state() ...@@ -1137,7 +1137,6 @@ rpl_binlog_state::rpl_binlog_state()
initialized= 1; initialized= 1;
} }
void void
rpl_binlog_state::reset_nolock() rpl_binlog_state::reset_nolock()
{ {
......
...@@ -231,9 +231,10 @@ struct rpl_binlog_state ...@@ -231,9 +231,10 @@ struct rpl_binlog_state
/* Auxiliary buffer to sort gtid list. */ /* Auxiliary buffer to sort gtid list. */
DYNAMIC_ARRAY gtid_sort_array; DYNAMIC_ARRAY gtid_sort_array;
rpl_binlog_state(); rpl_binlog_state() :initialized(0) {}
~rpl_binlog_state(); ~rpl_binlog_state();
void init();
void reset_nolock(); void reset_nolock();
void reset(); void reset();
void free(); void free();
......
...@@ -70,6 +70,7 @@ Relay_log_info::Relay_log_info(bool is_slave_recovery) ...@@ -70,6 +70,7 @@ Relay_log_info::Relay_log_info(bool is_slave_recovery)
DBUG_ENTER("Relay_log_info::Relay_log_info"); DBUG_ENTER("Relay_log_info::Relay_log_info");
relay_log.is_relay_log= TRUE; relay_log.is_relay_log= TRUE;
relay_log_state.init();
#ifdef HAVE_PSI_INTERFACE #ifdef HAVE_PSI_INTERFACE
relay_log.set_psi_keys(key_RELAYLOG_LOCK_index, relay_log.set_psi_keys(key_RELAYLOG_LOCK_index,
key_RELAYLOG_update_cond, key_RELAYLOG_update_cond,
......
...@@ -354,7 +354,7 @@ const uchar *query_state_map; ...@@ -354,7 +354,7 @@ const uchar *query_state_map;
#include "emb_qcache.h" #include "emb_qcache.h"
#endif #endif
#if !defined(EXTRA_DBUG) && !defined(DBUG_OFF) #if defined(EXTRA_DEBUG) && !defined(DBUG_OFF)
#define RW_WLOCK(M) {DBUG_PRINT("lock", ("rwlock wlock 0x%lx",(ulong)(M))); \ #define RW_WLOCK(M) {DBUG_PRINT("lock", ("rwlock wlock 0x%lx",(ulong)(M))); \
if (!mysql_rwlock_wrlock(M)) DBUG_PRINT("lock", ("rwlock wlock ok")); \ if (!mysql_rwlock_wrlock(M)) DBUG_PRINT("lock", ("rwlock wlock ok")); \
else DBUG_PRINT("lock", ("rwlock wlock FAILED %d", errno)); } else DBUG_PRINT("lock", ("rwlock wlock FAILED %d", errno)); }
......
...@@ -1733,7 +1733,6 @@ THD::~THD() ...@@ -1733,7 +1733,6 @@ THD::~THD()
other types are handled explicitely other types are handled explicitely
*/ */
void add_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var) void add_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var)
{ {
ulong *end= (ulong*) ((uchar*) to_var + ulong *end= (ulong*) ((uchar*) to_var +
......
...@@ -182,6 +182,7 @@ struct binlog_send_info { ...@@ -182,6 +182,7 @@ struct binlog_send_info {
{ {
error_text[0] = 0; error_text[0] = 0;
bzero(&error_gtid, sizeof(error_gtid)); bzero(&error_gtid, sizeof(error_gtid));
until_binlog_state.init();
} }
}; };
......
...@@ -54,7 +54,7 @@ static const char *lock_descriptions[] = ...@@ -54,7 +54,7 @@ static const char *lock_descriptions[] =
}; };
#ifndef DBUG_OFF #ifdef EXTRA_DEBUG
void void
print_where(COND *cond,const char *info, enum_query_type query_type) print_where(COND *cond,const char *info, enum_query_type query_type)
...@@ -559,16 +559,19 @@ C_MODE_END ...@@ -559,16 +559,19 @@ C_MODE_END
void mysql_print_status() void mysql_print_status()
{ {
char current_dir[FN_REFLEN]; char current_dir[FN_REFLEN];
char llbuff[10][22];
STATUS_VAR tmp; STATUS_VAR tmp;
uint count;
calc_sum_of_all_status(&tmp); count= calc_sum_of_all_status(&tmp);
printf("\nStatus information:\n\n"); printf("\nStatus information:\n\n");
(void) my_getwd(current_dir, sizeof(current_dir),MYF(0)); (void) my_getwd(current_dir, sizeof(current_dir),MYF(0));
printf("Current dir: %s\n", current_dir); printf("Current dir: %s\n", current_dir);
printf("Running threads: %d Stack size: %ld\n", thread_count, printf("Running threads: %d Cached threads: %lu Stack size: %ld\n",
count, cached_thread_count,
(long) my_thread_stack_size); (long) my_thread_stack_size);
#ifdef EXTRA_DEBUG
thr_print_locks(); // Write some debug info thr_print_locks(); // Write some debug info
#ifndef DBUG_OFF
print_cached_tables(); print_cached_tables();
#endif #endif
/* Print key cache status */ /* Print key cache status */
...@@ -614,28 +617,33 @@ Next alarm time: %lu\n", ...@@ -614,28 +617,33 @@ Next alarm time: %lu\n",
#ifdef HAVE_MALLINFO #ifdef HAVE_MALLINFO
struct mallinfo info= mallinfo(); struct mallinfo info= mallinfo();
printf("\nMemory status:\n\ printf("\nMemory status:\n\
Non-mmapped space allocated from system: %d\n\ Non-mmapped space allocated from system: %s\n\
Number of free chunks: %d\n\ Number of free chunks: %lu\n\
Number of fastbin blocks: %d\n\ Number of fastbin blocks: %lu\n\
Number of mmapped regions: %d\n\ Number of mmapped regions: %lu\n\
Space in mmapped regions: %d\n\ Space in mmapped regions: %s\n\
Maximum total allocated space: %d\n\ Maximum total allocated space: %s\n\
Space available in freed fastbin blocks: %d\n\ Space available in freed fastbin blocks: %s\n\
Total allocated space: %d\n\ Total allocated space: %s\n\
Total free space: %d\n\ Total free space: %s\n\
Top-most, releasable space: %d\n\ Top-most, releasable space: %s\n\
Estimated memory (with thread stack): %ld\n", Estimated memory (with thread stack): %s\n\
(int) info.arena , Global memory allocated by server: %s\n\
(int) info.ordblks, Memory allocated by threads: %s\n",
(int) info.smblks, llstr(info.arena, llbuff[0]),
(int) info.hblks, (ulong) info.ordblks,
(int) info.hblkhd, (ulong) info.smblks,
(int) info.usmblks, (ulong) info.hblks,
(int) info.fsmblks, llstr(info.hblkhd, llbuff[1]),
(int) info.uordblks, llstr(info.usmblks, llbuff[2]),
(int) info.fordblks, llstr(info.fsmblks, llbuff[3]),
(int) info.keepcost, llstr(info.uordblks, llbuff[4]),
(long) (thread_count * my_thread_stack_size + info.hblkhd + info.arena)); llstr(info.fordblks, llbuff[5]),
llstr(info.keepcost, llbuff[6]),
llstr((count + cached_thread_count)* my_thread_stack_size + info.hblkhd + info.arena, llbuff[7]),
llstr(tmp.global_memory_used, llbuff[8]),
llstr(tmp.local_memory_used, llbuff[9]));
#endif #endif
#ifdef HAVE_EVENT_SCHEDULER #ifdef HAVE_EVENT_SCHEDULER
......
...@@ -202,7 +202,7 @@ wsrep_uuid_t local_uuid = WSREP_UUID_UNDEFINED; ...@@ -202,7 +202,7 @@ wsrep_uuid_t local_uuid = WSREP_UUID_UNDEFINED;
wsrep_seqno_t local_seqno = WSREP_SEQNO_UNDEFINED; wsrep_seqno_t local_seqno = WSREP_SEQNO_UNDEFINED;
long wsrep_protocol_version = 3; long wsrep_protocol_version = 3;
wsp::Config_state wsrep_config_state; wsp::Config_state *wsrep_config_state;
// Boolean denoting if server is in initial startup phase. This is needed // Boolean denoting if server is in initial startup phase. This is needed
// to make sure that main thread waiting in wsrep_sst_wait() is signaled // to make sure that main thread waiting in wsrep_sst_wait() is signaled
...@@ -281,7 +281,7 @@ wsrep_view_handler_cb (void* app_ctx, ...@@ -281,7 +281,7 @@ wsrep_view_handler_cb (void* app_ctx,
*sst_req = NULL; *sst_req = NULL;
*sst_req_len = 0; *sst_req_len = 0;
wsrep_member_status_t memb_status= wsrep_config_state.get_status(); wsrep_member_status_t memb_status= wsrep_config_state->get_status();
if (memcmp(&cluster_uuid, &view->state_id.uuid, sizeof(wsrep_uuid_t))) if (memcmp(&cluster_uuid, &view->state_id.uuid, sizeof(wsrep_uuid_t)))
{ {
...@@ -442,7 +442,7 @@ wsrep_view_handler_cb (void* app_ctx, ...@@ -442,7 +442,7 @@ wsrep_view_handler_cb (void* app_ctx,
out: out:
if (view->status == WSREP_VIEW_PRIMARY) wsrep_startup= FALSE; if (view->status == WSREP_VIEW_PRIMARY) wsrep_startup= FALSE;
wsrep_config_state.set(memb_status, view); wsrep_config_state->set(memb_status, view);
return WSREP_CB_SUCCESS; return WSREP_CB_SUCCESS;
} }
...@@ -484,7 +484,7 @@ static void wsrep_synced_cb(void* app_ctx) ...@@ -484,7 +484,7 @@ static void wsrep_synced_cb(void* app_ctx)
signal_main= true; signal_main= true;
} }
wsrep_config_state.set(WSREP_MEMBER_SYNCED); wsrep_config_state->set(WSREP_MEMBER_SYNCED);
mysql_mutex_unlock (&LOCK_wsrep_ready); mysql_mutex_unlock (&LOCK_wsrep_ready);
if (signal_main) if (signal_main)
...@@ -753,6 +753,8 @@ int wsrep_init() ...@@ -753,6 +753,8 @@ int wsrep_init()
/* Initialize wsrep thread LOCKs and CONDs */ /* Initialize wsrep thread LOCKs and CONDs */
void wsrep_thr_init() void wsrep_thr_init()
{ {
DBUG_ENTER("wsrep_thr_init");
wsrep_config_state = new wsp::Config_state;
#ifdef HAVE_PSI_INTERFACE #ifdef HAVE_PSI_INTERFACE
mysql_mutex_register("sql", wsrep_mutexes, array_elements(wsrep_mutexes)); mysql_mutex_register("sql", wsrep_mutexes, array_elements(wsrep_mutexes));
mysql_cond_register("sql", wsrep_conds, array_elements(wsrep_conds)); mysql_cond_register("sql", wsrep_conds, array_elements(wsrep_conds));
...@@ -772,6 +774,7 @@ void wsrep_thr_init() ...@@ -772,6 +774,7 @@ void wsrep_thr_init()
mysql_mutex_init(key_LOCK_wsrep_slave_threads, &LOCK_wsrep_slave_threads, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_LOCK_wsrep_slave_threads, &LOCK_wsrep_slave_threads, MY_MUTEX_INIT_FAST);
mysql_mutex_init(key_LOCK_wsrep_desync, &LOCK_wsrep_desync, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_LOCK_wsrep_desync, &LOCK_wsrep_desync, MY_MUTEX_INIT_FAST);
mysql_mutex_init(key_LOCK_wsrep_config_state, &LOCK_wsrep_config_state, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_LOCK_wsrep_config_state, &LOCK_wsrep_config_state, MY_MUTEX_INIT_FAST);
DBUG_VOID_RETURN;
} }
...@@ -819,6 +822,8 @@ void wsrep_deinit(bool free_options) ...@@ -819,6 +822,8 @@ void wsrep_deinit(bool free_options)
/* Destroy wsrep thread LOCKs and CONDs */ /* Destroy wsrep thread LOCKs and CONDs */
void wsrep_thr_deinit() void wsrep_thr_deinit()
{ {
if (!wsrep_config_state)
return; // Never initialized
mysql_mutex_destroy(&LOCK_wsrep_ready); mysql_mutex_destroy(&LOCK_wsrep_ready);
mysql_cond_destroy(&COND_wsrep_ready); mysql_cond_destroy(&COND_wsrep_ready);
mysql_mutex_destroy(&LOCK_wsrep_sst); mysql_mutex_destroy(&LOCK_wsrep_sst);
...@@ -832,6 +837,8 @@ void wsrep_thr_deinit() ...@@ -832,6 +837,8 @@ void wsrep_thr_deinit()
mysql_mutex_destroy(&LOCK_wsrep_slave_threads); mysql_mutex_destroy(&LOCK_wsrep_slave_threads);
mysql_mutex_destroy(&LOCK_wsrep_desync); mysql_mutex_destroy(&LOCK_wsrep_desync);
mysql_mutex_destroy(&LOCK_wsrep_config_state); mysql_mutex_destroy(&LOCK_wsrep_config_state);
delete wsrep_config_state;
wsrep_config_state= 0; // Safety
} }
void wsrep_recover() void wsrep_recover()
......
...@@ -1256,7 +1256,7 @@ wsrep_cb_status_t wsrep_sst_donate_cb (void* app_ctx, void* recv_ctx, ...@@ -1256,7 +1256,7 @@ wsrep_cb_status_t wsrep_sst_donate_cb (void* app_ctx, void* recv_ctx,
/* This will be reset when sync callback is called. /* This will be reset when sync callback is called.
* Should we set wsrep_ready to FALSE here too? */ * Should we set wsrep_ready to FALSE here too? */
wsrep_config_state.set(WSREP_MEMBER_DONOR); wsrep_config_state->set(WSREP_MEMBER_DONOR);
const char* method = (char*)msg; const char* method = (char*)msg;
size_t method_len = strlen (method); size_t method_len = strlen (method);
......
...@@ -233,7 +233,7 @@ class Config_state ...@@ -233,7 +233,7 @@ class Config_state
} /* namespace wsp */ } /* namespace wsp */
extern wsp::Config_state wsrep_config_state; extern wsp::Config_state *wsrep_config_state;
namespace wsp { namespace wsp {
/* a class to manage env vars array */ /* a class to manage env vars array */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment