Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
MDEV-23693 Failing assertion: my_atomic_load32_explicit(&lock->lock_w…
…ord, MY_MEMORY_ORDER_RELAXED) == X_LOCK_DECR InnoDB frees the block lock during buffer pool shrinking when other thread is yet to release the block lock. While shrinking the buffer pool, InnoDB allows the page to be freed unless it is buffer fixed. In some cases, InnoDB releases the latch after unfixing the block. Fix: ==== - InnoDB should unfix the block after releases the latch. - Add more assertion to check buffer fix while accessing the page. - Introduced block_hint structure to store buf_block_t pointer and allow accessing the buf_block_t pointer only by passing a functor. It returns original buf_block_t* pointer if it is valid or nullptr if the pointer become stale. - Replace buf_block_is_uncompressed() with buf_pool_t::is_block_pointer() This change is motivated by a change in mysql-5.7.32: mysql/mysql-server@46e60de Bug #31036301 ASSERTION FAILURE: SYNC0RW.IC:429:LOCK->LOCK_WORD
- Loading branch information
1 parent
6a614d6
commit bc540b8
Showing
16 changed files
with
262 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /***************************************************************************** | ||
| Copyright (c) 2020, Oracle and/or its affiliates. All Rights Reserved. | ||
| Copyright (c) 2020, MariaDB Corporation. | ||
| This program is free software; you can redistribute it and/or modify it under | ||
| the terms of the GNU General Public License, version 2.0, as published by the | ||
| Free Software Foundation. | ||
| This program is also distributed with certain software (including but not | ||
| limited to OpenSSL) that is licensed under separate terms, as designated in a | ||
| particular file or component or in included license documentation. The authors | ||
| of MySQL hereby grant you an additional permission to link the program and | ||
| your derivative works with the separately licensed software that they have | ||
| included with MySQL. | ||
| This program is distributed in the hope that it will be useful, but WITHOUT | ||
| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0, | ||
| for more details. | ||
| You should have received a copy of the GNU General Public License along with | ||
| this program; if not, write to the Free Software Foundation, Inc., | ||
| 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| *****************************************************************************/ | ||
|
|
||
| #include "buf0block_hint.h" | ||
| namespace buf { | ||
|
|
||
| void Block_hint::buffer_fix_block_if_still_valid() | ||
| { | ||
| /* We need to check if m_block points to one of chunks. For this to be | ||
| meaningful we need to prevent freeing memory while we check, and until we | ||
| buffer-fix the block. For this purpose it is enough to latch any of the many | ||
| latches taken by buf_resize(). | ||
| However, for buffer-fixing to be meaningful, the block has to contain a page | ||
| (as opposed to being already empty, which might mean that buf_pool_resize() | ||
| can proceed and free it once we free the s-latch), so we confirm that the | ||
| block contains a page. However, it is not sufficient to check that this is | ||
| just any page, because just after we check it could get freed, unless we | ||
| have a latch which prevents this. This is tricky because page_hash latches | ||
| are sharded by page_id and we don't know the page_id until we look into the | ||
| block. To solve this chicken-and-egg problem somewhat, we latch the shard | ||
| for the m_page_id and compare block->page.id to it - so if is equal then we | ||
| can be reasonably sure that we have the correct latch. | ||
| There is still a theoretical problem here, where other threads might try | ||
| to modify the m_block->page.id while we are comparing it, but the chance of | ||
| accidentally causing the old space_id == m_page_id.m_space and the new | ||
| page_no == m_page_id.m_page_no is minimal as compilers emit a single 8-byte | ||
| comparison instruction to compare both at the same time atomically, and f() | ||
| will probably double-check the block->page.id again, anyway. | ||
| Finally, assuming that we have correct hash bucket latched, we should check if | ||
| the state of the block is BUF_BLOCK_FILE_PAGE before buffer-fixing the block, | ||
| as otherwise we risk buffer-fixing and operating on a block, which is already | ||
| meant to be freed. In particular, buf_LRU_free_page() first calls | ||
| buf_LRU_block_remove_hashed() under hash bucket latch protection to change the | ||
| state to BUF_BLOCK_REMOVE_HASH and then releases the latch. Later it calls | ||
| buf_LRU_block_free_hashed_page() without any latch to change the state to | ||
| BUF_BLOCK_MEMORY and reset the page's id, which means buf_resize() can free it | ||
| regardless of our buffer-fixing. */ | ||
| if (m_block) | ||
| { | ||
| const buf_pool_t *const buf_pool= buf_pool_get(m_page_id); | ||
| rw_lock_t *latch= buf_page_hash_lock_get(buf_pool, m_page_id); | ||
| rw_lock_s_lock(latch); | ||
| /* If not own buf_pool_mutex, page_hash can be changed. */ | ||
| latch= buf_page_hash_lock_s_confirm(latch, buf_pool, m_page_id); | ||
| if (buf_pool->is_block_field(m_block) && | ||
| m_page_id == m_block->page.id && | ||
| buf_block_get_state(m_block) == BUF_BLOCK_FILE_PAGE) | ||
| buf_block_buf_fix_inc(m_block, __FILE__, __LINE__); | ||
| else | ||
| clear(); | ||
| rw_lock_s_unlock(latch); | ||
| } | ||
| } | ||
| } // namespace buf |
Oops, something went wrong.