diff --git a/sql/rpl_commit_stage_manager.cc b/sql/rpl_commit_stage_manager.cc index d13c9ee7beb0..c186af1668b6 100644 --- a/sql/rpl_commit_stage_manager.cc +++ b/sql/rpl_commit_stage_manager.cc @@ -476,7 +476,14 @@ THD *Commit_stage_manager::fetch_queue_skip_acquire_lock(StageID stage) { void Commit_stage_manager::process_final_stage_for_ordered_commit_group( THD *first) { if (first != nullptr) { + /* + The below call to update_commit_group() function accesses the array + `commit_group_sidnos` and needs to be protected with + MYSQL_BIN_LOG::LOCK_commit. + */ + mysql_mutex_lock(mysql_bin_log.get_commit_lock()); gtid_state->update_commit_group(first); + mysql_mutex_unlock(mysql_bin_log.get_commit_lock()); signal_done(first, Commit_stage_manager::COMMIT_ORDER_FLUSH_STAGE); } } diff --git a/sql/rpl_gtid_state.cc b/sql/rpl_gtid_state.cc index cc2b1c72448c..4da136710a50 100644 --- a/sql/rpl_gtid_state.cc +++ b/sql/rpl_gtid_state.cc @@ -157,6 +157,9 @@ void Gtid_state::broadcast_owned_sidnos(const THD *thd) { void Gtid_state::update_commit_group(THD *first_thd) { DBUG_TRACE; + // Assert that we already hold MYSQL_BIN_LOG::LOCK_commit here + mysql_mutex_assert_owner(mysql_bin_log.get_commit_lock()); + bool gtid_threshold_breach = false; /* We are going to loop in all sessions of the group commit in order to avoid