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

insert-intention lock conflicts with waiting ORDINARY lock

Details

    Description

      We have two transactions and one record. The first transaction holds ORDINARY S-lock on the record, the second transaction created waiting ORDINARY X-lock and waits for the first transaction. Then the first transaction requests insert-intention lock on the record. And this lock conflicts with the waiting ORDINARY X-lock of the second transaction. What causes deadlock. Why it should conflict? The first transaction already holds lock on the record. And the second's transaction lock contains "waiting" flag.

      Let's take a look 10.6 code:

      dberr_t                                                                      
      lock_rec_insert_check_and_lock(...)
      {
      ...
            const unsigned type_mode= LOCK_X | LOCK_GAP | LOCK_INSERT_INTENTION;      
       
            if (lock_t *c_lock= lock_rec_other_has_conflicting(type_mode,             
                                                               g.cell(), id,          
                                                               heap_no, trx))         
            {                                                                         
              trx->mutex_lock();                                                      
              err= lock_rec_enqueue_waiting(c_lock, type_mode, id, block->frame,      
                                            heap_no, index, thr, nullptr);            
              trx->mutex_unlock();                                                    
            }
      ...
      }
      

      Neither lock_rec_insert_check_and_lock() nor lock_rec_other_has_conflicting() doesn't check conflicting lock is in waiting state and it already waits for the requesting insert-intention lock transaction.

      The test is attached: ii-conflicts-waiting.test

      Attachments

        Issue Links

          Activity

            vlad.lesin Vladislav Lesin created issue -
            vlad.lesin Vladislav Lesin made changes -
            Field Original Value New Value
            vlad.lesin Vladislav Lesin made changes -
            Description We have two transactions and one record. The first transaction holds ORDINARY S-lock on the record, the second transaction created waiting ORDINARY X-lock and waits for the first transaction. Then the first transaction requests insert-intention lock on the record. And this lock conflicts with the waiting ORDINARY X-lock of the second transaction. What causes deadlock. Why it should conflict? The first transaction already holds stronger lock, then the second transaction. And the second's transaction lock contains "waiting" flag.

            The test is attached: [^ii-conflicts-waiting.test]
            We have two transactions and one record. The first transaction holds ORDINARY S-lock on the record, the second transaction created waiting ORDINARY X-lock and waits for the first transaction. Then the first transaction requests insert-intention lock on the record. And this lock conflicts with the waiting ORDINARY X-lock of the second transaction. What causes deadlock. Why it should conflict? The first transaction already holds stronger lock, then the second transaction. And the second's transaction lock contains "waiting" flag.

            I have not yet checked versions less then 10.6.

            The test is attached: [^ii-conflicts-waiting.test]
            vlad.lesin Vladislav Lesin made changes -
            Description We have two transactions and one record. The first transaction holds ORDINARY S-lock on the record, the second transaction created waiting ORDINARY X-lock and waits for the first transaction. Then the first transaction requests insert-intention lock on the record. And this lock conflicts with the waiting ORDINARY X-lock of the second transaction. What causes deadlock. Why it should conflict? The first transaction already holds stronger lock, then the second transaction. And the second's transaction lock contains "waiting" flag.

            I have not yet checked versions less then 10.6.

            The test is attached: [^ii-conflicts-waiting.test]
            We have two transactions and one record. The first transaction holds ORDINARY S-lock on the record, the second transaction created waiting ORDINARY X-lock and waits for the first transaction. Then the first transaction requests insert-intention lock on the record. And this lock conflicts with the waiting ORDINARY X-lock of the second transaction. What causes deadlock. Why it should conflict? The first transaction already holds stronger lock, then the second transaction. And the second's transaction lock contains "waiting" flag.

            Let's take a look 10.6 code:

            {code:java}
            dberr_t⏎
            lock_rec_insert_check_and_lock(...)
            {
            ...
                  const unsigned type_mode= LOCK_X | LOCK_GAP | LOCK_INSERT_INTENTION;
             
                  if (lock_t *c_lock= lock_rec_other_has_conflicting(type_mode,
                                                                     g.cell(), id,
                                                                     heap_no, trx))
                  {
                    trx->mutex_lock();
                    err= lock_rec_enqueue_waiting(c_lock, type_mode, id, block->frame,
                                                  heap_no, index, thr, nullptr);
                    trx->mutex_unlock();
                  }
            ...
            }
            {code}

            Neither lock_rec_insert_check_and_lock() nor lock_rec_other_has_conflicting() doesn't check conflicting lock is in waiting state and it already waits for the requesting insert-intention lock transaction.

            I have not yet checked versions less then 10.6.

            The test is attached: [^ii-conflicts-waiting.test]
            vlad.lesin Vladislav Lesin made changes -
            Description We have two transactions and one record. The first transaction holds ORDINARY S-lock on the record, the second transaction created waiting ORDINARY X-lock and waits for the first transaction. Then the first transaction requests insert-intention lock on the record. And this lock conflicts with the waiting ORDINARY X-lock of the second transaction. What causes deadlock. Why it should conflict? The first transaction already holds stronger lock, then the second transaction. And the second's transaction lock contains "waiting" flag.

            Let's take a look 10.6 code:

            {code:java}
            dberr_t⏎
            lock_rec_insert_check_and_lock(...)
            {
            ...
                  const unsigned type_mode= LOCK_X | LOCK_GAP | LOCK_INSERT_INTENTION;
             
                  if (lock_t *c_lock= lock_rec_other_has_conflicting(type_mode,
                                                                     g.cell(), id,
                                                                     heap_no, trx))
                  {
                    trx->mutex_lock();
                    err= lock_rec_enqueue_waiting(c_lock, type_mode, id, block->frame,
                                                  heap_no, index, thr, nullptr);
                    trx->mutex_unlock();
                  }
            ...
            }
            {code}

            Neither lock_rec_insert_check_and_lock() nor lock_rec_other_has_conflicting() doesn't check conflicting lock is in waiting state and it already waits for the requesting insert-intention lock transaction.

            I have not yet checked versions less then 10.6.

            The test is attached: [^ii-conflicts-waiting.test]
            We have two transactions and one record. The first transaction holds ORDINARY S-lock on the record, the second transaction created waiting ORDINARY X-lock and waits for the first transaction. Then the first transaction requests insert-intention lock on the record. And this lock conflicts with the waiting ORDINARY X-lock of the second transaction. What causes deadlock. Why it should conflict? The first transaction already holds stronger lock, then the second transaction. And the second's transaction lock contains "waiting" flag.

            Let's take a look 10.6 code:

            {code:java}
            dberr_t
            lock_rec_insert_check_and_lock(...)
            {
            ...
                  const unsigned type_mode= LOCK_X | LOCK_GAP | LOCK_INSERT_INTENTION;
             
                  if (lock_t *c_lock= lock_rec_other_has_conflicting(type_mode,
                                                                     g.cell(), id,
                                                                     heap_no, trx))
                  {
                    trx->mutex_lock();
                    err= lock_rec_enqueue_waiting(c_lock, type_mode, id, block->frame,
                                                  heap_no, index, thr, nullptr);
                    trx->mutex_unlock();
                  }
            ...
            }
            {code}

            Neither lock_rec_insert_check_and_lock() nor lock_rec_other_has_conflicting() doesn't check conflicting lock is in waiting state and it already waits for the requesting insert-intention lock transaction.

            I have not yet checked versions less then 10.6.

            The test is attached: [^ii-conflicts-waiting.test]
            marko Marko Mäkelä made changes -
            Summary insert-intetion lock conflicts with waiting ORDINARY lock insert-intention lock conflicts with waiting ORDINARY lock
            vlad.lesin Vladislav Lesin made changes -
            Description We have two transactions and one record. The first transaction holds ORDINARY S-lock on the record, the second transaction created waiting ORDINARY X-lock and waits for the first transaction. Then the first transaction requests insert-intention lock on the record. And this lock conflicts with the waiting ORDINARY X-lock of the second transaction. What causes deadlock. Why it should conflict? The first transaction already holds stronger lock, then the second transaction. And the second's transaction lock contains "waiting" flag.

            Let's take a look 10.6 code:

            {code:java}
            dberr_t
            lock_rec_insert_check_and_lock(...)
            {
            ...
                  const unsigned type_mode= LOCK_X | LOCK_GAP | LOCK_INSERT_INTENTION;
             
                  if (lock_t *c_lock= lock_rec_other_has_conflicting(type_mode,
                                                                     g.cell(), id,
                                                                     heap_no, trx))
                  {
                    trx->mutex_lock();
                    err= lock_rec_enqueue_waiting(c_lock, type_mode, id, block->frame,
                                                  heap_no, index, thr, nullptr);
                    trx->mutex_unlock();
                  }
            ...
            }
            {code}

            Neither lock_rec_insert_check_and_lock() nor lock_rec_other_has_conflicting() doesn't check conflicting lock is in waiting state and it already waits for the requesting insert-intention lock transaction.

            I have not yet checked versions less then 10.6.

            The test is attached: [^ii-conflicts-waiting.test]
            We have two transactions and one record. The first transaction holds ORDINARY S-lock on the record, the second transaction created waiting ORDINARY X-lock and waits for the first transaction. Then the first transaction requests insert-intention lock on the record. And this lock conflicts with the waiting ORDINARY X-lock of the second transaction. What causes deadlock. Why it should conflict? The first transaction already holds lock on the record. And the second's transaction lock contains "waiting" flag.

            Let's take a look 10.6 code:

            {code:java}
            dberr_t
            lock_rec_insert_check_and_lock(...)
            {
            ...
                  const unsigned type_mode= LOCK_X | LOCK_GAP | LOCK_INSERT_INTENTION;
             
                  if (lock_t *c_lock= lock_rec_other_has_conflicting(type_mode,
                                                                     g.cell(), id,
                                                                     heap_no, trx))
                  {
                    trx->mutex_lock();
                    err= lock_rec_enqueue_waiting(c_lock, type_mode, id, block->frame,
                                                  heap_no, index, thr, nullptr);
                    trx->mutex_unlock();
                  }
            ...
            }
            {code}

            Neither lock_rec_insert_check_and_lock() nor lock_rec_other_has_conflicting() doesn't check conflicting lock is in waiting state and it already waits for the requesting insert-intention lock transaction.

            I have not yet checked versions less then 10.6.

            The test is attached: [^ii-conflicts-waiting.test]
            vlad.lesin Vladislav Lesin made changes -
            Affects Version/s 10.2 [ 14601 ]
            Affects Version/s 10.3 [ 22126 ]
            Affects Version/s 10.4 [ 22408 ]
            Affects Version/s 10.5 [ 23123 ]
            vlad.lesin Vladislav Lesin made changes -
            Description We have two transactions and one record. The first transaction holds ORDINARY S-lock on the record, the second transaction created waiting ORDINARY X-lock and waits for the first transaction. Then the first transaction requests insert-intention lock on the record. And this lock conflicts with the waiting ORDINARY X-lock of the second transaction. What causes deadlock. Why it should conflict? The first transaction already holds lock on the record. And the second's transaction lock contains "waiting" flag.

            Let's take a look 10.6 code:

            {code:java}
            dberr_t
            lock_rec_insert_check_and_lock(...)
            {
            ...
                  const unsigned type_mode= LOCK_X | LOCK_GAP | LOCK_INSERT_INTENTION;
             
                  if (lock_t *c_lock= lock_rec_other_has_conflicting(type_mode,
                                                                     g.cell(), id,
                                                                     heap_no, trx))
                  {
                    trx->mutex_lock();
                    err= lock_rec_enqueue_waiting(c_lock, type_mode, id, block->frame,
                                                  heap_no, index, thr, nullptr);
                    trx->mutex_unlock();
                  }
            ...
            }
            {code}

            Neither lock_rec_insert_check_and_lock() nor lock_rec_other_has_conflicting() doesn't check conflicting lock is in waiting state and it already waits for the requesting insert-intention lock transaction.

            I have not yet checked versions less then 10.6.

            The test is attached: [^ii-conflicts-waiting.test]
            We have two transactions and one record. The first transaction holds ORDINARY S-lock on the record, the second transaction created waiting ORDINARY X-lock and waits for the first transaction. Then the first transaction requests insert-intention lock on the record. And this lock conflicts with the waiting ORDINARY X-lock of the second transaction. What causes deadlock. Why it should conflict? The first transaction already holds lock on the record. And the second's transaction lock contains "waiting" flag.

            Let's take a look 10.6 code:

            {code:java}
            dberr_t
            lock_rec_insert_check_and_lock(...)
            {
            ...
                  const unsigned type_mode= LOCK_X | LOCK_GAP | LOCK_INSERT_INTENTION;
             
                  if (lock_t *c_lock= lock_rec_other_has_conflicting(type_mode,
                                                                     g.cell(), id,
                                                                     heap_no, trx))
                  {
                    trx->mutex_lock();
                    err= lock_rec_enqueue_waiting(c_lock, type_mode, id, block->frame,
                                                  heap_no, index, thr, nullptr);
                    trx->mutex_unlock();
                  }
            ...
            }
            {code}

            Neither lock_rec_insert_check_and_lock() nor lock_rec_other_has_conflicting() doesn't check conflicting lock is in waiting state and it already waits for the requesting insert-intention lock transaction.

            The test is attached: [^ii-conflicts-waiting.test]
            vlad.lesin Vladislav Lesin made changes -
            Fix Version/s 10.2 [ 14601 ]
            Fix Version/s 10.3 [ 22126 ]
            Fix Version/s 10.4 [ 22408 ]
            Fix Version/s 10.5 [ 23123 ]
            Fix Version/s 10.6 [ 24028 ]
            Fix Version/s 10.7 [ 24805 ]
            Fix Version/s 10.8 [ 26121 ]
            vlad.lesin Vladislav Lesin made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            julien.fritsch Julien Fritsch made changes -
            Priority Major [ 3 ] Critical [ 2 ]
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 127341 ] MariaDB v4 [ 144616 ]
            vlad.lesin Vladislav Lesin made changes -
            Comment [ A comment with security level 'Developers' was removed. ]
            marko Marko Mäkelä made changes -
            marko Marko Mäkelä made changes -
            Status In Progress [ 3 ] In Testing [ 10301 ]
            marko Marko Mäkelä made changes -
            Assignee Vladislav Lesin [ vlad.lesin ] Matthias Leich [ mleich ]
            mleich Matthias Leich made changes -
            Status In Testing [ 10301 ] Stalled [ 10000 ]
            mleich Matthias Leich made changes -
            Assignee Matthias Leich [ mleich ] Vladislav Lesin [ vlad.lesin ]
            vlad.lesin Vladislav Lesin made changes -
            vlad.lesin Vladislav Lesin made changes -
            Status Stalled [ 10000 ] In Progress [ 3 ]
            vlad.lesin Vladislav Lesin made changes -
            Status In Progress [ 3 ] In Testing [ 10301 ]
            vlad.lesin Vladislav Lesin made changes -
            Assignee Vladislav Lesin [ vlad.lesin ] Matthias Leich [ mleich ]
            mleich Matthias Leich made changes -
            Assignee Matthias Leich [ mleich ] Vladislav Lesin [ vlad.lesin ]
            Status In Testing [ 10301 ] Stalled [ 10000 ]
            vlad.lesin Vladislav Lesin made changes -
            Status Stalled [ 10000 ] In Progress [ 3 ]
            vlad.lesin Vladislav Lesin made changes -
            Assignee Vladislav Lesin [ vlad.lesin ] Marko Mäkelä [ marko ]
            Status In Progress [ 3 ] In Review [ 10002 ]
            marko Marko Mäkelä made changes -
            Assignee Marko Mäkelä [ marko ] Vladislav Lesin [ vlad.lesin ]
            Status In Review [ 10002 ] Stalled [ 10000 ]
            jplindst Jan Lindström (Inactive) made changes -
            vlad.lesin Vladislav Lesin made changes -
            Fix Version/s 10.5.14 [ 26809 ]
            Fix Version/s 10.6.6 [ 26811 ]
            Fix Version/s 10.7.2 [ 26813 ]
            Fix Version/s 10.8.1 [ 26815 ]
            Fix Version/s 10.2 [ 14601 ]
            Fix Version/s 10.3 [ 22126 ]
            Fix Version/s 10.4 [ 22408 ]
            Fix Version/s 10.5 [ 23123 ]
            Fix Version/s 10.6 [ 24028 ]
            Fix Version/s 10.7 [ 24805 ]
            Fix Version/s 10.8 [ 26121 ]
            Resolution Fixed [ 1 ]
            Status Stalled [ 10000 ] Closed [ 6 ]
            marko Marko Mäkelä made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            marko Marko Mäkelä made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            vlad.lesin Vladislav Lesin made changes -
            Fix Version/s 10.3.35 [ 27512 ]
            Fix Version/s 10.4.25 [ 27510 ]
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            marko Marko Mäkelä made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            marko Marko Mäkelä made changes -
            marko Marko Mäkelä made changes -
            marko Marko Mäkelä made changes -
            vlad.lesin Vladislav Lesin made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            mariadb-jira-automation Jira Automation (IT) made changes -
            Zendesk Related Tickets 202352 201658 136328
            Zendesk active tickets 201658
            vlad.lesin Vladislav Lesin made changes -
            Resolution Fixed [ 1 ]
            Status Closed [ 6 ] Stalled [ 10000 ]
            vlad.lesin Vladislav Lesin made changes -
            Status Stalled [ 10000 ] In Progress [ 3 ]
            vlad.lesin Vladislav Lesin made changes -
            vlad.lesin Vladislav Lesin made changes -
            Resolution Fixed [ 1 ]
            Status In Progress [ 3 ] Closed [ 6 ]
            JIraAutomate JiraAutomate made changes -
            Fix Version/s 10.5.16 [ 27508 ]
            Fix Version/s 10.6.8 [ 27506 ]
            Fix Version/s 10.7.4 [ 27504 ]
            Fix Version/s 10.8.3 [ 27502 ]
            alessandro.vetere Alessandro Vetere made changes -

            People

              vlad.lesin Vladislav Lesin
              vlad.lesin Vladislav Lesin
              Votes:
              1 Vote for this issue
              Watchers:
              12 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.