Skip to content

Commit

Permalink
Cleanup: make slave_exec_mode of its enum type and pack Log_event better
Browse files Browse the repository at this point in the history
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'.
  • Loading branch information
FooBarrior authored and vuvova committed Aug 15, 2023
1 parent 982b689 commit c373e6c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
36 changes: 19 additions & 17 deletions sql/log_event.h
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions sql/log_event_server.cc
Expand Up @@ -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;
Expand All @@ -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;
/*
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c373e6c

Please sign in to comment.