Skip to content

Commit

Permalink
MDEV-22890 DEADLOCK of threads detected: row0sel.cc S-LOCK / btr0cur.…
Browse files Browse the repository at this point in the history
…cc S-LOCK / row0quiesce.cc X-LOCK

Problem:
=======
- Read operations are always allowed to hold a secondary index leaf
latch and then look up the corresponding clustered index record.
Flush table operation acquires secondary index latch while holding
a clustered index latch. It leads to deadlock violation.

Fix:
====
- Flush table operation should acquire secondary index before taking
clustered index to avoid deadlock violation with select operation.
  • Loading branch information
Thirunarayanan committed Jul 14, 2020
1 parent f73db93 commit 194a720
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions storage/innobase/include/dict0dict.ic
Original file line number Diff line number Diff line change
Expand Up @@ -1026,16 +1026,18 @@ dict_table_x_lock_indexes(
/*======================*/
dict_table_t* table) /*!< in: table */
{
dict_index_t* index;

ut_ad(mutex_own(&dict_sys->mutex));

dict_index_t* clust_index = dict_table_get_first_index(table);

/* Loop through each index of the table and lock them */
for (index = dict_table_get_first_index(table);
for (dict_index_t* index = dict_table_get_next_index(clust_index);
index != NULL;
index = dict_table_get_next_index(index)) {
rw_lock_x_lock(dict_index_get_lock(index));
}

rw_lock_x_lock(dict_index_get_lock(clust_index));
}

/*********************************************************************//**
Expand Down
8 changes: 5 additions & 3 deletions storage/xtradb/include/dict0dict.ic
Original file line number Diff line number Diff line change
Expand Up @@ -1026,16 +1026,18 @@ dict_table_x_lock_indexes(
/*======================*/
dict_table_t* table) /*!< in: table */
{
dict_index_t* index;

ut_ad(mutex_own(&dict_sys->mutex));

dict_index_t* clust_index = dict_table_get_first_index(table);

/* Loop through each index of the table and lock them */
for (index = dict_table_get_first_index(table);
for (dict_index_t* index = dict_table_get_next_index(clust_index);
index != NULL;
index = dict_table_get_next_index(index)) {
rw_lock_x_lock(dict_index_get_lock(index));
}

rw_lock_x_lock(dict_index_get_lock(clust_index));
}

/*********************************************************************//**
Expand Down

0 comments on commit 194a720

Please sign in to comment.