From 20bb4ed882fb798f62b1c0fa8e6e3193f6530c5d Mon Sep 17 00:00:00 2001 From: ParadoxV5 Date: Wed, 23 Jul 2025 09:45:19 -0600 Subject: [PATCH] MDEV-36810 Deduplicate `LOG_EVENT_OFFSET` `LOG_EVENT_OFFSET` is a duplicate of `EVENT_TYPE_OFFSET` and `BIN_LOG_HEADER_SIZE` depending on the context. While there, centralize `BIN_LOG_HEADER_SIZE` to `sql/rpl_constants.h` (previously from `sql/unireg.h` and `client/mysqlbinlog.cc`) Reviewed-by: Brandon Nesterenko --- client/mysqlbinlog.cc | 1 - sql/log.cc | 7 +++++-- sql/log_event.h | 2 -- sql/rpl_constants.h | 3 +++ sql/sql_repl.cc | 18 +++++++++++++----- sql/unireg.h | 8 -------- 6 files changed, 21 insertions(+), 18 deletions(-) diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index ce8bed9bf38..d29d6c67038 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -70,7 +70,6 @@ extern "C" unsigned char *mysql_net_store_length(unsigned char *packet, size_t l Rpl_filter *binlog_filter= 0; -#define BIN_LOG_HEADER_SIZE 4 #define PROBE_HEADER_LEN (EVENT_LEN_OFFSET+4) /* Needed for Rpl_filter */ diff --git a/sql/log.cc b/sql/log.cc index aaf71c7b3a3..c9731b9402f 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -5956,8 +5956,11 @@ int MYSQL_BIN_LOG::new_file_impl(bool commit_by_rotate) We log the whole file name for log file as the user may decide to change base names at some point. */ - Rotate_log_event r(new_name + dirname_length(new_name), 0, LOG_EVENT_OFFSET, - is_relay_log ? Rotate_log_event::RELAY_LOG : 0); + Rotate_log_event r( + &new_name[dirname_length(new_name)], /* strlen() */ 0, + BIN_LOG_HEADER_SIZE, + is_relay_log ? Rotate_log_event::RELAY_LOG : 0 + ); enum_binlog_checksum_alg checksum_alg = BINLOG_CHECKSUM_ALG_UNDEF; /* The current relay-log's closing Rotate event must have checksum diff --git a/sql/log_event.h b/sql/log_event.h index f024c160191..0ccd9a047d3 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -92,8 +92,6 @@ class String; #define LOG_READ_CHECKSUM_FAILURE -8 #define LOG_READ_DECRYPT -9 -#define LOG_EVENT_OFFSET 4 - /* 3 is MySQL 4.x; 4 is MySQL 5.0.0. Compared to version 3, version 4 has: diff --git a/sql/rpl_constants.h b/sql/rpl_constants.h index f319d08303c..6a63e4fe1aa 100644 --- a/sql/rpl_constants.h +++ b/sql/rpl_constants.h @@ -20,6 +20,9 @@ #include #include +/** Size of the `"\xfe""bin"` magic mumber */ +#define BIN_LOG_HEADER_SIZE 4 + /** Enumeration of the incidents that can occur for the server. */ diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 3f41bd44f7f..e027571cc90 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -2261,7 +2261,9 @@ send_event_to_slave(binlog_send_info *info, Log_event_type event_type, return "Failed on my_net_write()"; } - DBUG_PRINT("info", ("log event code %d", (*packet)[LOG_EVENT_OFFSET+1] )); + DBUG_PRINT("info", ("log event code %d", + (*packet)[/* Replication protocol status byte */ 1 + EVENT_TYPE_OFFSET] + )); if (event_type == LOAD_EVENT) { if (send_file(info->thd)) @@ -2528,7 +2530,9 @@ static int send_format_descriptor_event(binlog_send_info *info, IO_CACHE *log, DBUG_RETURN(1); } - event_type= (Log_event_type)((uchar)(*packet)[LOG_EVENT_OFFSET+ev_offset]); + event_type= static_cast( + static_cast((*packet)[ev_offset + EVENT_TYPE_OFFSET]) + ); /* The packet has offsets equal to the normal offsets in a @@ -2663,7 +2667,9 @@ static int send_format_descriptor_event(binlog_send_info *info, IO_CACHE *log, DBUG_RETURN(1); } - event_type= (Log_event_type)((uchar)(*packet)[LOG_EVENT_OFFSET + ev_offset]); + event_type= static_cast( + static_cast((*packet)[ev_offset + EVENT_TYPE_OFFSET]) + ); if (event_type == START_ENCRYPTION_EVENT) { Start_encryption_log_event *sele= (Start_encryption_log_event *) @@ -2931,8 +2937,10 @@ static int send_events(binlog_send_info *info, IO_CACHE* log, LOG_INFO* linfo, return 1; } - Log_event_type event_type= - (Log_event_type)((uchar)(*packet)[LOG_EVENT_OFFSET+ev_offset]); + Log_event_type event_type= static_cast( + static_cast((*packet)[ev_offset + EVENT_TYPE_OFFSET]) + ); + #ifndef DBUG_OFF if (info->dbug_reconnect_counter > 0) diff --git a/sql/unireg.h b/sql/unireg.h index 44a9c8f5289..278d1797b92 100644 --- a/sql/unireg.h +++ b/sql/unireg.h @@ -144,14 +144,6 @@ */ #define MIN_TURBOBM_PATTERN_LEN 3 -/* - Defines for binary logging. - Do not decrease the value of BIN_LOG_HEADER_SIZE. - Do not even increase it before checking code. -*/ - -#define BIN_LOG_HEADER_SIZE 4 - #define DEFAULT_KEY_CACHE_NAME "default"