Commit 3d5e32b2 authored by unknown's avatar unknown

Bug#30331 Table_locks_waited shows inaccurate values

The problem is that the Table_locks_waited was incremented only
when the lock request succeed. If a thread waiting for the lock
gets killed or the lock request is aborted, the variable would
not be incremented, leading to inaccurate values in the variable.

The solution is to increment the Table_locks_waited whenever the
lock request is queued. This reflects better the intended behavior
of the variable -- show how many times a lock was waited.


mysql-test/r/lock_multi.result:
  Add test case result for Bug#30331
mysql-test/t/lock_multi.test:
  Add test case for Bug#30331
mysys/thr_lock.c:
  Increment locks_waited whenever the thread is supposed
  to wait for the lock.
parent 8f9e655d
......@@ -143,4 +143,16 @@ connection: default
flush tables;
unlock tables;
drop table t1;
drop table if exists t1,t2;
create table t1 (a int);
flush status;
lock tables t1 read;
show status like 'Table_locks_waited';
Variable_name Value
Table_locks_waited 0
insert into t1 values(1);;
drop table t1;
show status like 'Table_locks_waited';
Variable_name Value
Table_locks_waited 1
End of 5.1 tests
......@@ -439,4 +439,30 @@ connection default;
disconnect flush;
drop table t1;
#
# Bug#30331: Table_locks_waited shows inaccurate values
#
--disable_warnings
drop table if exists t1,t2;
--enable_warnings
create table t1 (a int);
flush status;
lock tables t1 read;
show status like 'Table_locks_waited';
connect (waiter,localhost,root,,);
connection waiter;
--send insert into t1 values(1);
connection default;
let $wait_condition=
select count(*) = 1 from information_schema.processlist
where state = "Locked" and info = "insert into t1 values(1)";
--source include/wait_condition.inc
drop table t1;
disconnect waiter;
connection default;
show status like 'Table_locks_waited';
#show global status like "Table_locks_waited";
--echo End of 5.1 tests
......@@ -405,6 +405,8 @@ wait_for_lock(struct st_lock_list *wait, THR_LOCK_DATA *data,
wait->last= &data->next;
}
statistic_increment(locks_waited, &THR_LOCK_lock);
/* Set up control struct to allow others to abort locks */
thread_var->current_mutex= &data->lock->mutex;
thread_var->current_cond= cond;
......@@ -469,7 +471,6 @@ wait_for_lock(struct st_lock_list *wait, THR_LOCK_DATA *data,
else
{
result= THR_LOCK_SUCCESS;
statistic_increment(locks_waited, &THR_LOCK_lock);
if (data->lock->get_status)
(*data->lock->get_status)(data->status_param, 0);
check_locks(data->lock,"got wait_for_lock",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