Skip to content

Commit 73081b7

Browse files
committed
MDEV-36684 - main.mdl_sync fails under valgrind (test for Bug#42643)
Valgrind is single threaded and only changes threads as part of system calls or waits. Some busy loops were identified and fixed where the server assumes that some other thread will change the state, which will not happen with valgrind. Based on patch by Monty. Original patch introduced VALGRIND_YIELD, which emits pthread_yield() only in valgrind builds. However it was agreed that it is a good idea to emit yield() unconditionally, such that other affected schedulers (like SCHED_FIFO) benefit from this change. Also avoid pthread_yield() in favour of standard std::this_thread::yield().
1 parent d9cd4e1 commit 73081b7

File tree

3 files changed

+4
-0
lines changed

3 files changed

+4
-0
lines changed

sql/sql_base.cc

+2
Original file line numberDiff line numberDiff line change
@@ -4460,6 +4460,7 @@ bool open_tables(THD *thd, const DDL_options_st &options,
44604460
goto error;
44614461

44624462
error= FALSE;
4463+
std::this_thread::yield();
44634464
goto restart;
44644465
}
44654466
goto error;
@@ -4522,6 +4523,7 @@ bool open_tables(THD *thd, const DDL_options_st &options,
45224523
goto error;
45234524

45244525
error= FALSE;
4526+
std::this_thread::yield();
45254527
goto restart;
45264528
}
45274529
/*

sql/table_cache.cc

+1
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,7 @@ TABLE_SHARE *tdc_acquire_share(THD *thd, TABLE_LIST *tl, uint flags,
901901
{
902902
mysql_mutex_unlock(&element->LOCK_table_share);
903903
lf_hash_search_unpin(thd->tdc_hash_pins);
904+
std::this_thread::yield();
904905
goto retry;
905906
}
906907
lf_hash_search_unpin(thd->tdc_hash_pins);

storage/innobase/trx/trx0purge.cc

+1
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,7 @@ dict_table_t *purge_sys_t::close_and_reopen(table_id_t id, THD *thd,
11761176
MDL_context *mdl_context= static_cast<MDL_context*>(thd_mdl_context(thd));
11771177
ut_ad(mdl_context);
11781178
retry:
1179+
std::this_thread::yield();
11791180
ut_ad(m_active);
11801181

11811182
for (que_thr_t *thr= UT_LIST_GET_FIRST(purge_sys.query->thrs); thr;

0 commit comments

Comments
 (0)