Skip to content

Commit

Permalink
Fix heap overflow in group_relay_log_name handling
Browse files Browse the repository at this point in the history
Summary:
We were accessing group_relay_log_name in
Query_log_event::do_apply_event_worker() but it's assigned only after
the coordinator thread encounters an end event (i.e. xid event or a
query event with "COMMIT" or "ROLLBACK" query). This was causing a race
between accessing group_relay_log_name in the worker thread and writing
it on the coordinator thread. We don't need to set transaction position
in events other than end event, so now we set transaction position in
query event only if it's an end event. The race is eliminated because
group_relay_log_name is set before enqueuing the event to the worker
thread (in both dep repl and vanilla mts).

Reviewed By: lth

Differential Revision: D28767430

fbshipit-source-id: 3a76e04713c
  • Loading branch information
abhinav04sharma authored and facebook-github-bot committed Jun 1, 2021
1 parent 16b2705 commit b0df78d
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions sql/log_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4698,15 +4698,17 @@ int Query_log_event::do_apply_event(Relay_log_info const *rli) {
}

int Query_log_event::do_apply_event_worker(Slave_worker *w) {
// Note: We're using event's future_event_relay_log_pos instead of
// rli->get_event_relay_log_pos() because rli is only updated in
// do_update_pos() which is called after applying the event and we might need
// to use this pos during application (e.g. during commit)
Slave_job_group *ptr_g = w->c_rli->gaq->get_job_group(mts_group_idx);
thd->set_trans_relay_log_pos(ptr_g->group_relay_log_name
? ptr_g->group_relay_log_name
: w->get_group_relay_log_name(),
future_event_relay_log_pos);
if (ends_group()) {
// Note: We're using event's future_event_relay_log_pos instead of
// rli->get_event_relay_log_pos() because rli is only updated in
// do_update_pos() which is called after applying the event and we might
// need to use this pos during application (e.g. during commit)
Slave_job_group *ptr_g = w->c_rli->gaq->get_job_group(mts_group_idx);
thd->set_trans_relay_log_pos(ptr_g->group_relay_log_name
? ptr_g->group_relay_log_name
: w->get_group_relay_log_name(),
future_event_relay_log_pos);
}
return do_apply_event(w, query, q_len);
}

Expand Down

0 comments on commit b0df78d

Please sign in to comment.