[MDEV-8876] Table_lock_waited is not counted if table is write locked Created: 2015-09-30  Updated: 2015-10-28  Resolved: 2015-10-28

Status: Closed
Project: MariaDB Server
Component/s: Locking
Affects Version/s: 10.1.7
Fix Version/s: N/A

Type: Bug Priority: Trivial
Reporter: Michaël de groot Assignee: Unassigned
Resolution: Not a Bug Votes: 0
Labels: None
Environment:

CentOS 6.7



 Description   

Hi,

table_lock_waited is not increased if an INSERT has to wait for a lock table. Reproduce:
1. LOCK TABLE a WRITE;
2. other thread: insert into table a
3. First thread: unlock tables;
4. Observe: SHOW GLOBAL status LIKE 'table_locks_waited';

Command output:

 
MariaDB [hello]> show create table a;
+-------+----------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                           |
+-------+----------------------------------------------------------------------------------------------------------------------------------------+
| a     | CREATE TABLE `a` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 |
+-------+----------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
 
MariaDB [hello]> lock table a write;
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [hello]> 
[2]+  Stopped                 mysql
[root@galera1 my.cnf.d]# fg 1
mysql
 
MariaDB [hello]> insert into a values(null);
 
 
 
 
^Z
[1]+  Stopped                 mysql
[root@galera1 my.cnf.d]# fg 2
mysql
 
MariaDB [hello]> unlock tables;
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [hello]> show global status like 'table_lock%';
+-----------------------+-------+
| Variable_name         | Value |
+-----------------------+-------+
| Table_locks_immediate | 26    |
| Table_locks_waited    | 0     |
+-----------------------+-------+
2 rows in set (0.00 sec)
 
MariaDB [hello]> 
 
mysql  Ver 15.1 Distrib 10.1.7-MariaDB, for Linux (x86_64) using readline 5.1



 Comments   
Comment by Elena Stepanova [ 2015-10-28 ]

Table_locks_waited is a counter for table-level locks, while in this case the inserting thread waits for a metadata lock (it can be seen in SHOW PROCESSLIST output). If you use a READ lock instead, you'll see the counter increase.

Generated at Thu Feb 08 07:30:27 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.