Commit 32be7dff authored by Michael Widenius's avatar Michael Widenius

Return to original stage after mysql_lock_tables

Stage "Filling schema table" is now properly shown in 'show processlist'


mysys/mf_keycache.c:
  Simple cleanup with more comments
sql/lock.cc:
  Return to original stage after mysql_lock_tables
  Made 'Table lock' as a true stage
sql/sql_show.cc:
  Restore original stage after get_schema_tables_result
parent c11a054a
...@@ -1020,11 +1020,11 @@ void end_simple_key_cache(SIMPLE_KEY_CACHE_CB *keycache, my_bool cleanup) ...@@ -1020,11 +1020,11 @@ void end_simple_key_cache(SIMPLE_KEY_CACHE_CB *keycache, my_bool cleanup)
*/ */
static void link_into_queue(KEYCACHE_WQUEUE *wqueue, static void link_into_queue(KEYCACHE_WQUEUE *wqueue,
struct st_my_thread_var *thread) struct st_my_thread_var *thread)
{ {
struct st_my_thread_var *last; struct st_my_thread_var *last;
DBUG_ASSERT(!thread->next && !thread->prev); DBUG_ASSERT(!thread->next && !thread->prev);
if (! (last= wqueue->last_thread)) if (! (last= wqueue->last_thread))
{ {
/* Queue is empty */ /* Queue is empty */
...@@ -1033,10 +1033,15 @@ static void link_into_queue(KEYCACHE_WQUEUE *wqueue, ...@@ -1033,10 +1033,15 @@ static void link_into_queue(KEYCACHE_WQUEUE *wqueue,
} }
else else
{ {
thread->prev= last->next->prev; DBUG_ASSERT(last->next->prev == &last->next);
last->next->prev= &thread->next; /* Add backlink to previous element */
thread->next= last->next; thread->prev= last->next->prev;
last->next= thread; /* Fix first in list to point backwords to current */
last->next->prev= &thread->next;
/* Next should point to the first element in list */
thread->next= last->next;
/* Fix old element to point to new one */
last->next= thread;
} }
wqueue->last_thread= thread; wqueue->last_thread= thread;
} }
...@@ -1057,17 +1062,22 @@ static void link_into_queue(KEYCACHE_WQUEUE *wqueue, ...@@ -1057,17 +1062,22 @@ static void link_into_queue(KEYCACHE_WQUEUE *wqueue,
*/ */
static void unlink_from_queue(KEYCACHE_WQUEUE *wqueue, static void unlink_from_queue(KEYCACHE_WQUEUE *wqueue,
struct st_my_thread_var *thread) struct st_my_thread_var *thread)
{ {
KEYCACHE_DBUG_PRINT("unlink_from_queue", ("thread %ld", thread->id)); KEYCACHE_DBUG_PRINT("unlink_from_queue", ("thread %ld", thread->id));
DBUG_ASSERT(thread->next && thread->prev); DBUG_ASSERT(thread->next && thread->prev);
if (thread->next == thread) if (thread->next == thread)
{
/* The queue contains only one member */ /* The queue contains only one member */
wqueue->last_thread= NULL; wqueue->last_thread= NULL;
}
else else
{ {
/* Remove current element from list */
thread->next->prev= thread->prev; thread->next->prev= thread->prev;
*thread->prev=thread->next; *thread->prev= thread->next;
/* If first element, change list pointer to point to previous element */
if (wqueue->last_thread == thread) if (wqueue->last_thread == thread)
wqueue->last_thread= STRUCT_PTR(struct st_my_thread_var, next, wqueue->last_thread= STRUCT_PTR(struct st_my_thread_var, next,
thread->prev); thread->prev);
...@@ -1111,10 +1121,10 @@ static void wait_on_queue(KEYCACHE_WQUEUE *wqueue, ...@@ -1111,10 +1121,10 @@ static void wait_on_queue(KEYCACHE_WQUEUE *wqueue,
{ {
struct st_my_thread_var *last; struct st_my_thread_var *last;
struct st_my_thread_var *thread= my_thread_var; struct st_my_thread_var *thread= my_thread_var;
/* Add to queue. */
DBUG_ASSERT(!thread->next); DBUG_ASSERT(!thread->next);
DBUG_ASSERT(!thread->prev); /* Not required, but must be true anyway. */ DBUG_ASSERT(!thread->prev); /* Not required, but must be true anyway. */
/* Add to queue. */
if (! (last= wqueue->last_thread)) if (! (last= wqueue->last_thread))
thread->next= thread; thread->next= thread;
else else
...@@ -1125,7 +1135,7 @@ static void wait_on_queue(KEYCACHE_WQUEUE *wqueue, ...@@ -1125,7 +1135,7 @@ static void wait_on_queue(KEYCACHE_WQUEUE *wqueue,
wqueue->last_thread= thread; wqueue->last_thread= thread;
/* /*
Wait until thread is removed from queue by the signalling thread. Wait until thread is removed from queue by the signaling thread.
The loop protects against stray signals. The loop protects against stray signals.
*/ */
do do
...@@ -1163,10 +1173,11 @@ static void release_whole_queue(KEYCACHE_WQUEUE *wqueue) ...@@ -1163,10 +1173,11 @@ static void release_whole_queue(KEYCACHE_WQUEUE *wqueue)
if (!(last= wqueue->last_thread)) if (!(last= wqueue->last_thread))
return; return;
next= last->next; next= last->next; /* First (oldest) element */
do do
{ {
thread=next; thread=next;
DBUG_ASSERT(thread);
KEYCACHE_DBUG_PRINT("release_whole_queue: signal", KEYCACHE_DBUG_PRINT("release_whole_queue: signal",
("thread %ld", thread->id)); ("thread %ld", thread->id));
/* Signal the thread. */ /* Signal the thread. */
......
...@@ -301,15 +301,16 @@ bool mysql_lock_tables(THD *thd, MYSQL_LOCK *sql_lock, uint flags) ...@@ -301,15 +301,16 @@ bool mysql_lock_tables(THD *thd, MYSQL_LOCK *sql_lock, uint flags)
int rc= 1; int rc= 1;
ulong timeout= (flags & MYSQL_LOCK_IGNORE_TIMEOUT) ? ulong timeout= (flags & MYSQL_LOCK_IGNORE_TIMEOUT) ?
LONG_TIMEOUT : thd->variables.lock_wait_timeout; LONG_TIMEOUT : thd->variables.lock_wait_timeout;
PSI_stage_info org_stage;
DBUG_ENTER("mysql_lock_tables(sql_lock)"); DBUG_ENTER("mysql_lock_tables(sql_lock)");
THD_STAGE_INFO(thd, stage_system_lock); thd->enter_stage(&stage_system_lock, &org_stage, __func__, __FILE__,
__LINE__);
if (sql_lock->table_count && lock_external(thd, sql_lock->table, if (sql_lock->table_count && lock_external(thd, sql_lock->table,
sql_lock->table_count)) sql_lock->table_count))
goto end; goto end;
thd_proc_info(thd, "Table lock"); THD_STAGE_INFO(thd, stage_table_lock);
/* Copy the lock data array. thr_multi_lock() reorders its contents. */ /* Copy the lock data array. thr_multi_lock() reorders its contents. */
memmove(sql_lock->locks + sql_lock->lock_count, sql_lock->locks, memmove(sql_lock->locks + sql_lock->lock_count, sql_lock->locks,
...@@ -323,7 +324,7 @@ bool mysql_lock_tables(THD *thd, MYSQL_LOCK *sql_lock, uint flags) ...@@ -323,7 +324,7 @@ bool mysql_lock_tables(THD *thd, MYSQL_LOCK *sql_lock, uint flags)
(void) unlock_external(thd, sql_lock->table, sql_lock->table_count); (void) unlock_external(thd, sql_lock->table, sql_lock->table_count);
end: end:
THD_STAGE_INFO(thd, stage_after_table_lock); THD_STAGE_INFO(thd, org_stage);
if (thd->killed) if (thd->killed)
{ {
......
...@@ -9458,6 +9458,8 @@ PSI_stage_info stage_sql_thd_waiting_until_delay= { 0, "Waiting until MASTER_DEL ...@@ -9458,6 +9458,8 @@ PSI_stage_info stage_sql_thd_waiting_until_delay= { 0, "Waiting until MASTER_DEL
PSI_stage_info stage_storing_result_in_query_cache= { 0, "storing result in query cache", 0}; PSI_stage_info stage_storing_result_in_query_cache= { 0, "storing result in query cache", 0};
PSI_stage_info stage_storing_row_into_queue= { 0, "storing row into queue", 0}; PSI_stage_info stage_storing_row_into_queue= { 0, "storing row into queue", 0};
PSI_stage_info stage_system_lock= { 0, "System lock", 0}; PSI_stage_info stage_system_lock= { 0, "System lock", 0};
PSI_stage_info stage_table_lock= { 0, "Table lock", 0};
PSI_stage_info stage_filling_schema_table= { 0, "Filling schema table", 0};
PSI_stage_info stage_update= { 0, "update", 0}; PSI_stage_info stage_update= { 0, "update", 0};
PSI_stage_info stage_updating= { 0, "updating", 0}; PSI_stage_info stage_updating= { 0, "updating", 0};
PSI_stage_info stage_updating_main_table= { 0, "updating main table", 0}; PSI_stage_info stage_updating_main_table= { 0, "updating main table", 0};
...@@ -9591,6 +9593,8 @@ PSI_stage_info *all_server_stages[]= ...@@ -9591,6 +9593,8 @@ PSI_stage_info *all_server_stages[]=
& stage_storing_result_in_query_cache, & stage_storing_result_in_query_cache,
& stage_storing_row_into_queue, & stage_storing_row_into_queue,
& stage_system_lock, & stage_system_lock,
& stage_table_lock,
& stage_filling_schema_table,
& stage_update, & stage_update,
& stage_updating, & stage_updating,
& stage_updating_main_table, & stage_updating_main_table,
......
...@@ -413,6 +413,8 @@ extern PSI_stage_info stage_statistics; ...@@ -413,6 +413,8 @@ extern PSI_stage_info stage_statistics;
extern PSI_stage_info stage_storing_result_in_query_cache; extern PSI_stage_info stage_storing_result_in_query_cache;
extern PSI_stage_info stage_storing_row_into_queue; extern PSI_stage_info stage_storing_row_into_queue;
extern PSI_stage_info stage_system_lock; extern PSI_stage_info stage_system_lock;
extern PSI_stage_info stage_table_lock;
extern PSI_stage_info stage_filling_schema_table;
extern PSI_stage_info stage_update; extern PSI_stage_info stage_update;
extern PSI_stage_info stage_updating; extern PSI_stage_info stage_updating;
extern PSI_stage_info stage_updating_main_table; extern PSI_stage_info stage_updating_main_table;
......
...@@ -8081,12 +8081,13 @@ bool get_schema_tables_result(JOIN *join, ...@@ -8081,12 +8081,13 @@ bool get_schema_tables_result(JOIN *join,
THD *thd= join->thd; THD *thd= join->thd;
LEX *lex= thd->lex; LEX *lex= thd->lex;
bool result= 0; bool result= 0;
const char *old_proc_info; PSI_stage_info org_stage;
DBUG_ENTER("get_schema_tables_result"); DBUG_ENTER("get_schema_tables_result");
Warnings_only_error_handler err_handler; Warnings_only_error_handler err_handler;
thd->push_internal_handler(&err_handler); thd->push_internal_handler(&err_handler);
old_proc_info= thd_proc_info(thd, "Filling schema table"); thd->enter_stage(&stage_filling_schema_table, &org_stage, __func__, __FILE__,
__LINE__);
JOIN_TAB *tab; JOIN_TAB *tab;
for (tab= first_linear_tab(join, WITHOUT_BUSH_ROOTS, WITH_CONST_TABLES); for (tab= first_linear_tab(join, WITHOUT_BUSH_ROOTS, WITH_CONST_TABLES);
...@@ -8190,7 +8191,7 @@ bool get_schema_tables_result(JOIN *join, ...@@ -8190,7 +8191,7 @@ bool get_schema_tables_result(JOIN *join,
} }
else if (result) else if (result)
my_error(ER_UNKNOWN_ERROR, MYF(0)); my_error(ER_UNKNOWN_ERROR, MYF(0));
thd_proc_info(thd, old_proc_info); THD_STAGE_INFO(thd, org_stage);
DBUG_RETURN(result); DBUG_RETURN(result);
} }
......
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