diff options
-rw-r--r-- | storage/innobase/buf/buf0buf.cc | 11 | ||||
-rw-r--r-- | storage/innobase/include/buf0buf.h | 4 | ||||
-rw-r--r-- | storage/innobase/include/sux_lock.h | 14 |
3 files changed, 15 insertions, 14 deletions
diff --git a/storage/innobase/buf/buf0buf.cc b/storage/innobase/buf/buf0buf.cc index cc92cb3fdbe..cd7f471e52f 100644 --- a/storage/innobase/buf/buf0buf.cc +++ b/storage/innobase/buf/buf0buf.cc @@ -3436,12 +3436,12 @@ func_exit: return(TRUE); } -/** Try to U-latch a page. +/** Try to S-latch a page. Suitable for using when holding the lock_sys latches (as it avoids deadlock). @param[in] page_id page identifier @param[in,out] mtr mini-transaction @return the block -@retval nullptr if an U-latch cannot be granted immediately */ +@retval nullptr if an S-latch cannot be granted immediately */ buf_block_t *buf_page_try_get(const page_id_t page_id, mtr_t *mtr) { ut_ad(mtr); @@ -3463,16 +3463,13 @@ buf_block_t *buf_page_try_get(const page_id_t page_id, mtr_t *mtr) buf_block_buf_fix_inc(block); hash_lock->read_unlock(); - /* We will always try to acquire an U latch. - In lock_rec_print() we may already be holding an S latch on the page, - and recursive S latch acquisition is not allowed. */ - if (!block->lock.u_lock_try(false)) + if (!block->lock.s_lock_try()) { buf_block_buf_fix_dec(block); return nullptr; } - mtr_memo_push(mtr, block, MTR_MEMO_PAGE_SX_FIX); + mtr_memo_push(mtr, block, MTR_MEMO_PAGE_S_FIX); #ifdef UNIV_DEBUG if (!(++buf_dbg_counter % 5771)) buf_pool.validate(); diff --git a/storage/innobase/include/buf0buf.h b/storage/innobase/include/buf0buf.h index ad2997b2c94..ba61bb1e92f 100644 --- a/storage/innobase/include/buf0buf.h +++ b/storage/innobase/include/buf0buf.h @@ -232,12 +232,12 @@ buf_page_optimistic_get( ib_uint64_t modify_clock,/*!< in: modify clock value */ mtr_t* mtr); /*!< in: mini-transaction */ -/** Try to U-latch a page. +/** Try to S-latch a page. Suitable for using when holding the lock_sys latches (as it avoids deadlock). @param[in] page_id page identifier @param[in,out] mtr mini-transaction @return the block -@retval nullptr if an U-latch cannot be granted immediately */ +@retval nullptr if an S-latch cannot be granted immediately */ buf_block_t *buf_page_try_get(const page_id_t page_id, mtr_t *mtr); /** Get read access to a compressed page (usually of type diff --git a/storage/innobase/include/sux_lock.h b/storage/innobase/include/sux_lock.h index 1875915a5e5..436c2bc6600 100644 --- a/storage/innobase/include/sux_lock.h +++ b/storage/innobase/include/sux_lock.h @@ -21,7 +21,7 @@ this program; if not, write to the Free Software Foundation, Inc., #include "my_atomic_wrapper.h" #include "os0thread.h" #ifdef UNIV_DEBUG -# include <set> +# include <unordered_set> #endif /** A "fat" rw-lock that supports @@ -48,7 +48,7 @@ class sux_lock final /** Protects readers */ mutable srw_mutex readers_lock; /** Threads that hold the lock in shared mode */ - std::atomic<std::set<os_thread_id_t>*> readers; + std::atomic<std::unordered_multiset<os_thread_id_t>*> readers; #endif /** The multiplier in recursive for X locks */ @@ -130,14 +130,15 @@ private: /** Register the current thread as a holder of a shared lock */ void s_lock_register() { + const os_thread_id_t id= os_thread_get_curr_id(); readers_lock.wr_lock(); auto r= readers.load(std::memory_order_relaxed); if (!r) { - r= new std::set<os_thread_id_t>(); + r= new std::unordered_multiset<os_thread_id_t>(); readers.store(r, std::memory_order_relaxed); } - ut_ad(r->emplace(os_thread_get_curr_id()).second); + r->emplace(id); readers_lock.wr_unlock(); } #endif @@ -218,10 +219,13 @@ public: void s_unlock() { #ifdef UNIV_DEBUG + const os_thread_id_t id= os_thread_get_curr_id(); auto r= readers.load(std::memory_order_relaxed); ut_ad(r); readers_lock.wr_lock(); - ut_ad(r->erase(os_thread_get_curr_id()) == 1); + auto i= r->find(id); + ut_ad(i != r->end()); + r->erase(i); readers_lock.wr_unlock(); #endif lock.rd_unlock(); |