1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00
This commit is contained in:
Sergei Golubchik
2014-05-07 10:04:30 +02:00
parent 7226287c06
commit 04bce7b569
208 changed files with 3026 additions and 1138 deletions

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
/* Copyright (c) 2008, 2013, 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
@@ -38,22 +38,32 @@
/** Size of the mutex instances array. @sa mutex_array */
ulong mutex_max;
/** True when @c mutex_array is full. */
bool mutex_full;
/** Number of mutexes instance lost. @sa mutex_array */
ulong mutex_lost;
/** Size of the rwlock instances array. @sa rwlock_array */
ulong rwlock_max;
/** True when @c rwlock_array is full. */
bool rwlock_full;
/** Number or rwlock instances lost. @sa rwlock_array */
ulong rwlock_lost;
/** Size of the conditions instances array. @sa cond_array */
ulong cond_max;
/** True when @c cond_array is full. */
bool cond_full;
/** Number of conditions instances lost. @sa cond_array */
ulong cond_lost;
/** Size of the thread instances array. @sa thread_array */
ulong thread_max;
/** True when @c thread_array is full. */
bool thread_full;
/** Number or thread instances lost. @sa thread_array */
ulong thread_lost;
/** Size of the file instances array. @sa file_array */
ulong file_max;
/** True when @c file_array is full. */
bool file_full;
/** Number of file instances lost. @sa file_array */
ulong file_lost;
/**
@@ -61,14 +71,20 @@ ulong file_lost;
Signed value, for easier comparisons with a file descriptor number.
*/
long file_handle_max;
/** True when @c file_handle_array is full. */
bool file_handle_full;
/** Number of file handle lost. @sa file_handle_array */
ulong file_handle_lost;
/** Size of the table instances array. @sa table_array */
ulong table_max;
/** True when @c table_array is full. */
bool table_full;
/** Number of table instances lost. @sa table_array */
ulong table_lost;
/** Size of the socket instances array. @sa socket_array */
ulong socket_max;
/** True when @c socket_array is full. */
bool socket_full;
/** Number of socket instances lost. @sa socket_array */
ulong socket_lost;
/** Number of EVENTS_WAITS_HISTORY records per thread. */
@@ -185,20 +201,28 @@ int init_instruments(const PFS_global_param *param)
DBUG_ASSERT(wait_class_max != 0);
mutex_max= param->m_mutex_sizing;
mutex_full= false;
mutex_lost= 0;
rwlock_max= param->m_rwlock_sizing;
rwlock_full= false;
rwlock_lost= 0;
cond_max= param->m_cond_sizing;
cond_full= false;
cond_lost= 0;
file_max= param->m_file_sizing;
file_full= false;
file_lost= 0;
file_handle_max= param->m_file_handle_sizing;
file_handle_full= false;
file_handle_lost= 0;
table_max= param->m_table_sizing;
table_full= false;
table_lost= 0;
thread_max= param->m_thread_sizing;
thread_full= false;
thread_lost= 0;
socket_max= param->m_socket_sizing;
socket_full= false;
socket_lost= 0;
events_waits_history_per_thread= param->m_events_waits_history_sizing;
@@ -601,6 +625,17 @@ PFS_mutex* create_mutex(PFS_mutex_class *klass, const void *identity)
uint attempts= 0;
PFS_mutex *pfs;
if (mutex_full)
{
/*
This is a safety plug.
When mutex_array is severely undersized,
do not spin to death for each call.
*/
mutex_lost++;
return NULL;
}
while (++attempts <= mutex_max)
{
/*
@@ -645,6 +680,15 @@ PFS_mutex* create_mutex(PFS_mutex_class *klass, const void *identity)
}
mutex_lost++;
/*
Race condition.
The mutex_array might not be full if a concurrent thread
called destroy_mutex() during the scan, leaving one
empty slot we did not find.
However, 99.999 percent full tables or 100 percent full tables
are treated the same here, we declare the array overloaded.
*/
mutex_full= true;
return NULL;
}
@@ -662,6 +706,7 @@ void destroy_mutex(PFS_mutex *pfs)
if (klass->is_singleton())
klass->m_singleton= NULL;
pfs->m_lock.allocated_to_free();
mutex_full= false;
}
/**
@@ -677,6 +722,12 @@ PFS_rwlock* create_rwlock(PFS_rwlock_class *klass, const void *identity)
uint attempts= 0;
PFS_rwlock *pfs;
if (rwlock_full)
{
rwlock_lost++;
return NULL;
}
while (++attempts <= rwlock_max)
{
/* See create_mutex() */
@@ -705,6 +756,7 @@ PFS_rwlock* create_rwlock(PFS_rwlock_class *klass, const void *identity)
}
rwlock_lost++;
rwlock_full= true;
return NULL;
}
@@ -722,6 +774,7 @@ void destroy_rwlock(PFS_rwlock *pfs)
if (klass->is_singleton())
klass->m_singleton= NULL;
pfs->m_lock.allocated_to_free();
rwlock_full= false;
}
/**
@@ -737,6 +790,12 @@ PFS_cond* create_cond(PFS_cond_class *klass, const void *identity)
uint attempts= 0;
PFS_cond *pfs;
if (cond_full)
{
cond_lost++;
return NULL;
}
while (++attempts <= cond_max)
{
/* See create_mutex() */
@@ -763,6 +822,7 @@ PFS_cond* create_cond(PFS_cond_class *klass, const void *identity)
}
cond_lost++;
cond_full= true;
return NULL;
}
@@ -780,6 +840,7 @@ void destroy_cond(PFS_cond *pfs)
if (klass->is_singleton())
klass->m_singleton= NULL;
pfs->m_lock.allocated_to_free();
cond_full= false;
}
PFS_thread* PFS_thread::get_current_thread()
@@ -791,7 +852,7 @@ PFS_thread* PFS_thread::get_current_thread()
void PFS_thread::reset_session_connect_attrs()
{
m_session_connect_attrs_length= 0;
m_session_connect_attrs_cs= NULL;
m_session_connect_attrs_cs_number= 0;
if ((m_session_connect_attrs != NULL) &&
(session_connect_attrs_size_per_thread > 0) )
@@ -818,6 +879,12 @@ PFS_thread* create_thread(PFS_thread_class *klass, const void *identity,
uint attempts= 0;
PFS_thread *pfs;
if (thread_full)
{
thread_lost++;
return NULL;
}
while (++attempts <= thread_max)
{
/* See create_mutex() */
@@ -833,6 +900,8 @@ PFS_thread* create_thread(PFS_thread_class *klass, const void *identity,
pfs->m_parent_thread_internal_id= 0;
pfs->m_processlist_id= processlist_id;
pfs->m_event_id= 1;
pfs->m_stmt_lock.set_allocated();
pfs->m_session_lock.set_allocated();
pfs->m_enabled= true;
pfs->m_class= klass;
pfs->m_events_waits_current= & pfs->m_events_waits_stack[WAIT_STACK_BOTTOM];
@@ -860,11 +929,9 @@ PFS_thread* create_thread(PFS_thread_class *klass, const void *identity,
pfs->m_dbname_length= 0;
pfs->m_command= 0;
pfs->m_start_time= 0;
pfs->m_processlist_state_ptr= NULL;
pfs->m_processlist_state_length= 0;
pfs->m_processlist_info_ptr= NULL;
pfs->m_stage= 0;
pfs->m_processlist_info[0]= '\0';
pfs->m_processlist_info_length= 0;
pfs->m_processlist_lock.set_allocated();
pfs->m_host= NULL;
pfs->m_user= NULL;
@@ -942,6 +1009,7 @@ PFS_thread* create_thread(PFS_thread_class *klass, const void *identity,
}
thread_lost++;
thread_full= true;
return NULL;
}
@@ -1053,6 +1121,7 @@ void destroy_thread(PFS_thread *pfs)
pfs->m_digest_hash_pins= NULL;
}
pfs->m_lock.allocated_to_free();
thread_full= false;
}
/**
@@ -1203,6 +1272,12 @@ search:
return NULL;
}
if (file_full)
{
file_lost++;
return NULL;
}
while (++attempts <= file_max)
{
/* See create_mutex() */
@@ -1256,6 +1331,7 @@ search:
}
file_lost++;
file_full= true;
return NULL;
}
@@ -1295,6 +1371,7 @@ void destroy_file(PFS_thread *thread, PFS_file *pfs)
if (klass->is_singleton())
klass->m_singleton= NULL;
pfs->m_lock.allocated_to_free();
file_full= false;
}
/**
@@ -1312,6 +1389,12 @@ PFS_table* create_table(PFS_table_share *share, PFS_thread *opening_thread,
uint attempts= 0;
PFS_table *pfs;
if (table_full)
{
table_lost++;
return NULL;
}
while (++attempts <= table_max)
{
/* See create_mutex() */
@@ -1342,6 +1425,7 @@ PFS_table* create_table(PFS_table_share *share, PFS_thread *opening_thread,
}
table_lost++;
table_full= true;
return NULL;
}
@@ -1439,6 +1523,7 @@ void destroy_table(PFS_table *pfs)
DBUG_ASSERT(pfs != NULL);
pfs->m_share->dec_refcount();
pfs->m_lock.allocated_to_free();
table_full= false;
}
/**
@@ -1455,6 +1540,12 @@ PFS_socket* create_socket(PFS_socket_class *klass, const my_socket *fd,
uint attempts= 0;
PFS_socket *pfs;
if (socket_full)
{
socket_lost++;
return NULL;
}
uint fd_used= 0;
uint addr_len_used= addr_len;
@@ -1504,6 +1595,7 @@ PFS_socket* create_socket(PFS_socket_class *klass, const my_socket *fd,
}
socket_lost++;
socket_full= true;
return NULL;
}
@@ -1541,6 +1633,7 @@ void destroy_socket(PFS_socket *pfs)
pfs->m_fd= 0;
pfs->m_addr_len= 0;
pfs->m_lock.allocated_to_free();
socket_full= false;
}
static void reset_mutex_waits_by_instance(void)
@@ -1756,55 +1849,57 @@ void aggregate_all_statements(PFS_statement_stat *from_array,
}
}
void aggregate_thread_stats(PFS_thread *thread)
void aggregate_thread_stats(PFS_thread *thread,
PFS_account *safe_account,
PFS_user *safe_user,
PFS_host *safe_host)
{
if (likely(thread->m_account != NULL))
if (likely(safe_account != NULL))
{
thread->m_account->m_disconnected_count++;
safe_account->m_disconnected_count++;
return;
}
if (thread->m_user != NULL)
thread->m_user->m_disconnected_count++;
if (safe_user != NULL)
safe_user->m_disconnected_count++;
if (thread->m_host != NULL)
thread->m_host->m_disconnected_count++;
if (safe_host != NULL)
safe_host->m_disconnected_count++;
/* There is no global table for connections statistics. */
return;
}
void aggregate_thread(PFS_thread *thread)
void aggregate_thread(PFS_thread *thread,
PFS_account *safe_account,
PFS_user *safe_user,
PFS_host *safe_host)
{
aggregate_thread_waits(thread);
aggregate_thread_stages(thread);
aggregate_thread_statements(thread);
aggregate_thread_stats(thread);
aggregate_thread_waits(thread, safe_account, safe_user, safe_host);
aggregate_thread_stages(thread, safe_account, safe_user, safe_host);
aggregate_thread_statements(thread, safe_account, safe_user, safe_host);
aggregate_thread_stats(thread, safe_account, safe_user, safe_host);
}
void aggregate_thread_waits(PFS_thread *thread)
void aggregate_thread_waits(PFS_thread *thread,
PFS_account *safe_account,
PFS_user *safe_user,
PFS_host *safe_host)
{
if (likely(thread->m_account != NULL))
if (likely(safe_account != NULL))
{
DBUG_ASSERT(thread->m_user == NULL);
DBUG_ASSERT(thread->m_host == NULL);
DBUG_ASSERT(thread->m_account->get_refcount() > 0);
/*
Aggregate EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME
to EVENTS_WAITS_SUMMARY_BY_ACCOUNT_BY_EVENT_NAME.
*/
aggregate_all_event_names(thread->m_instr_class_waits_stats,
thread->m_account->m_instr_class_waits_stats);
safe_account->m_instr_class_waits_stats);
return;
}
if ((thread->m_user != NULL) && (thread->m_host != NULL))
if ((safe_user != NULL) && (safe_host != NULL))
{
DBUG_ASSERT(thread->m_user->get_refcount() > 0);
DBUG_ASSERT(thread->m_host->get_refcount() > 0);
/*
Aggregate EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME to:
- EVENTS_WAITS_SUMMARY_BY_USER_BY_EVENT_NAME
@@ -1812,34 +1907,30 @@ void aggregate_thread_waits(PFS_thread *thread)
in parallel.
*/
aggregate_all_event_names(thread->m_instr_class_waits_stats,
thread->m_user->m_instr_class_waits_stats,
thread->m_host->m_instr_class_waits_stats);
safe_user->m_instr_class_waits_stats,
safe_host->m_instr_class_waits_stats);
return;
}
if (thread->m_user != NULL)
if (safe_user != NULL)
{
DBUG_ASSERT(thread->m_user->get_refcount() > 0);
/*
Aggregate EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME
to EVENTS_WAITS_SUMMARY_BY_USER_BY_EVENT_NAME, directly.
*/
aggregate_all_event_names(thread->m_instr_class_waits_stats,
thread->m_user->m_instr_class_waits_stats);
safe_user->m_instr_class_waits_stats);
return;
}
if (thread->m_host != NULL)
if (safe_host != NULL)
{
DBUG_ASSERT(thread->m_host->get_refcount() > 0);
/*
Aggregate EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME
to EVENTS_WAITS_SUMMARY_BY_HOST_BY_EVENT_NAME, directly.
*/
aggregate_all_event_names(thread->m_instr_class_waits_stats,
thread->m_host->m_instr_class_waits_stats);
safe_host->m_instr_class_waits_stats);
return;
}
@@ -1847,29 +1938,25 @@ void aggregate_thread_waits(PFS_thread *thread)
thread->reset_waits_stats();
}
void aggregate_thread_stages(PFS_thread *thread)
void aggregate_thread_stages(PFS_thread *thread,
PFS_account *safe_account,
PFS_user *safe_user,
PFS_host *safe_host)
{
if (likely(thread->m_account != NULL))
if (likely(safe_account != NULL))
{
DBUG_ASSERT(thread->m_user == NULL);
DBUG_ASSERT(thread->m_host == NULL);
DBUG_ASSERT(thread->m_account->get_refcount() > 0);
/*
Aggregate EVENTS_STAGES_SUMMARY_BY_THREAD_BY_EVENT_NAME
to EVENTS_STAGES_SUMMARY_BY_ACCOUNT_BY_EVENT_NAME.
*/
aggregate_all_stages(thread->m_instr_class_stages_stats,
thread->m_account->m_instr_class_stages_stats);
safe_account->m_instr_class_stages_stats);
return;
}
if ((thread->m_user != NULL) && (thread->m_host != NULL))
if ((safe_user != NULL) && (safe_host != NULL))
{
DBUG_ASSERT(thread->m_user->get_refcount() > 0);
DBUG_ASSERT(thread->m_host->get_refcount() > 0);
/*
Aggregate EVENTS_STAGES_SUMMARY_BY_THREAD_BY_EVENT_NAME to:
- EVENTS_STAGES_SUMMARY_BY_USER_BY_EVENT_NAME
@@ -1877,15 +1964,13 @@ void aggregate_thread_stages(PFS_thread *thread)
in parallel.
*/
aggregate_all_stages(thread->m_instr_class_stages_stats,
thread->m_user->m_instr_class_stages_stats,
thread->m_host->m_instr_class_stages_stats);
safe_user->m_instr_class_stages_stats,
safe_host->m_instr_class_stages_stats);
return;
}
if (thread->m_user != NULL)
if (safe_user != NULL)
{
DBUG_ASSERT(thread->m_user->get_refcount() > 0);
/*
Aggregate EVENTS_STAGES_SUMMARY_BY_THREAD_BY_EVENT_NAME to:
- EVENTS_STAGES_SUMMARY_BY_USER_BY_EVENT_NAME
@@ -1893,21 +1978,19 @@ void aggregate_thread_stages(PFS_thread *thread)
in parallel.
*/
aggregate_all_stages(thread->m_instr_class_stages_stats,
thread->m_user->m_instr_class_stages_stats,
safe_user->m_instr_class_stages_stats,
global_instr_class_stages_array);
return;
}
if (thread->m_host != NULL)
if (safe_host != NULL)
{
DBUG_ASSERT(thread->m_host->get_refcount() > 0);
/*
Aggregate EVENTS_STAGES_SUMMARY_BY_THREAD_BY_EVENT_NAME
to EVENTS_STAGES_SUMMARY_BY_HOST_BY_EVENT_NAME, directly.
*/
aggregate_all_stages(thread->m_instr_class_stages_stats,
thread->m_host->m_instr_class_stages_stats);
safe_host->m_instr_class_stages_stats);
return;
}
@@ -1919,29 +2002,25 @@ void aggregate_thread_stages(PFS_thread *thread)
global_instr_class_stages_array);
}
void aggregate_thread_statements(PFS_thread *thread)
void aggregate_thread_statements(PFS_thread *thread,
PFS_account *safe_account,
PFS_user *safe_user,
PFS_host *safe_host)
{
if (likely(thread->m_account != NULL))
if (likely(safe_account != NULL))
{
DBUG_ASSERT(thread->m_user == NULL);
DBUG_ASSERT(thread->m_host == NULL);
DBUG_ASSERT(thread->m_account->get_refcount() > 0);
/*
Aggregate EVENTS_STATEMENTS_SUMMARY_BY_THREAD_BY_EVENT_NAME
to EVENTS_STATEMENTS_SUMMARY_BY_ACCOUNT_BY_EVENT_NAME.
*/
aggregate_all_statements(thread->m_instr_class_statements_stats,
thread->m_account->m_instr_class_statements_stats);
safe_account->m_instr_class_statements_stats);
return;
}
if ((thread->m_user != NULL) && (thread->m_host != NULL))
if ((safe_user != NULL) && (safe_host != NULL))
{
DBUG_ASSERT(thread->m_user->get_refcount() > 0);
DBUG_ASSERT(thread->m_host->get_refcount() > 0);
/*
Aggregate EVENTS_STATEMENT_SUMMARY_BY_THREAD_BY_EVENT_NAME to:
- EVENTS_STATEMENT_SUMMARY_BY_USER_BY_EVENT_NAME
@@ -1949,15 +2028,13 @@ void aggregate_thread_statements(PFS_thread *thread)
in parallel.
*/
aggregate_all_statements(thread->m_instr_class_statements_stats,
thread->m_user->m_instr_class_statements_stats,
thread->m_host->m_instr_class_statements_stats);
safe_user->m_instr_class_statements_stats,
safe_host->m_instr_class_statements_stats);
return;
}
if (thread->m_user != NULL)
if (safe_user != NULL)
{
DBUG_ASSERT(thread->m_user->get_refcount() > 0);
/*
Aggregate EVENTS_STATEMENTS_SUMMARY_BY_THREAD_BY_EVENT_NAME to:
- EVENTS_STATEMENTS_SUMMARY_BY_USER_BY_EVENT_NAME
@@ -1965,21 +2042,19 @@ void aggregate_thread_statements(PFS_thread *thread)
in parallel.
*/
aggregate_all_statements(thread->m_instr_class_statements_stats,
thread->m_user->m_instr_class_statements_stats,
safe_user->m_instr_class_statements_stats,
global_instr_class_statements_array);
return;
}
if (thread->m_host != NULL)
if (safe_host != NULL)
{
DBUG_ASSERT(thread->m_host->get_refcount() > 0);
/*
Aggregate EVENTS_STATEMENTS_SUMMARY_BY_THREAD_BY_EVENT_NAME
to EVENTS_STATEMENTS_SUMMARY_BY_HOST_BY_EVENT_NAME, directly.
*/
aggregate_all_statements(thread->m_instr_class_statements_stats,
thread->m_host->m_instr_class_statements_stats);
safe_host->m_instr_class_statements_stats);
return;
}