Loading mysql-test/r/status.result 0 → 100644 +6 −0 Original line number Diff line number Diff line Variable_name Value Table_locks_immediate 5 Table_locks_waited 0 Variable_name Value Table_locks_immediate 8 Table_locks_waited 1 mysql-test/t/status.test 0 → 100644 +23 −0 Original line number Diff line number Diff line 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%'; mysys/thr_lock.c +7 −1 Original line number Diff line number Diff line Loading @@ -83,7 +83,7 @@ multiple read locks. #include <errno.h> my_bool thr_lock_inited=0; ulong locks_immediate = 0L, locks_waited = 0L; /* The following constants are only for debug output */ #define MAX_THREADS 100 Loading Loading @@ -387,6 +387,7 @@ static my_bool wait_for_lock(struct st_lock_list *wait, THR_LOCK_DATA *data, else { result=0; ++locks_waited; if (data->lock->get_status) (*data->lock->get_status)(data->status_param); check_locks(data->lock,"got wait_for_lock",0); Loading Loading @@ -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); if (lock->get_status) (*lock->get_status)(data->status_param); ++locks_immediate; goto end; } if (lock->write.data->type == TL_WRITE_ONLY) Loading @@ -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) lock->read_no_write_count++; check_locks(lock,"read lock with no write locks",0); ++locks_immediate; goto end; } /* Can't get lock yet; Wait for it */ Loading Loading @@ -501,6 +504,7 @@ int thr_lock(THR_LOCK_DATA *data,enum thr_lock_type lock_type) data->cond=get_cond(); if (lock->get_status) (*lock->get_status)(data->status_param); ++locks_immediate; goto end; } } Loading Loading @@ -535,6 +539,7 @@ int thr_lock(THR_LOCK_DATA *data,enum thr_lock_type lock_type) check_locks(lock,"second write lock",0); if (data->lock->get_status) (*data->lock->get_status)(data->status_param); ++locks_immediate; goto end; } DBUG_PRINT("lock",("write locked by thread: %ld", Loading @@ -560,6 +565,7 @@ int thr_lock(THR_LOCK_DATA *data,enum thr_lock_type lock_type) if (data->lock->get_status) (*data->lock->get_status)(data->status_param); check_locks(lock,"only write lock",0); ++locks_immediate; goto end; } } Loading sql/mysqld.cc +3 −0 Original line number Diff line number Diff line Loading @@ -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_rows_in_use,delayed_insert_errors,flush_time, thread_created; ulong filesort_rows, filesort_range_count, filesort_scan_count; extern "C" ulong locks_immediate, locks_waited; ulong filesort_merge_passes; ulong select_range_check_count, select_range_count, select_scan_count; ulong select_full_range_join_count,select_full_join_count; Loading Loading @@ -2804,6 +2805,8 @@ struct show_var_st status_vars[]= { {"Sort_range", (char*) &filesort_range_count, SHOW_LONG}, {"Sort_rows", (char*) &filesort_rows, 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_created", (char*) &thread_created, SHOW_LONG_CONST}, {"Threads_connected", (char*) &thread_count, SHOW_INT_CONST}, Loading sql/sql_base.cc +3 −1 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ TABLE *unused_tables; /* 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, const char *name, const char *alias, bool locked); Loading Loading @@ -1166,7 +1167,8 @@ bool wait_for_tables(THD *thd) { /* Now we can open all tables without any interference */ 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); thd->proc_info=0; Loading Loading
mysql-test/r/status.result 0 → 100644 +6 −0 Original line number Diff line number Diff line Variable_name Value Table_locks_immediate 5 Table_locks_waited 0 Variable_name Value Table_locks_immediate 8 Table_locks_waited 1
mysql-test/t/status.test 0 → 100644 +23 −0 Original line number Diff line number Diff line 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%';
mysys/thr_lock.c +7 −1 Original line number Diff line number Diff line Loading @@ -83,7 +83,7 @@ multiple read locks. #include <errno.h> my_bool thr_lock_inited=0; ulong locks_immediate = 0L, locks_waited = 0L; /* The following constants are only for debug output */ #define MAX_THREADS 100 Loading Loading @@ -387,6 +387,7 @@ static my_bool wait_for_lock(struct st_lock_list *wait, THR_LOCK_DATA *data, else { result=0; ++locks_waited; if (data->lock->get_status) (*data->lock->get_status)(data->status_param); check_locks(data->lock,"got wait_for_lock",0); Loading Loading @@ -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); if (lock->get_status) (*lock->get_status)(data->status_param); ++locks_immediate; goto end; } if (lock->write.data->type == TL_WRITE_ONLY) Loading @@ -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) lock->read_no_write_count++; check_locks(lock,"read lock with no write locks",0); ++locks_immediate; goto end; } /* Can't get lock yet; Wait for it */ Loading Loading @@ -501,6 +504,7 @@ int thr_lock(THR_LOCK_DATA *data,enum thr_lock_type lock_type) data->cond=get_cond(); if (lock->get_status) (*lock->get_status)(data->status_param); ++locks_immediate; goto end; } } Loading Loading @@ -535,6 +539,7 @@ int thr_lock(THR_LOCK_DATA *data,enum thr_lock_type lock_type) check_locks(lock,"second write lock",0); if (data->lock->get_status) (*data->lock->get_status)(data->status_param); ++locks_immediate; goto end; } DBUG_PRINT("lock",("write locked by thread: %ld", Loading @@ -560,6 +565,7 @@ int thr_lock(THR_LOCK_DATA *data,enum thr_lock_type lock_type) if (data->lock->get_status) (*data->lock->get_status)(data->status_param); check_locks(lock,"only write lock",0); ++locks_immediate; goto end; } } Loading
sql/mysqld.cc +3 −0 Original line number Diff line number Diff line Loading @@ -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_rows_in_use,delayed_insert_errors,flush_time, thread_created; ulong filesort_rows, filesort_range_count, filesort_scan_count; extern "C" ulong locks_immediate, locks_waited; ulong filesort_merge_passes; ulong select_range_check_count, select_range_count, select_scan_count; ulong select_full_range_join_count,select_full_join_count; Loading Loading @@ -2804,6 +2805,8 @@ struct show_var_st status_vars[]= { {"Sort_range", (char*) &filesort_range_count, SHOW_LONG}, {"Sort_rows", (char*) &filesort_rows, 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_created", (char*) &thread_created, SHOW_LONG_CONST}, {"Threads_connected", (char*) &thread_count, SHOW_INT_CONST}, Loading
sql/sql_base.cc +3 −1 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ TABLE *unused_tables; /* 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, const char *name, const char *alias, bool locked); Loading Loading @@ -1166,7 +1167,8 @@ bool wait_for_tables(THD *thd) { /* Now we can open all tables without any interference */ 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); thd->proc_info=0; Loading