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

Innodb_deadlocks status variable counts wrong

Details

    Description

      When I provoke ONE deadlock the Innodb_deadlocks status counter is increase by TWO. This oversubscribes the number of deadlocks happening in a mariadb database.

      Documentation states: Total number of InnoDB deadlocks.
      https://mariadb.com/kb/en/innodb-status-variables/#innodb_deadlocks

      So IMHO it should be 1 and not 2.

      Reproducible:

      SQL> SHOW GLOBAL STATUS LIKE '%dead%';
      +------------------+-------+
      | Variable_name    | Value |
      +------------------+-------+
      | Innodb_deadlocks | 0     |
      +------------------+-------+
       
      Session 1> START TRANSACTION;
      Session 2> START TRANSACTION;
      Session 1> UPDATE test SET data = 'bla' WHERE id = 2;
      Session 2> UPDATE test SET data = 'bla' WHERE id = 1524;
      Session 1> UPDATE test SET data = 'bla' WHERE id = 1524;
      Session 2> UPDATE test SET data = 'bla' WHERE id = 2;
       
      SQL> SHOW GLOBAL STATUS LIKE '%dead%';
      +------------------+-------+
      | Variable_name    | Value |
      +------------------+-------+
      | Innodb_deadlocks | 2     |
      +------------------+-------+
      

      Table:

      CREATE TABLE `test` (
        `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
        `data` varchar(128) DEFAULT NULL,
        `ts` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
        PRIMARY KEY (`id`)
      );
      

      Data:

      INSERT INTO test SELECT NULL, 'Some data', NOW();
      INSERT INTO test SELECT NULL, 'Some data', NOW() FROM test;
      ...
      

      Attachments

        Issue Links

          Activity

            In 10.5.17 the counter is NOT increased at all... The newer versions all counted twice.

            oli Oli Sennhauser added a comment - In 10.5.17 the counter is NOT increased at all... The newer versions all counted twice.

            Hi oli,

            In your test above, you appear to be triggering two deadlocks in session 2, so the counter should increment by two. Is this incorrect? Can you please let me know which version had the other behaviour you are describing so we can compare?

            As for the 10.5.17 issue, please file a separate Jira for this with a test case and we can look into it.

            TheLinuxJedi Andrew Hutchings (Inactive) added a comment - Hi oli , In your test above, you appear to be triggering two deadlocks in session 2, so the counter should increment by two. Is this incorrect? Can you please let me know which version had the other behaviour you are describing so we can compare? As for the 10.5.17 issue, please file a separate Jira for this with a test case and we can look into it.

            Hi @TheLinuxJedi

            No, why 2? The first statement creates the lock, the second statement hangs in the lock or creates the deadlock, depending on which session you are starting... So IHMO the counter should only increase by one (2 sessions, 3-4 locks, but one deadlock).

            This feature seems to have a long history (xtradb). Xtradb supported the counter, then, when xtradb was replaced by innodb, the counter vanished. Then the feature was backported/reimplemented in 10.5. But it seems to not work (see my 1st comment). Then it was improved with 10.6 but now it counts twice.

            10.5.17 -> Innodb_deadlocks = 0
            10.6.17 -> Innodb_deadlocks = 2
            10.11.7 -> Innodb_deadlocks = 2
            11.5.1 -> Innodb_deadlocks = 2

            But should always be 1.

            oli Oli Sennhauser added a comment - Hi @TheLinuxJedi No, why 2? The first statement creates the lock, the second statement hangs in the lock or creates the deadlock, depending on which session you are starting... So IHMO the counter should only increase by one (2 sessions, 3-4 locks, but one deadlock). This feature seems to have a long history (xtradb). Xtradb supported the counter, then, when xtradb was replaced by innodb, the counter vanished. Then the feature was backported/reimplemented in 10.5. But it seems to not work (see my 1st comment). Then it was improved with 10.6 but now it counts twice. 10.5.17 -> Innodb_deadlocks = 0 10.6.17 -> Innodb_deadlocks = 2 10.11.7 -> Innodb_deadlocks = 2 11.5.1 -> Innodb_deadlocks = 2 But should always be 1.

            Ah! I understand now. You are doing things in a different order to the test in the description. OK, then yes, this is a bug. I'll fix the description.

            TheLinuxJedi Andrew Hutchings (Inactive) added a comment - Ah! I understand now. You are doing things in a different order to the test in the description. OK, then yes, this is a bug. I'll fix the description.

            Hello. I can fix this issue as well as mdev-33937. But the questions are:
            1. Should I commit under the 10.6 and then do cherry-pick to another branch or the flow is different?
            2. I think version 10.5 should be removed from the description because it is related to 33937.
            Thanks.

            TheIaroslav Iaroslav Babanin added a comment - Hello. I can fix this issue as well as mdev-33937. But the questions are: 1. Should I commit under the 10.6 and then do cherry-pick to another branch or the flow is different? 2. I think version 10.5 should be removed from the description because it is related to 33937. Thanks.

            TheIaroslav You can fix both bugs as a part of this issue. You can put the patch for 10.5 (lowest version) and 10.6 (if the patch is different from 10.6)

            thiru Thirunarayanan Balathandayuthapani added a comment - TheIaroslav You can fix both bugs as a part of this issue. You can put the patch for 10.5 (lowest version) and 10.6 (if the patch is different from 10.6)

            People

              marko Marko Mäkelä
              oli Oli Sennhauser
              Votes:
              0 Vote for this issue
              Watchers:
              6 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.