Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-30658

lock_row_lock_current_waits counter in information_schema.innodb_metrics may become negative

    XMLWordPrintable

Details

    Description

      Consider the following test case involving 3 sessions. In the first one run this:

      MariaDB [test]> CREATE TABLE `test` (`col` varchar(10) ) engine=InnoDB;
      Query OK, 0 rows affected (0.106 sec)
       
      MariaDB [test]> insert into test values ('a');
      Query OK, 1 row affected (0.038 sec)
       
      MariaDB [test]> select name, count,time_enabled from information_schema.innodb_metrics where name ='lock_row_lock_current_waits'; 
      +-----------------------------+-------+---------------------+
      | name                        | count | time_enabled        |
      +-----------------------------+-------+---------------------+
      | lock_row_lock_current_waits |     0 | 2023-02-14 18:31:50 |
      +-----------------------------+-------+---------------------+
      1 row in set (0.001 sec)
      

      Now, in the second one update the only row in the InnoDB table created:

      MariaDB [test]> begin;update test set col='c' where col='a';
      Query OK, 0 rows affected (0.000 sec)
       
      Query OK, 1 row affected (0.003 sec)
      Rows matched: 1  Changed: 1  Warnings: 0
      

      In the third one run similar update that will hang waiting for 50 seconds (with default settings):

      MariaDB [test]> begin;update test set col='b' where col='a';
      

      Now in the first session we can see counter increased, reset it and wait a bit:

      MariaDB [test]> select name, count,time_enabled from information_schema.innodb_metrics where name ='lock_row_lock_current_waits'; 
      +-----------------------------+-------+---------------------+
      | name                        | count | time_enabled        |
      +-----------------------------+-------+---------------------+
      | lock_row_lock_current_waits |     1 | 2023-02-14 18:31:50 |
      +-----------------------------+-------+---------------------+
      1 row in set (0.001 sec)
       
      MariaDB [test]> set global innodb_monitor_disable='lock_row_lock_current_waits';
      Query OK, 0 rows affected (0.000 sec)
       
      MariaDB [test]> set global innodb_monitor_reset_all='lock_row_lock_current_waits'; 
      Query OK, 0 rows affected (0.000 sec)
       
      MariaDB [test]> set global innodb_monitor_enable='lock_row_lock_current_waits';
      Query OK, 0 rows affected (0.000 sec)
       
      MariaDB [test]> select name, count,time_enabled from information_schema.innodb_metrics where name ='lock_row_lock_current_waits';
      +-----------------------------+-------+---------------------+
      | name                        | count | time_enabled        |
      +-----------------------------+-------+---------------------+
      | lock_row_lock_current_waits |     0 | 2023-02-15 18:19:42 |
      +-----------------------------+-------+---------------------+
      1 row in set (0.001 sec)
      

      When we get this error message in the third session:

      Query OK, 0 rows affected (0.000 sec)
       
      ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
      MariaDB [test]> 
      

      in the first one we get a negative value of the counter:

      MariaDB [test]> select name, count,time_enabled from information_schema.innodb_metrics where name ='lock_row_lock_current_waits';
      +-----------------------------+-------+---------------------+
      | name                        | count | time_enabled        |
      +-----------------------------+-------+---------------------+
      | lock_row_lock_current_waits |    -1 | 2023-02-15 18:19:42 |
      +-----------------------------+-------+---------------------+
      1 row in set (0.001 sec)
      

      This is a bug and similar bugs were reported (and some fixed) many times for MySQL:

      https://bugs.mysql.com/bug.php?id=73114
      https://bugs.mysql.com/bug.php?id=75966
      https://bugs.mysql.com/bug.php?id=81099
      https://bugs.mysql.com/bug.php?id=79703
      ...

      Attachments

        Issue Links

          Activity

            People

              vlad.lesin Vladislav Lesin
              valerii Valerii Kravchuk
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.