diff --git a/storage/innobase/buf/buf0buf.cc b/storage/innobase/buf/buf0buf.cc index d3eb0adbb8e..92d32299ce9 100644 --- a/storage/innobase/buf/buf0buf.cc +++ b/storage/innobase/buf/buf0buf.cc @@ -90,6 +90,8 @@ this program; if not, write to the Free Software Foundation, Inc., #ifdef UNIV_DEBUG #include "ut0stateful_latching_rules.h" +#include "current_thd.h" +#include "debug_sync.h" #endif /* UNIV_DEBUG */ #ifdef HAVE_LIBNUMA @@ -2208,8 +2210,27 @@ static void buf_pool_resize() { ut_ad(buf_pool->n_chunks_new == buf_pool->n_chunks); ut_ad(UT_LIST_GET_LEN(buf_pool->withdraw) == 0); + DBUG_EXECUTE_IF("buf_pool_resize_simulate_wait", { + const char act[] = + "now SIGNAL " + "buf_pool_resize_stopped_before_setting_new_size " + "WAIT_FOR " + "buf_pool_resize_update_new_size"; + assert(!debug_sync_set_action(current_thd, STRING_WITH_LEN(act))); + }); + buf_pool->curr_size = new_instance_size; + DBUG_EXECUTE_IF("buf_pool_resize_simulate_wait", { + const char act[] = + "now SIGNAL " + "buf_pool_resize_stopped_after_setting_new_size " + "WAIT_FOR " + "buf_pool_resize_continue"; + assert(!debug_sync_set_action(current_thd, STRING_WITH_LEN(act))); + DBUG_SET("-d,buf_pool_resize_simulate_wait"); + }); + ut_ad(srv_buf_pool_chunk_unit % UNIV_PAGE_SIZE == 0); buf_pool->n_chunks_new = new_instance_size * UNIV_PAGE_SIZE / srv_buf_pool_chunk_unit; @@ -2671,6 +2692,9 @@ withdraw_retry: /** This is the thread for resizing buffer pool. It waits for an event and when waked up either performs a resizing and sleeps again. */ void buf_resize_thread() { +#ifdef UNIV_DEBUG + THD *thd = create_internal_thd(); +#endif while (srv_shutdown_state.load() < SRV_SHUTDOWN_CLEANUP) { os_event_wait(srv_buf_resize_event); os_event_reset(srv_buf_resize_event); @@ -2694,6 +2718,9 @@ void buf_resize_thread() { buf_pool_resize(); } +#ifdef UNIV_DEBUG + destroy_internal_thd(thd); +#endif } /** Clears the adaptive hash index on all pages in the buffer pool. */ diff --git a/storage/innobase/buf/buf0lru.cc b/storage/innobase/buf/buf0lru.cc index 864eac435c7..e5eee13230d 100644 --- a/storage/innobase/buf/buf0lru.cc +++ b/storage/innobase/buf/buf0lru.cc @@ -56,6 +56,10 @@ this program; if not, write to the Free Software Foundation, Inc., #include "trx0trx.h" #include "ut0byte.h" #include "ut0rnd.h" +#ifdef UNIV_DEBUG +#include "current_thd.h" +#include "debug_sync.h" +#endif /** The number of blocks from the LRU_old pointer onward, including the block pointed to, must be buf_pool->LRU_old_ratio/BUF_LRU_OLD_RATIO_DIV @@ -1256,18 +1260,37 @@ static void buf_LRU_check_size_of_non_data_objects( { const size_t mb = (buf_pool->curr_size / (1024 * 1024 / UNIV_PAGE_SIZE)); - if (!recv_recovery_is_on() && buf_pool->curr_size == buf_pool->old_size && +#ifdef UNIV_DEBUG + auto buf_check_size_debug_wait = []() { + const char act[] = + "now SIGNAL " + "buf_pool_resize_update_new_size " + "WAIT_FOR " + "buf_pool_resize_stopped_after_setting_new_size"; + assert(!debug_sync_set_action(current_thd, STRING_WITH_LEN(act))); + DBUG_SET("-d,buf_check_size_simulate_wait"); + return true; + }; +#endif + + ulint old_size = buf_pool->old_size; + std::atomic_thread_fence(std::memory_order_acquire); + + if (!recv_recovery_is_on() && buf_pool->curr_size == old_size && + DBUG_EVALUATE_IF("buf_check_size_simulate_wait", + buf_check_size_debug_wait(), true) && UT_LIST_GET_LEN(buf_pool->free) + UT_LIST_GET_LEN(buf_pool->LRU) < - buf_pool->curr_size / 20) { + buf_pool->curr_size / 20 && + buf_pool->curr_size == old_size) { const bool buf_pool_full = true; LogErr(ERROR_LEVEL, ER_IB_BUFFER_POOL_FULL, "buf_LRU_check_size_of_non_data_objects()", mb); ut_a(!buf_pool_full); - } else if (!recv_recovery_is_on() && - buf_pool->curr_size == buf_pool->old_size && + } else if (!recv_recovery_is_on() && buf_pool->curr_size == old_size && (UT_LIST_GET_LEN(buf_pool->free) + - UT_LIST_GET_LEN(buf_pool->LRU)) < buf_pool->curr_size / 3) { + UT_LIST_GET_LEN(buf_pool->LRU)) < buf_pool->curr_size / 3 && + buf_pool->curr_size == old_size) { if (!buf_lru_switched_on_innodb_mon.exchange(true)) { /* Over 67 % of the buffer pool is occupied by lock heaps or the adaptive hash index or BUF_BLOCK_MEMORY pages. This may be a memory leak! */