From 703fd4ae7207981691965634fdbdda794c6aa880 Mon Sep 17 00:00:00 2001 From: Kristian Nielsen Date: Thu, 17 Sep 2026 12:02:49 +0200 Subject: [PATCH] After-review fixes Signed-off-by: Kristian Nielsen --- sql/semisync_master.h | 14 +++++++-- sql/sql_repl.cc | 66 ++++++++++++++++++++----------------------- 2 files changed, 42 insertions(+), 38 deletions(-) diff --git a/sql/semisync_master.h b/sql/semisync_master.h index e5202ffe6ef..c3d68d0f99d 100644 --- a/sql/semisync_master.h +++ b/sql/semisync_master.h @@ -40,7 +40,12 @@ struct Tranx_node { /* - Encapsulate a reference to a binlog position. + Encapsulate a reference to a binlog position used in semi-sync. Such a + position contains both the GTID and the filename/offset values. + + This struct Repl_semi_sync_trx_info is used to pass such references + as function arguments, where the underlying memory for the log_file + filename string is managed separately by the caller. */ struct Repl_semi_sync_trx_info { rpl_gtid gtid; @@ -55,7 +60,12 @@ struct Repl_semi_sync_trx_info { /* - Structure to save transaction log filename and position + Structure to save transaction log filename and position. + + This struct Trans_binlog_info holds the same information (GTID and + filename/offset) as struct Repl_semi_sync_trx_info, but in addition + contains an embedded buffer that provides memory allocation/ownership + of the log_file filename string. */ struct Trans_binlog_info : public Repl_semi_sync_trx_info { char file_name_buf[FN_REFLEN]; diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index d759b15e90e..42d49d13da9 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -2158,29 +2158,38 @@ gtid_state_from_binlog_pos(const char *in_name, uint32 pos, String *out_str) } +static bool +is_end_of_group_event(bool standalone, Log_event_type event_type, + String *packet, my_off_t ev_offset, size_t len, + enum_binlog_checksum_alg current_checksum_alg) +{ + if (standalone) + return !Log_event::is_part_of_group(event_type); + return + (event_type == XID_EVENT || event_type == XA_PREPARE_LOG_EVENT || + ( /* QUERY_COMPRESSED_EVENT would never be commmit or rollback */ + event_type == QUERY_EVENT && + Query_log_event::peek_is_commit_rollback((uchar*) packet->ptr() + + ev_offset, + len - ev_offset, + current_checksum_alg))); +} + + static bool is_until_reached(binlog_send_info *info, ulong *ev_offset, Log_event_type event_type, const char **errmsg, uint32 current_pos) { - switch (info->gtid_until_group) - { - case GTID_UNTIL_NOT_DONE: + DBUG_ASSERT(info->gtid_until_group == GTID_UNTIL_NOT_DONE || + info->gtid_until_group == GTID_UNTIL_STOP_AFTER_STANDALONE || + info->gtid_until_group == GTID_UNTIL_STOP_AFTER_TRANSACTION); + bool standalone= info->gtid_until_group == GTID_UNTIL_STOP_AFTER_STANDALONE; + if (info->gtid_until_group == GTID_UNTIL_NOT_DONE || + !is_end_of_group_event(standalone, event_type, info->packet, + *ev_offset, info->packet->length(), + info->current_checksum_alg)) return false; - case GTID_UNTIL_STOP_AFTER_STANDALONE: - if (Log_event::is_part_of_group(event_type)) - return false; - break; - case GTID_UNTIL_STOP_AFTER_TRANSACTION: - if (event_type != XID_EVENT && event_type != XA_PREPARE_LOG_EVENT && - (event_type != QUERY_EVENT || /* QUERY_COMPRESSED_EVENT would never be commmit or rollback */ - !Query_log_event::peek_is_commit_rollback - ((uchar*) info->packet->ptr() + *ev_offset, - info->packet->length() - *ev_offset, - info->current_checksum_alg))) - return false; - break; - } /* The last event group has been sent, now the START SLAVE UNTIL condition @@ -2406,26 +2415,11 @@ send_event_to_slave(binlog_send_info *info, Log_event_type event_type, if (info->in_event_group) { - if (info->standalone) + if (is_end_of_group_event(info->standalone, event_type, packet, + ev_offset, len, current_checksum_alg)) { - if (!Log_event::is_part_of_group(event_type)) - { - info->in_event_group= false; - end_of_group_event= true; - } - } - else - { - if (event_type == XID_EVENT || event_type == XA_PREPARE_LOG_EVENT || - (event_type == QUERY_EVENT && /* QUERY_COMPRESSED_EVENT would never be commmit or rollback */ - Query_log_event::peek_is_commit_rollback((uchar*) packet->ptr() + - ev_offset, - len - ev_offset, - current_checksum_alg))) - { - info->in_event_group= false; - end_of_group_event= true; - } + info->in_event_group= false; + end_of_group_event= true; } /*