MySQL 5.7&8.0 Bug 组提交参数设置不当导致事务提交hung住
MySQL 5.7引入了组提交功能,组提交的两个参数binlog_group_commit_sync_delay和binlog_group_commit_sync_no_delay_count,如果设置不当,可能导致事务提交hung住。这个问题持续了多个版本,修改了两次源码,才最终完全修复。
第一次Bug:
见地址:https://bugs.mysql.com/bug.php?id=80652
根据Bug描述,当如下参数设置时,会触发事务提交hung住。
- binlog_group_commit_sync_delay设置为1~9
- binlog_group_commit_sync_no_delay_count设置为大于1
从官方提供的Release Note来看,这个Bug在5.7.17版本被修复。
对比一下 5.7.16 和 5.7.17 关于这个Bug的修改内容,源码文件位于 sql/binlog.cc 。
首先看5.7.16的这段代码,如下:
time_t Stage_manager::wait_count_or_timeout(ulong count, time_t usec, StageID stage)
{
time_t to_wait=
DBUG_EVALUATE_IF("bgc_set_infinite_delay", LONG_MAX, usec);
/*
For testing purposes while waiting for inifinity
to arrive, we keep checking the queue size at regular,
small intervals. Otherwise, waiting 0.1 * infinite
is too long.
*/
time_t delta=
DBUG_EVALUATE_IF("bgc_set_infinite_delay", 100000,
static_cast(to_wait * 0.1));
while (to_wait > 0 && (count == 0 || static_cast(m_queue[stage].get_size()) < count))
{
#ifndef DBUG_OFF
if (current_thd)
DEBUG_SYNC(current_thd, "bgc_wait_count_or_timeout");
#endif
my_sleep(delta);
to_wait -= delta;
}
return to_wait;
}