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

ER_LOCK_DEADLOCK on concurrent read and insert into already locked gap

Details

    Description

      mysql_ha_read: Got error 149 when reading table and ER_LOCK_DEADLOCK on concurrent reading/updating versioned partitioned table

      Notes:

      • The test case in the given form fails for in the first few attempts, but it can vary on different machines and builds; run with --repeat=N.
      • There are a couple of lines in the middle of the test which are unimportant for the error, but they help with the timing, without them it fails less reliably. The can probably be replaced with a proper synchronization.
      • I am not sure if the deadlock and the error in the log always come together. Please not that the error in the log alone does not make an MTR test fail, because it's currently suppressed in include/mtr_warnings.sql. We are considering removing the suppression, but first we need to check how many of existing tests would be affected. Meanwhile, if you need the test to fail upon the log error, remove the suppression from the file locally.
      • The problem might be not related to versioning, but I couldn't remove either versioning or partitioning from the test case.

      --source include/have_innodb.inc
      --source include/have_partition.inc
       
      CREATE TABLE t1 (
        pk INT,
        c CHAR(32),
        PRIMARY KEY (pk)
      ) ENGINE=InnoDB WITH SYSTEM VERSIONING PARTITION BY HASH(pk) PARTITIONS 2;
       
      INSERT INTO t1 VALUES (1,'foo'),(2,'bar');
      HANDLER t1 OPEN AS h;
       
      --connect (con1,localhost,root,,test)
      --send
        UPDATE t1 SET c = 4;
       
      --connection default
       
      # Two statements below are not required for the scenario,
      # but apparently they help with the timing, it fails better with them
      --error ER_UNKNOWN_TABLE
      HANDLER unknown_handler CLOSE;
      --error ER_NO_SUCH_TABLE
      HANDLER unknown_table OPEN;
       
      HANDLER h READ `PRIMARY` PREV;
       
      # Cleanup
       
      --connection con1
      --reap
      --disconnect con1
      --connection default
      HANDLER h CLOSE;
      DROP TABLE t1;
      

      10.3 4946eb7b

      mysqltest: At line 26: query 'HANDLER h READ `PRIMARY` PREV' failed: 1213: Deadlock found when trying to get lock; try restarting transaction
      

      CURRENT_TEST: bug.error149b
      2019-02-23 21:55:43 19 [ERROR] mysql_ha_read: Got error 149 when reading table 'h'
      

      Attachments

        1. failing_thread.txt
          4 kB
        2. tampering_thread.txt
          4 kB
        3. v.test
          1 kB

        Issue Links

          Activity

            Yes, transaction 1. and 3. is the same transaction trx 2. I didn't write "from step" for brevity. vlad.lesin I don't insist anything, please see task description. You can test it yourself, it does cancel SELECT.

            > What exactly subsystem do you mean?

            I don't mean exact subsystem. I mean user POV.

            midenok Aleksey Midenkov added a comment - Yes, transaction 1. and 3. is the same transaction trx 2. I didn't write "from step" for brevity. vlad.lesin I don't insist anything, please see task description. You can test it yourself, it does cancel SELECT. > What exactly subsystem do you mean? I don't mean exact subsystem. I mean user POV.
            midenok Aleksey Midenkov added a comment - - edited

            vlad.lesin Can you show the test case with ACID violation, please?

            midenok Aleksey Midenkov added a comment - - edited vlad.lesin Can you show the test case with ACID violation, please?

            midenok, ok, here is modified test with different locking order:

            --source include/have_innodb.inc                                                
            --source include/have_debug.inc                                                 
            --source include/have_debug_sync.inc                                            
                                                                                            
            create or replace table t1 (pk int primary key, x int) engine innodb;           
            insert into t1 values (3, 0);                                                   
            start transaction; # trx 1                                                      
            update t1 set x= 1;                                                             
            insert into t1 values (2, 1);                                                   
                                                                                            
            connect (con1,localhost,root,,test);                                            
            SET DEBUG_SYNC="lock_wait_before_suspend SIGNAL trx2_suspended";                
            send select * from t1 for update; # trx 2                                       
                                                                                            
            connection default;                                                             
            SET DEBUG_SYNC="now WAIT_FOR trx2_suspended";                                   
            commit;                                                                         
                                                                                            
            connection con1;                                                                
            --echo # There is no ER_LOCK_DEADLOCK here, as expected                         
            reap;                                                                           
                                                                                            
            connection default;                                                             
            disconnect con1;                                                                
            drop table t1; 
            

            And there is no deadlock error, as expected. As well as there is deadlock error in the original test. What is also expected(I explained it in details in the my previous comment).

            vlad.lesin Vladislav Lesin added a comment - midenok , ok, here is modified test with different locking order: --source include/have_innodb.inc --source include/have_debug.inc --source include/have_debug_sync.inc create or replace table t1 (pk int primary key, x int ) engine innodb; insert into t1 values ( 3 , 0 ); start transaction; # trx 1 update t1 set x= 1 ; insert into t1 values ( 2 , 1 ); connect (con1,localhost,root,,test); SET DEBUG_SYNC= "lock_wait_before_suspend SIGNAL trx2_suspended" ; send select * from t1 for update; # trx 2 connection default ; SET DEBUG_SYNC= "now WAIT_FOR trx2_suspended" ; commit; connection con1; --echo # There is no ER_LOCK_DEADLOCK here, as expected reap; connection default ; disconnect con1; drop table t1; And there is no deadlock error, as expected. As well as there is deadlock error in the original test. What is also expected(I explained it in details in the my previous comment).

            midenok,
            > Can you show the test case with ACID violation, please?
            Ah, I see you did some workaround by moving cursor before its storing and after it's restoring. I need some time to understand how it works with MDEV-20605 fix.

            vlad.lesin Vladislav Lesin added a comment - midenok , > Can you show the test case with ACID violation, please? Ah, I see you did some workaround by moving cursor before its storing and after it's restoring. I need some time to understand how it works with MDEV-20605 fix.

            vlad.lesin recently improved this area in MDEV-34877. Would that change the outcome of the test in the Description?

            marko Marko Mäkelä added a comment - vlad.lesin recently improved this area in MDEV-34877 . Would that change the outcome of the test in the Description?

            People

              vlad.lesin Vladislav Lesin
              elenst Elena Stepanova
              Votes:
              1 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

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