Commit caa985e6 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-28454 Latching order violation (and hang) in ibuf_insert_low

Since commit 2ca11234 (MDEV-26217)
the function trx_t::commit(std::vector<pfs_os_file_t>&)
holds exclusive lock_sys.latch while invoking fil_delete_tablespace(),
which in turn may wait for change buffer tree latches in
ibuf_delete_for_discarded_space().

ibuf_insert_low(): If a shared lock_sys.latch cannot be acquired
without waiting, refuse to buffer the insert. In this way, a
deadlock with a DDL operation will be avoided.

ibuf_insert_to_index_page(), ibuf_delete(): Remove redundant calls to
record locking. In ibuf_insert_low() we already ensured that no record
locks existed on the page. No locks can be added before the buffered
changes have been merged.
parent d8b943fb
...@@ -3299,9 +3299,15 @@ ibuf_insert_low( ...@@ -3299,9 +3299,15 @@ ibuf_insert_low(
commit_exit: commit_exit:
ibuf_mtr_commit(&bitmap_mtr); ibuf_mtr_commit(&bitmap_mtr);
goto fail_exit; goto fail_exit;
} else if (!lock_sys.rd_lock_try()) {
goto commit_exit;
} else { } else {
LockGuard g{lock_sys.rec_hash, page_id}; hash_cell_t* cell = lock_sys.rec_hash.cell_get(page_id.fold());
if (lock_sys_t::get_first(g.cell(), page_id)) { lock_sys.rec_hash.latch(cell)->acquire();
const lock_t* lock = lock_sys_t::get_first(*cell, page_id);
lock_sys.rec_hash.latch(cell)->release();
lock_sys.rd_unlock();
if (lock) {
goto commit_exit; goto commit_exit;
} }
} }
...@@ -3804,7 +3810,6 @@ ibuf_insert_to_index_page( ...@@ -3804,7 +3810,6 @@ ibuf_insert_to_index_page(
/* Delete the different-length record, and insert the /* Delete the different-length record, and insert the
buffered one. */ buffered one. */
lock_rec_store_on_page_infimum(block, rec);
page_cur_delete_rec(&page_cur, index, offsets, mtr); page_cur_delete_rec(&page_cur, index, offsets, mtr);
page_cur_move_to_prev(&page_cur); page_cur_move_to_prev(&page_cur);
rec = ibuf_insert_to_index_page_low(entry, block, index, rec = ibuf_insert_to_index_page_low(entry, block, index,
...@@ -3812,8 +3817,6 @@ ibuf_insert_to_index_page( ...@@ -3812,8 +3817,6 @@ ibuf_insert_to_index_page(
&page_cur); &page_cur);
ut_ad(!cmp_dtuple_rec(entry, rec, offsets)); ut_ad(!cmp_dtuple_rec(entry, rec, offsets));
lock_rec_restore_from_page_infimum(*block, rec,
block->page.id());
} else { } else {
offsets = NULL; offsets = NULL;
ibuf_insert_to_index_page_low(entry, block, index, ibuf_insert_to_index_page_low(entry, block, index,
...@@ -3946,8 +3949,6 @@ ibuf_delete( ...@@ -3946,8 +3949,6 @@ ibuf_delete(
return; return;
} }
lock_update_delete(block, rec);
if (!page_zip) { if (!page_zip) {
max_ins_size max_ins_size
= page_get_max_insert_size_after_reorganize( = page_get_max_insert_size_after_reorganize(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment