diff --git a/sql/log_event.cc b/sql/log_event.cc index 420d8d6..46e2853 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -6961,12 +7085,11 @@ int Xid_apply_log_event::do_apply_event(Relay_log_info const *rli) { DBUG_ENTER("Xid_log_event::do_apply_event"); int error= 0; - char saved_group_master_log_name[FN_REFLEN]; char saved_group_relay_log_name[FN_REFLEN]; volatile my_off_t saved_group_master_log_pos; volatile my_off_t saved_group_relay_log_pos; - - char new_group_master_log_name[FN_REFLEN]; + // ril->group_master_log_name is never updated before storage, so no need to + // save it and make a new one, we are always using the current one in this function. char new_group_relay_log_name[FN_REFLEN]; volatile my_off_t new_group_master_log_pos; volatile my_off_t new_group_relay_log_pos; @@ -7008,8 +7131,6 @@ int Xid_apply_log_event::do_apply_event(Relay_log_info const *rli) Save the rli positions. We need them to temporarily reset the positions just before the commit. */ - strmake(saved_group_master_log_name, rli_ptr->get_group_master_log_name(), - FN_REFLEN - 1); saved_group_master_log_pos= rli_ptr->get_group_master_log_pos(); strmake(saved_group_relay_log_name, rli_ptr->get_group_relay_log_name(), FN_REFLEN - 1); @@ -7043,9 +7164,11 @@ int Xid_apply_log_event::do_apply_event(Relay_log_info const *rli) rli repository being transactional means replication is crash safe. Positions are written into transactional tables ahead of commit and the changes are made permanent during commit. - XA transactional does not actually commit so has to defer its flush_info(). + + See Xid_apply_log_event::do_apply_event_worker() at the same code section. */ - if (!thd->get_transaction()->xid_state()->check_in_xa(false) && + bool is_in_xa= false; + if (!(is_in_xa= thd->get_transaction()->xid_state()->check_in_xa(false)) && rli_ptr->is_transactional()) { if ((error= rli_ptr->flush_info(true))) @@ -7080,8 +7203,6 @@ int Xid_apply_log_event::do_apply_event(Relay_log_info const *rli) Save the new rli positions. These positions will be set back to group* positions on successful completion of the commit operation. */ - strmake(new_group_master_log_name, rli_ptr->get_group_master_log_name(), - FN_REFLEN - 1); new_group_master_log_pos= rli_ptr->get_group_master_log_pos(); strmake(new_group_relay_log_name, rli_ptr->get_group_relay_log_name(), FN_REFLEN - 1); @@ -7090,8 +7211,6 @@ int Xid_apply_log_event::do_apply_event(Relay_log_info const *rli) Rollback positions in memory just before commit. Position values will be reset to their new values only on successful commit operation. */ - rli_ptr->set_group_master_log_name(saved_group_master_log_name); - rli_ptr->notify_group_master_log_name_update(); rli_ptr->set_group_master_log_pos(saved_group_master_log_pos); rli_ptr->set_group_relay_log_name(saved_group_relay_log_name); rli_ptr->notify_group_relay_log_name_update(); @@ -7118,8 +7237,6 @@ int Xid_apply_log_event::do_apply_event(Relay_log_info const *rli) "crash_after_commit_before_update_pos."); DBUG_SUICIDE();); /* Update positions on successful commit */ - rli_ptr->set_group_master_log_name(new_group_master_log_name); - rli_ptr->notify_group_master_log_name_update(); rli_ptr->set_group_master_log_pos(new_group_master_log_pos); rli_ptr->set_group_relay_log_name(new_group_relay_log_name); rli_ptr->notify_group_relay_log_name_update(); @@ -7137,8 +7254,9 @@ int Xid_apply_log_event::do_apply_event(Relay_log_info const *rli) Where as for non transactional rli repository the positions are flushed only on succesful commit. */ - if (!rli_ptr->is_transactional()) - rli_ptr->flush_info(false); + if (!rli_ptr->is_transactional() || + (is_in_xa)) + rli_ptr->flush_info(rli_ptr->is_transactional()); } err: mysql_cond_broadcast(&rli_ptr->data_cond); diff --git a/sql/rpl_rli_pdb.cc b/sql/rpl_rli_pdb.cc index d234d4c..76410dc 100644 --- a/sql/rpl_rli_pdb.cc +++ b/sql/rpl_rli_pdb.cc @@ -1245,7 +1294,12 @@ void Slave_worker::slave_worker_ends_group(Log_event* ev, int error) ptr_g->group_relay_log_name != NULL); DBUG_ASSERT(ptr_g->worker_id == id); - if (ev->get_type_code() != binary_log::XID_EVENT) + /* + For both types of events, the commit_positions() was already called in + Xid_apply_log_event::do_apply_event_worker(). + */ + if (ev->get_type_code() != binary_log::XID_EVENT && + ev->get_type_code() != binary_log::XA_PREPARE_LOG_EVENT) { commit_positions(ev, ptr_g, false); DBUG_EXECUTE_IF("crash_after_commit_and_update_pos", diff --git a/sql/rpl_rli_pdb.h b/sql/rpl_rli_pdb.h index f352ed2..6483845 100644 --- a/sql/rpl_rli_pdb.h +++ b/sql/rpl_rli_pdb.h @@ -403,7 +403,8 @@ public: Prealloced_array curr_group_exec_parts; // Current Group Executed Partitions - bool curr_group_seen_begin; // is set to TRUE with explicit B-event + // Already defined in base class and this member is not used anywhere, so remove it here. + //bool curr_group_seen_begin; // is set to TRUE with explicit B-event. #ifndef DBUG_OFF bool curr_group_seen_sequence_number; // is set to TRUE about starts_group() #endif diff --git a/sql/rpl_slave.cc b/sql/rpl_slave.cc index ac076ac..ef7e0f2 100644 --- a/sql/rpl_slave.cc +++ b/sql/rpl_slave.cc @@ -4890,7 +4911,8 @@ apply_event_and_update_pos(Log_event** ptr_ev, THD* thd, Relay_log_info* rli) */ int error= 0; if (*ptr_ev && - (ev->get_type_code() != binary_log::XID_EVENT || + ((ev->get_type_code() != binary_log::XID_EVENT && + ev->get_type_code() != binary_log::XA_PREPARE_LOG_EVENT) || skip_event || (rli->is_mts_recovery() && !is_gtid_event(ev) && (ev->ends_group() || !rli->mts_recovery_group_seen_begin) && bitmap_is_set(&rli->recovery_groups, rli->mts_recovery_index)))) @@ -5403,8 +5429,8 @@ static int exec_relay_log_event(THD* thd, Relay_log_info* rli) */ DBUG_EXECUTE_IF("incomplete_group_in_relay_log", if ((ev->get_type_code() == binary_log::XID_EVENT) || - ((ev->get_type_code() == binary_log::QUERY_EVENT) && - strcmp("COMMIT", ((Query_log_event *) ev)->query) == 0)) + (ev->get_type_code() == binary_log::XA_PREPARE_LOG_EVENT) || + ((ev->get_type_code() == binary_log::QUERY_EVENT) && ev->ends_group())) { DBUG_ASSERT(thd->get_transaction()->cannot_safely_rollback( Transaction_ctx::SESSION));