From c373e6c3d6ebd493cebf09f1eb14a40d185354cc Mon Sep 17 00:00:00 2001 From: Nikita Malyavin Date: Mon, 7 Aug 2023 22:25:17 +0400 Subject: [PATCH] Cleanup: make slave_exec_mode of its enum type and pack Log_event better Pack these fields together: event_owns_temp_buf cache_type slave_exec_mode checksum_alg Make them bitfields to fit a single 2-byte hole. This saves 24 bytes per event. SLAVE_EXEC_MODE_LAST_BIT is rewritten as > SLAVE_EXEC_MODE_LAST= SLAVE_EXEC_MODE_IDEMPOTENT to avoid a false-positive -Wbitfield-enum-conversion warning: Bit-field 'slave_exec_mode' is not wide enough to store all enumerators of 'enum_slave_exec_mode'. --- sql/log_event.h | 36 +++++++++++++++++++----------------- sql/log_event_server.cc | 8 ++++---- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/sql/log_event.h b/sql/log_event.h index 17d642bebaf45..848ad0cead985 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -54,6 +54,8 @@ #include "rpl_record.h" #include "rpl_reporting.h" #include "sql_class.h" /* THD */ +#else +typedef ulong enum_slave_exec_mode; #endif #include "rpl_gtid.h" @@ -1249,12 +1251,6 @@ class Log_event event's type, and its content is distributed in the event-specific fields. */ uchar *temp_buf; - - /* - TRUE <=> this event 'owns' temp_buf and should call my_free() when done - with it - */ - bool event_owns_temp_buf; /* Timestamp on the master(for debugging and replication of @@ -1284,13 +1280,29 @@ class Log_event */ uint16 flags; + /** + true <=> this event 'owns' temp_buf and should call my_free() when done + with it + */ + bool event_owns_temp_buf; + enum_event_cache_type cache_type; /** A storage to cache the global system variable's value. Handling of a separate event will be governed its member. */ - ulong slave_exec_mode; + enum_slave_exec_mode slave_exec_mode; + + /** + The value is set by caller of FD constructor and + Log_event::write_header() for the rest. + In the FD case it's propagated into the last byte + of post_header_len[] at FD::write(). + On the slave side the value is assigned from post_header_len[last] + of the last seen FD event. + */ + enum enum_binlog_checksum_alg checksum_alg; Log_event_writer *writer; @@ -1436,16 +1448,6 @@ class Log_event return read_log_event(file, packet, fdle, checksum_alg, get_max_packet()); } - /* - The value is set by caller of FD constructor and - Log_event::write_header() for the rest. - In the FD case it's propagated into the last byte - of post_header_len[] at FD::write(). - On the slave side the value is assigned from post_header_len[last] - of the last seen FD event. - */ - enum enum_binlog_checksum_alg checksum_alg; - static void *operator new(size_t size) { extern PSI_memory_key key_memory_log_event; diff --git a/sql/log_event_server.cc b/sql/log_event_server.cc index 46321c5915a82..afdb43db26494 100644 --- a/sql/log_event_server.cc +++ b/sql/log_event_server.cc @@ -544,8 +544,8 @@ int append_query_string(CHARSET_INFO *csinfo, String *to, **************************************************************************/ Log_event::Log_event(THD* thd_arg, uint16 flags_arg, bool using_trans) - :log_pos(0), temp_buf(0), exec_time(0), thd(thd_arg), - checksum_alg(BINLOG_CHECKSUM_ALG_UNDEF) + :log_pos(0), temp_buf(0), exec_time(0), + checksum_alg(BINLOG_CHECKSUM_ALG_UNDEF), thd(thd_arg) { server_id= thd->variables.server_id; when= thd->start_time; @@ -569,7 +569,7 @@ Log_event::Log_event(THD* thd_arg, uint16 flags_arg, bool using_trans) Log_event::Log_event() :temp_buf(0), exec_time(0), flags(0), cache_type(EVENT_INVALID_CACHE), - thd(0), checksum_alg(BINLOG_CHECKSUM_ALG_UNDEF) + checksum_alg(BINLOG_CHECKSUM_ALG_UNDEF), thd(0) { server_id= global_system_variables.server_id; /* @@ -5099,7 +5099,7 @@ int Rows_log_event::do_apply_event(rpl_group_info *rgi) bitmap_set_bit(table->write_set, table->s->vers.end_fieldno); } - this->slave_exec_mode= slave_exec_mode_options; // fix the mode + this->slave_exec_mode= (enum_slave_exec_mode)slave_exec_mode_options; // Do event specific preparations error= do_before_row_operations(rgi);