Skip to content

Commit 374f30c

Browse files
committed
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 <brandon.nesterenko@mariadb.com>
1 parent 002330e commit 374f30c

File tree

6 files changed

+21
-18
lines changed

6 files changed

+21
-18
lines changed

client/mysqlbinlog.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ extern "C" unsigned char *mysql_net_store_length(unsigned char *packet, size_t l
7070

7171
Rpl_filter *binlog_filter= 0;
7272

73-
#define BIN_LOG_HEADER_SIZE 4
7473
#define PROBE_HEADER_LEN (EVENT_LEN_OFFSET+4)
7574

7675
/* Needed for Rpl_filter */

sql/log.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5967,8 +5967,11 @@ int MYSQL_BIN_LOG::new_file_impl(bool commit_by_rotate)
59675967
We log the whole file name for log file as the user may decide
59685968
to change base names at some point.
59695969
*/
5970-
Rotate_log_event r(new_name + dirname_length(new_name), 0, LOG_EVENT_OFFSET,
5971-
is_relay_log ? Rotate_log_event::RELAY_LOG : 0);
5970+
Rotate_log_event r(
5971+
&new_name[dirname_length(new_name)], /* strlen() */ 0,
5972+
BIN_LOG_HEADER_SIZE,
5973+
is_relay_log ? Rotate_log_event::RELAY_LOG : 0
5974+
);
59725975
enum_binlog_checksum_alg checksum_alg = BINLOG_CHECKSUM_ALG_UNDEF;
59735976
/*
59745977
The current relay-log's closing Rotate event must have checksum

sql/log_event.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ class String;
9292
#define LOG_READ_CHECKSUM_FAILURE -8
9393
#define LOG_READ_DECRYPT -9
9494

95-
#define LOG_EVENT_OFFSET 4
96-
9795
/*
9896
3 is MySQL 4.x; 4 is MySQL 5.0.0.
9997
Compared to version 3, version 4 has:

sql/rpl_constants.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
#include <my_sys.h>
2121
#include <my_crypt.h>
2222

23+
/** Size of the `"\xfe""bin"` magic mumber */
24+
#define BIN_LOG_HEADER_SIZE 4
25+
2326
/**
2427
Enumeration of the incidents that can occur for the server.
2528
*/

sql/sql_repl.cc

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2261,7 +2261,9 @@ send_event_to_slave(binlog_send_info *info, Log_event_type event_type,
22612261
return "Failed on my_net_write()";
22622262
}
22632263

2264-
DBUG_PRINT("info", ("log event code %d", (*packet)[LOG_EVENT_OFFSET+1] ));
2264+
DBUG_PRINT("info", ("log event code %d",
2265+
(*packet)[/* Replication protocol status byte */ 1 + EVENT_TYPE_OFFSET]
2266+
));
22652267
if (event_type == LOAD_EVENT)
22662268
{
22672269
if (send_file(info->thd))
@@ -2528,7 +2530,9 @@ static int send_format_descriptor_event(binlog_send_info *info, IO_CACHE *log,
25282530
DBUG_RETURN(1);
25292531
}
25302532

2531-
event_type= (Log_event_type)((uchar)(*packet)[LOG_EVENT_OFFSET+ev_offset]);
2533+
event_type= static_cast<Log_event_type>(
2534+
static_cast<unsigned char>((*packet)[ev_offset + EVENT_TYPE_OFFSET])
2535+
);
25322536

25332537
/*
25342538
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,
26632667
DBUG_RETURN(1);
26642668
}
26652669

2666-
event_type= (Log_event_type)((uchar)(*packet)[LOG_EVENT_OFFSET + ev_offset]);
2670+
event_type= static_cast<Log_event_type>(
2671+
static_cast<unsigned char>((*packet)[ev_offset + EVENT_TYPE_OFFSET])
2672+
);
26672673
if (event_type == START_ENCRYPTION_EVENT)
26682674
{
26692675
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,
29312937
return 1;
29322938
}
29332939

2934-
Log_event_type event_type=
2935-
(Log_event_type)((uchar)(*packet)[LOG_EVENT_OFFSET+ev_offset]);
2940+
Log_event_type event_type= static_cast<Log_event_type>(
2941+
static_cast<unsigned char>((*packet)[ev_offset + EVENT_TYPE_OFFSET])
2942+
);
2943+
29362944

29372945
#ifndef DBUG_OFF
29382946
if (info->dbug_reconnect_counter > 0)

sql/unireg.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,6 @@
144144
*/
145145
#define MIN_TURBOBM_PATTERN_LEN 3
146146

147-
/*
148-
Defines for binary logging.
149-
Do not decrease the value of BIN_LOG_HEADER_SIZE.
150-
Do not even increase it before checking code.
151-
*/
152-
153-
#define BIN_LOG_HEADER_SIZE 4
154-
155147
#define DEFAULT_KEY_CACHE_NAME "default"
156148

157149

0 commit comments

Comments
 (0)