Table_locks_waited

Table_locks_immediate
parent 7c5db0d3
Variable_name Value
Table_locks_immediate 5
Table_locks_waited 0
Variable_name Value
Table_locks_immediate 8
Table_locks_waited 1
connect (con1,localhost,root,,test,0,mysql-master.sock);
connect (con2,localhost,root,,test,0,mysql-master.sock);
#don't polute binlog
show status like 'Table_lock%';
connection con1;
SET SQL_LOG_BIN=0;
drop table if exists t1;
create table t1(n int);
insert into t1 values(1);
connection con2;
lock tables t1 read;
unlock tables;
lock tables t1 read;
connection con1;
send update t1 set n = 3;
connection con2;
sleep 0.5;
unlock tables;
connection con1;
reap;
show status like 'Table_lock%';
...@@ -83,7 +83,7 @@ multiple read locks. ...@@ -83,7 +83,7 @@ multiple read locks.
#include <errno.h> #include <errno.h>
my_bool thr_lock_inited=0; my_bool thr_lock_inited=0;
ulong locks_immediate = 0L, locks_waited = 0L;
/* The following constants are only for debug output */ /* The following constants are only for debug output */
#define MAX_THREADS 100 #define MAX_THREADS 100
...@@ -387,6 +387,7 @@ static my_bool wait_for_lock(struct st_lock_list *wait, THR_LOCK_DATA *data, ...@@ -387,6 +387,7 @@ static my_bool wait_for_lock(struct st_lock_list *wait, THR_LOCK_DATA *data,
else else
{ {
result=0; result=0;
++locks_waited;
if (data->lock->get_status) if (data->lock->get_status)
(*data->lock->get_status)(data->status_param); (*data->lock->get_status)(data->status_param);
check_locks(data->lock,"got wait_for_lock",0); check_locks(data->lock,"got wait_for_lock",0);
...@@ -447,6 +448,7 @@ int thr_lock(THR_LOCK_DATA *data,enum thr_lock_type lock_type) ...@@ -447,6 +448,7 @@ int thr_lock(THR_LOCK_DATA *data,enum thr_lock_type lock_type)
check_locks(lock,"read lock with old write lock",0); check_locks(lock,"read lock with old write lock",0);
if (lock->get_status) if (lock->get_status)
(*lock->get_status)(data->status_param); (*lock->get_status)(data->status_param);
++locks_immediate;
goto end; goto end;
} }
if (lock->write.data->type == TL_WRITE_ONLY) if (lock->write.data->type == TL_WRITE_ONLY)
...@@ -470,6 +472,7 @@ int thr_lock(THR_LOCK_DATA *data,enum thr_lock_type lock_type) ...@@ -470,6 +472,7 @@ int thr_lock(THR_LOCK_DATA *data,enum thr_lock_type lock_type)
if ((int) lock_type == (int) TL_READ_NO_INSERT) if ((int) lock_type == (int) TL_READ_NO_INSERT)
lock->read_no_write_count++; lock->read_no_write_count++;
check_locks(lock,"read lock with no write locks",0); check_locks(lock,"read lock with no write locks",0);
++locks_immediate;
goto end; goto end;
} }
/* Can't get lock yet; Wait for it */ /* Can't get lock yet; Wait for it */
...@@ -501,6 +504,7 @@ int thr_lock(THR_LOCK_DATA *data,enum thr_lock_type lock_type) ...@@ -501,6 +504,7 @@ int thr_lock(THR_LOCK_DATA *data,enum thr_lock_type lock_type)
data->cond=get_cond(); data->cond=get_cond();
if (lock->get_status) if (lock->get_status)
(*lock->get_status)(data->status_param); (*lock->get_status)(data->status_param);
++locks_immediate;
goto end; goto end;
} }
} }
...@@ -535,6 +539,7 @@ int thr_lock(THR_LOCK_DATA *data,enum thr_lock_type lock_type) ...@@ -535,6 +539,7 @@ int thr_lock(THR_LOCK_DATA *data,enum thr_lock_type lock_type)
check_locks(lock,"second write lock",0); check_locks(lock,"second write lock",0);
if (data->lock->get_status) if (data->lock->get_status)
(*data->lock->get_status)(data->status_param); (*data->lock->get_status)(data->status_param);
++locks_immediate;
goto end; goto end;
} }
DBUG_PRINT("lock",("write locked by thread: %ld", DBUG_PRINT("lock",("write locked by thread: %ld",
...@@ -560,6 +565,7 @@ int thr_lock(THR_LOCK_DATA *data,enum thr_lock_type lock_type) ...@@ -560,6 +565,7 @@ int thr_lock(THR_LOCK_DATA *data,enum thr_lock_type lock_type)
if (data->lock->get_status) if (data->lock->get_status)
(*data->lock->get_status)(data->status_param); (*data->lock->get_status)(data->status_param);
check_locks(lock,"only write lock",0); check_locks(lock,"only write lock",0);
++locks_immediate;
goto end; goto end;
} }
} }
......
...@@ -260,6 +260,7 @@ ulong query_id=1L,long_query_count,long_query_time,aborted_threads, ...@@ -260,6 +260,7 @@ ulong query_id=1L,long_query_count,long_query_time,aborted_threads,
delayed_queue_size,delayed_insert_threads,delayed_insert_writes, delayed_queue_size,delayed_insert_threads,delayed_insert_writes,
delayed_rows_in_use,delayed_insert_errors,flush_time, thread_created; delayed_rows_in_use,delayed_insert_errors,flush_time, thread_created;
ulong filesort_rows, filesort_range_count, filesort_scan_count; ulong filesort_rows, filesort_range_count, filesort_scan_count;
extern "C" ulong locks_immediate, locks_waited;
ulong filesort_merge_passes; ulong filesort_merge_passes;
ulong select_range_check_count, select_range_count, select_scan_count; ulong select_range_check_count, select_range_count, select_scan_count;
ulong select_full_range_join_count,select_full_join_count; ulong select_full_range_join_count,select_full_join_count;
...@@ -2804,6 +2805,8 @@ struct show_var_st status_vars[]= { ...@@ -2804,6 +2805,8 @@ struct show_var_st status_vars[]= {
{"Sort_range", (char*) &filesort_range_count, SHOW_LONG}, {"Sort_range", (char*) &filesort_range_count, SHOW_LONG},
{"Sort_rows", (char*) &filesort_rows, SHOW_LONG}, {"Sort_rows", (char*) &filesort_rows, SHOW_LONG},
{"Sort_scan", (char*) &filesort_scan_count, SHOW_LONG}, {"Sort_scan", (char*) &filesort_scan_count, SHOW_LONG},
{"Table_locks_immediate", (char*) &locks_immediate, SHOW_LONG},
{"Table_locks_waited", (char*) &locks_waited, SHOW_LONG},
{"Threads_cached", (char*) &cached_thread_count, SHOW_LONG_CONST}, {"Threads_cached", (char*) &cached_thread_count, SHOW_LONG_CONST},
{"Threads_created", (char*) &thread_created, SHOW_LONG_CONST}, {"Threads_created", (char*) &thread_created, SHOW_LONG_CONST},
{"Threads_connected", (char*) &thread_count, SHOW_INT_CONST}, {"Threads_connected", (char*) &thread_count, SHOW_INT_CONST},
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
TABLE *unused_tables; /* Used by mysql_test */ TABLE *unused_tables; /* Used by mysql_test */
HASH open_cache; /* Used by mysql_test */ HASH open_cache; /* Used by mysql_test */
extern "C" ulong locks_waited, locks_immediate;
static int open_unireg_entry(THD *thd,TABLE *entry,const char *db, static int open_unireg_entry(THD *thd,TABLE *entry,const char *db,
const char *name, const char *alias, bool locked); const char *name, const char *alias, bool locked);
...@@ -1166,7 +1167,8 @@ bool wait_for_tables(THD *thd) ...@@ -1166,7 +1167,8 @@ bool wait_for_tables(THD *thd)
{ {
/* Now we can open all tables without any interference */ /* Now we can open all tables without any interference */
thd->proc_info="Reopen tables"; thd->proc_info="Reopen tables";
result=reopen_tables(thd,0,0); if(!(result=reopen_tables(thd,0,0)))
++locks_waited;
} }
pthread_mutex_unlock(&LOCK_open); pthread_mutex_unlock(&LOCK_open);
thd->proc_info=0; thd->proc_info=0;
......
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