summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThirunarayanan Balathandayuthapani <thiru@mariadb.com>2020-07-10 17:50:04 +0530
committerThirunarayanan Balathandayuthapani <thiru@mariadb.com>2020-07-14 12:47:32 +0530
commit194a720e28ed426552558b32c68577db9f29ab2e (patch)
treee0915de44bd313bd8cb33047d914febf3482a32f
parentf73db93329c1d22f9ca5696b46d50d137e6095ad (diff)
downloadmariadb-git-194a720e28ed426552558b32c68577db9f29ab2e.tar.gz
MDEV-22890 DEADLOCK of threads detected: row0sel.cc S-LOCK / btr0cur.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.
-rw-r--r--storage/innobase/include/dict0dict.ic8
-rw-r--r--storage/xtradb/include/dict0dict.ic8
2 files changed, 10 insertions, 6 deletions
diff --git a/storage/innobase/include/dict0dict.ic b/storage/innobase/include/dict0dict.ic
index bd1d529f753..93a6c4a7cc1 100644
--- a/storage/innobase/include/dict0dict.ic
+++ b/storage/innobase/include/dict0dict.ic
@@ -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));
}
/*********************************************************************//**
diff --git a/storage/xtradb/include/dict0dict.ic b/storage/xtradb/include/dict0dict.ic
index 475391a3f75..c5ea95b7c08 100644
--- a/storage/xtradb/include/dict0dict.ic
+++ b/storage/xtradb/include/dict0dict.ic
@@ -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));
}
/*********************************************************************//**