Skip to content

Commit 09bfaf3

Browse files
committed
Fix a potential lost wakeup for binlog_commit_wait_usec
If a transaction T1 needs to wait for a transaction T2, T2's commit will skip the normal binlog_commit_wait_usec delay, in order not to needlessly stall throughput. This works by checking if T2 is already ready to commit. If so, it is woken up. If not, we set a flag in T2 so that when it gets ready to commit, it will do so immediately. But there was a potential race due to insufficient locking, if T2 gets ready to commit just at the point where T1 does the check. If the race hits, the wakeup (and early commit) of T2 might be lost. The race is only theoretical (from code inspection, no known test case), but seems best to fix it anyway, by properly locking LOCK_prepare_ordered around the check.
1 parent 999c43a commit 09bfaf3

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

sql/log.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7664,14 +7664,13 @@ void
76647664
MYSQL_BIN_LOG::binlog_trigger_immediate_group_commit()
76657665
{
76667666
group_commit_entry *head;
7667-
mysql_mutex_lock(&LOCK_prepare_ordered);
7667+
mysql_mutex_assert_owner(&LOCK_prepare_ordered);
76687668
head= group_commit_queue;
76697669
if (head)
76707670
{
76717671
head->thd->has_waiter= true;
76727672
mysql_cond_signal(&COND_prepare_ordered);
76737673
}
7674-
mysql_mutex_unlock(&LOCK_prepare_ordered);
76757674
}
76767675

76777676

@@ -7690,9 +7689,11 @@ binlog_report_wait_for(THD *thd1, THD *thd2)
76907689
{
76917690
if (opt_binlog_commit_wait_count == 0)
76927691
return;
7692+
mysql_mutex_lock(&LOCK_prepare_ordered);
76937693
thd2->has_waiter= true;
76947694
if (thd2->waiting_on_group_commit)
76957695
mysql_bin_log.binlog_trigger_immediate_group_commit();
7696+
mysql_mutex_unlock(&LOCK_prepare_ordered);
76967697
}
76977698

76987699

0 commit comments

Comments
 (0)