MySQL 8.3.0
Source Code Documentation
Rows_log_event Class Referenceabstract

Common base class for all row-containing log events. More...

#include <log_event.h>

Inheritance diagram for Rows_log_event:
[legend]

Classes

class  Key_compare
 

Public Types

enum  row_lookup_mode {
  ROW_LOOKUP_UNDEFINED = 0 , ROW_LOOKUP_NOT_NEEDED = 1 , ROW_LOOKUP_INDEX_SCAN = 2 , ROW_LOOKUP_TABLE_SCAN = 3 ,
  ROW_LOOKUP_HASH_SCAN = 4
}
 
enum  enum_error {
  ERR_OPEN_FAILURE = -1 , ERR_OK = 0 , ERR_TABLE_LIMIT_EXCEEDED = 1 , ERR_OUT_OF_MEM = 2 ,
  ERR_BAD_TABLE_DEF = 3 , ERR_RBR_TO_SBR = 4
}
 Enumeration of the errors that can be returned. More...
 
enum  { RLE_NO_FLAGS = 0U }
 
typedef uint16 flag_set
 
- Public Types inherited from mysql::binlog::event::Rows_event
enum  enum_flag {
  STMT_END_F = (1U << 0) , NO_FOREIGN_KEY_CHECKS_F = (1U << 1) , RELAXED_UNIQUE_CHECKS_F = (1U << 2) , COMPLETE_ROWS_F = (1U << 3) ,
  ALL_FLAGS
}
 These definitions allow to combine the flags into an appropriate flag set using the normal bitwise operators. More...
 
- Public Types inherited from mysql::binlog::event::Binary_log_event
enum  enum_post_header_length {
  QUERY_HEADER_MINIMAL_LEN = (4 + 4 + 1 + 2) , QUERY_HEADER_LEN = (QUERY_HEADER_MINIMAL_LEN + 2) , STOP_HEADER_LEN = 0 , START_V3_HEADER_LEN = (2 + ST_SERVER_VER_LEN + 4) ,
  ROTATE_HEADER_LEN = 8 , INTVAR_HEADER_LEN = 0 , APPEND_BLOCK_HEADER_LEN = 4 , DELETE_FILE_HEADER_LEN = 4 ,
  RAND_HEADER_LEN = 0 , USER_VAR_HEADER_LEN = 0 , FORMAT_DESCRIPTION_HEADER_LEN = (START_V3_HEADER_LEN + 1 + LOG_EVENT_TYPES) , XID_HEADER_LEN = 0 ,
  BEGIN_LOAD_QUERY_HEADER_LEN = APPEND_BLOCK_HEADER_LEN , ROWS_HEADER_LEN_V1 = 8 , TABLE_MAP_HEADER_LEN = 8 , EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN = (4 + 4 + 4 + 1) ,
  EXECUTE_LOAD_QUERY_HEADER_LEN , INCIDENT_HEADER_LEN = 2 , HEARTBEAT_HEADER_LEN = 0 , IGNORABLE_HEADER_LEN = 0 ,
  ROWS_HEADER_LEN_V2 = 10 , TRANSACTION_CONTEXT_HEADER_LEN = 18 , VIEW_CHANGE_HEADER_LEN = 52 , XA_PREPARE_HEADER_LEN = 0 ,
  TRANSACTION_PAYLOAD_HEADER_LEN = 0
}
 The lengths for the fixed data part of each event. More...
 
- Public Types inherited from Log_event
enum  enum_skip_reason { EVENT_SKIP_NOT , EVENT_SKIP_IGNORE , EVENT_SKIP_COUNT }
 Enumeration of what kinds of skipping (and non-skipping) that can occur when the slave executes an event. More...
 

Public Member Functions

 Rows_log_event (Rows_log_event &&) noexcept=delete
 
Rows_log_eventoperator= (Rows_log_event &&) noexcept=delete
 
 Rows_log_event (const Rows_log_event &)=delete
 
Rows_log_eventoperator= (const Rows_log_event &)=delete
 
 ~Rows_log_event () override
 
void set_flags (flag_set flags_arg)
 
void clear_flags (flag_set flags_arg)
 
flag_set get_flags (flag_set flags_arg) const
 
virtual mysql::binlog::event::Log_event_type get_general_type_code ()=0
 
int pack_info (Protocol *protocol) override
 Stores a string representation of this event in the Protocol. More...
 
int add_row_data (uchar *data, size_t length)
 
size_t get_data_size () override
 
MY_BITMAP const * get_cols () const
 
MY_BITMAP const * get_cols_ai () const
 
const mysql::binlog::event::Table_idget_table_id () const
 
virtual bool read_write_bitmaps_cmp (const TABLE *table) const =0
 Compares the table's read/write_set with the columns included in this event's before-image and/or after-image. More...
 
bool write_data_header (Basic_ostream *ostream) override
 
bool write_data_body (Basic_ostream *ostream) override
 
const char * get_db () override
 
- Public Member Functions inherited from mysql::binlog::event::Rows_event
 Rows_event (Log_event_type type_arg)
 Constructs an event directly. More...
 
 Rows_event (const char *buf, const Format_description_event *fde)
 The constructor is responsible for decoding the event contained in the buffer. More...
 
 ~Rows_event () override
 
unsigned long long get_table_id () const
 
enum_flag get_flags () const
 
uint32_t get_null_bits_len () const
 
unsigned long get_width () const
 
std::string get_enum_flag_string () const
 Gets the flags listed as strings. More...
 
- Public Member Functions inherited from mysql::binlog::event::Binary_log_event
virtual ~Binary_log_event ()=0
 
 Binary_log_event (const Binary_log_event &)=default
 
 Binary_log_event (Binary_log_event &&)=default
 
Binary_log_eventoperator= (const Binary_log_event &)=default
 
Binary_log_eventoperator= (Binary_log_event &&)=default
 
enum Log_event_type get_event_type () const
 Helper method. More...
 
const Log_event_headerheader () const
 Return a const pointer to the header of the log event. More...
 
Log_event_headerheader ()
 Return a non-const pointer to the header of the log event. More...
 
const Log_event_footerfooter () const
 Return a const pointer to the footer of the log event. More...
 
Log_event_footerfooter ()
 Return a non-const pointer to the footer of the log event. More...
 
Event_readerreader ()
 Returns a reference to the event Event_reader object. More...
 
- Public Member Functions inherited from Log_event
 Log_event (mysql::binlog::event::Log_event_header *header, mysql::binlog::event::Log_event_footer *footer, enum_event_cache_type cache_type_arg, enum_event_logging_type logging_type_arg)
 This minimal constructor is for when you are not even sure that there is a valid THD. More...
 
 Log_event (THD *thd_arg, uint16 flags_arg, enum_event_cache_type cache_type_arg, enum_event_logging_type logging_type_arg, mysql::binlog::event::Log_event_header *header, mysql::binlog::event::Log_event_footer *footer)
 
int net_send (Protocol *protocol, const char *log_name, my_off_t pos)
 Only called by SHOW BINLOG EVENTS. More...
 
void * operator new (size_t size)
 
bool wrapper_my_b_safe_write (Basic_ostream *ostream, const uchar *buf, size_t data_length)
 Write the given buffer to the given output stream, updating the checksum if checksums are enabled. More...
 
virtual bool write (Basic_ostream *ostream)
 
time_t get_time ()
 Prints a "session_var=value" string. More...
 
virtual mysql::binlog::event::Log_event_type get_type_code () const
 
virtual bool is_sbr_logging_format () const
 Return true if the event has to be logged using SBR for DMLs. More...
 
bool is_valid ()
 
void set_artificial_event ()
 
void set_relay_log_event ()
 
bool is_artificial_event () const
 
bool is_relay_log_event () const
 
bool is_ignorable_event () const
 
bool is_no_filter_event () const
 
bool is_using_trans_cache () const
 
bool is_using_stmt_cache () const
 
bool is_using_immediate_logging () const
 
 Log_event (mysql::binlog::event::Log_event_header *header, mysql::binlog::event::Log_event_footer *footer)
 
virtual void claim_memory_ownership (bool claim)
 Allow thread to CLAIM or DISCLAIM the ownership of this object depends on the parameter value passed. More...
 
virtual ~Log_event ()
 
void register_temp_buf (char *buf, bool free_in_destructor=true)
 
void free_temp_buf ()
 
const char * get_type_str () const
 Returns the human readable name of this event's type. More...
 
bool is_mts_sequential_exec ()
 Is called from get_mts_execution_mode() to. More...
 
virtual uint8 get_mts_dbs (Mts_db_names *arg, Rpl_filter *rpl_filter)
 The method fills in pointers to event's database name c-strings to a supplied array. More...
 
bool contains_partition_info (bool)
 
virtual uint8 mts_number_dbs ()
 
bool is_mts_group_isolated ()
 
virtual bool starts_group () const
 Events of a certain type can start or end a group of events treated transactionally wrt binlog. More...
 
virtual bool ends_group () const
 
int apply_event (Relay_log_info *rli)
 Apply the event to the database. More...
 
int apply_gtid_event (Relay_log_info *rli)
 Apply the GTID event in curr_group_data to the database. More...
 
int update_pos (Relay_log_info *rli)
 Update the relay log position. More...
 
enum_skip_reason shall_skip (Relay_log_info *rli)
 Decide if the event shall be skipped, and the reason for skipping it. More...
 
virtual int do_apply_event_worker (Slave_worker *w)
 

Public Attributes

uint m_row_count
 
- Public Attributes inherited from mysql::binlog::event::Rows_event
Extra_row_info m_extra_row_info
 
- Public Attributes inherited from Log_event
char * temp_buf
 
bool m_free_temp_buf_in_destructor
 
ulong exec_time
 
uint32 server_id
 
ulong rbr_exec_mode
 A storage to cache the global system variable's value. More...
 
enum_event_cache_type event_cache_type
 Defines the type of the cache, if any, where the event will be stored before being flushed to disk. More...
 
enum_event_logging_type event_logging_type
 Defines when information, i.e. More...
 
ha_checksum crc
 Placeholder for event checksum while writing to binlog. More...
 
ulong mts_group_idx
 Index in rli->gaq array to indicate a group that this event is purging. More...
 
mysql::binlog::event::Log_event_headercommon_header
 The Log_event_header class contains the variable present in the common header. More...
 
mysql::binlog::event::Log_event_footercommon_footer
 The Log_event_footer class contains the variable present in the common footer. More...
 
Relay_log_infoworker
 MTS: associating the event with either an assigned Worker or Coordinator. More...
 
ulonglong future_event_relay_log_pos
 A copy of the main rli value stored into event to pass to MTS worker rli. More...
 
THDthd
 
db_worker_hash_entrymts_assigned_partitions [MAX_DBS_IN_EVENT_MTS]
 Partition info associate with event to deliver to MTS event applier. More...
 

Protected Member Functions

 Rows_log_event (THD *, TABLE *, const mysql::binlog::event::Table_id &table_id, MY_BITMAP const *cols, bool is_transactional, mysql::binlog::event::Log_event_type event_type, const unsigned char *extra_row_ndb_info)
 
 Rows_log_event (const char *row_data, const mysql::binlog::event::Format_description_event *description_event)
 
virtual int do_add_row_data (uchar *data, size_t length)
 
int unpack_current_row (const Relay_log_info *const rli, MY_BITMAP const *cols, bool is_after_image, bool only_seek=false)
 Unpack the current row image from the event into m_table->record[0]. More...
 
int update_generated_columns (MY_BITMAP const &fields_to_update)
 Updates the generated columns of the TABLE object referenced by m_table, that have an active bit in the parameter bitset fields_to_update. More...
 
void decide_row_lookup_algorithm_and_key () SUPPRESS_UBSAN_CLANG10
 
int row_operations_scan_and_key_setup ()
 
int row_operations_scan_and_key_teardown (int error)
 
bool is_auto_inc_in_extra_columns (const Relay_log_info *const rli)
 Helper function to check whether there is an auto increment column on the table where the event is to be applied. More...
 
bool is_rbr_logging_format () const override
 Return true if the event has to be logged using RBR for DMLs. More...
 
- Protected Member Functions inherited from mysql::binlog::event::Binary_log_event
 Binary_log_event (Log_event_type type_code)
 This constructor is used to initialize the type_code of header object m_header. More...
 
 Binary_log_event (const char **buf, const Format_description_event *fde)
 This constructor will create a new object of Log_event_header and initialize the variable m_header, which in turn will be used to initialize Log_event's member common_header. More...
 
- Protected Member Functions inherited from Log_event
uint32 write_header_to_memory (uchar *buf)
 Writes the common header of this event to the given memory buffer. More...
 
bool write_header (Basic_ostream *ostream, size_t data_length)
 Writes the common-header of this event to the given output stream and updates the checksum. More...
 
bool write_footer (Basic_ostream *ostream)
 
bool need_checksum ()
 A decider of whether to trigger checksum computation or not. More...
 
enum_skip_reason continue_group (Relay_log_info *rli)
 Helper function to ignore an event w.r.t. More...
 

Static Protected Member Functions

static bool is_trx_retryable_upon_engine_error (int error)
 Helper function to check whether the storage engine error allows for the transaction to be retried or not. More...
 

Protected Attributes

Rows_applier_psi_stage m_psi_progress
 
TABLEm_table
 
MY_BITMAP m_cols
 
MY_BITMAP m_local_cols
 Bitmap denoting columns available in the image as they appear in the table setup. More...
 
Hash_slave_rows m_hash
 Hash table that will hold the entries for while using HASH_SCAN algorithm to search and update/delete rows. More...
 
uint m_rows_lookup_algorithm
 The algorithm to use while searching for rows using the before image. More...
 
MY_BITMAP m_cols_ai
 Bitmap for columns available in the after image, if present. More...
 
MY_BITMAP m_local_cols_ai
 Bitmap denoting columns available in the after-image as they appear in the table setup. More...
 
uint32 m_bitbuf [128/(sizeof(uint32) *8)]
 
uint32 m_bitbuf_ai [128/(sizeof(uint32) *8)]
 
ucharm_rows_buf
 
ucharm_rows_cur
 
ucharm_rows_end
 
const ucharm_curr_row
 
const ucharm_curr_row_end
 
ucharm_key
 
uint m_key_index
 
KEYm_key_info
 
std::set< uchar *, Key_comparem_distinct_keys
 
std::set< uchar *, Key_compare >::iterator m_itr
 
ucharm_distinct_key_spare_buf
 A spare buffer which will be used when saving the distinct keys for doing an index scan with HASH_SCAN search algorithm. More...
 
- Protected Attributes inherited from mysql::binlog::event::Rows_event
Log_event_type m_type
 
Table_id m_table_id
 Actual event type. More...
 
uint16_t m_flags
 
unsigned long m_width
 Flags for row-level events. More...
 
uint32_t n_bits_len
 The width of the columns bitmap. More...
 
uint16_t var_header_len
 value determined by (m_width + 7) / 8 More...
 
std::vector< uint8_t > columns_before_image
 
std::vector< uint8_t > columns_after_image
 
std::vector< uint8_t > row
 

Private Member Functions

int do_apply_event (Relay_log_info const *rli) override
 Primitive to apply an event to the database. More...
 
int do_update_pos (Relay_log_info *rli) override
 The method either increments the relay log position or commits the current statement and increments the master group position if the event is STMT_END_F flagged and the statement corresponds to the autocommit query (i.e replicated without wrapping in BEGIN/COMMIT) More...
 
enum_skip_reason do_shall_skip (Relay_log_info *rli) override
 Decide if this event shall be skipped or not and the reason for skipping it. More...
 
virtual int do_before_row_operations (const Relay_log_info *const log)=0
 
virtual int do_after_row_operations (const Relay_log_info *const log, int error)=0
 
virtual int do_exec_row (const Relay_log_info *const rli)=0
 
int handle_idempotent_and_ignored_errors (Relay_log_info const *rli, int *err)
 Private member function called while handling idempotent errors. More...
 
void do_post_row_operations (Relay_log_info const *rli, int err)
 Private member function called after updating/deleting a row. More...
 
int do_apply_row (Relay_log_info const *rli)
 Commodity wrapper around do_exec_row(), that deals with resetting the thd reference in the table. More...
 
int do_index_scan_and_update (Relay_log_info const *rli)
 Implementation of the index scan and update algorithm. More...
 
int do_hash_scan_and_update (Relay_log_info const *rli)
 Implementation of the hash_scan and update algorithm. More...
 
int do_table_scan_and_update (Relay_log_info const *rli)
 Implementation of the legacy table_scan and update algorithm. More...
 
virtual int skip_after_image_for_update_event (const Relay_log_info *rli, const uchar *curr_bi_start)
 Seek past the after-image of an update event, in case a row was processed without reading the after-image. More...
 
int open_record_scan ()
 Initializes scanning of rows. More...
 
int close_record_scan ()
 Does the cleanup. More...
 
int next_record_scan (bool first_read)
 Fetches next row. More...
 
int add_key_to_distinct_keyset ()
 Populates the m_distinct_keys with unique keys to be modified during HASH_SCAN over keys. More...
 
int do_hash_row (Relay_log_info const *rli)
 Populates the m_hash when using HASH_SCAN. More...
 
int do_scan_and_update (Relay_log_info const *rli)
 This member function scans the table and applies the changes that had been previously hashed. More...
 

Private Attributes

ColumnViewPtr m_column_view {nullptr}
 Wrapper around TABLE *m_table that abstracts the table field set iteration logic, since it is not mandatory that all table fields are to be replicated. More...
 
MY_BITMAP write_set_backup
 This bitmap is used as a backup for the write set while we calculate the values for any hidden generated columns (functional indexes). More...
 

Friends

class Old_rows_log_event
 

Additional Inherited Members

- Static Public Member Functions inherited from mysql::binlog::event::Rows_event
static std::string get_flag_string (enum_flag flag)
 Gets a string describing the flags. More...
 
- Static Public Member Functions inherited from Log_event
static void init_show_field_list (mem_root_deque< Item * > *field_list)
 init_show_field_list() prepares the column names and types for the output of SHOW BINLOG EVENTS; it is used only by SHOW BINLOG EVENTS. More...
 
static void operator delete (void *ptr, size_t)
 
static void * operator new (size_t, void *ptr)
 
static void operator delete (void *, void *)
 
static const char * get_type_str (mysql::binlog::event::Log_event_type type)
 Returns the human readable name of the given event type. More...
 
static const char * get_type_str (uint type)
 Get the name of an event type, or "Unknown" if out of range. More...
 
- Static Public Attributes inherited from mysql::binlog::event::Binary_log_event
static const int LOG_EVENT_TYPES = (ENUM_END_EVENT - 1)
 
- Protected Types inherited from Log_event
enum  enum_event_cache_type {
  EVENT_INVALID_CACHE = 0 , EVENT_STMT_CACHE , EVENT_TRANSACTIONAL_CACHE , EVENT_NO_CACHE ,
  EVENT_CACHE_COUNT
}
 
enum  enum_event_logging_type { EVENT_INVALID_LOGGING = 0 , EVENT_NORMAL_LOGGING , EVENT_IMMEDIATE_LOGGING , EVENT_CACHE_LOGGING_COUNT }
 

Detailed Description

Common base class for all row-containing log events.

RESPONSIBILITIES

Encode the common parts of all events containing rows, which are:

  • Write data header and data body to an IO_CACHE.

Virtual inheritance is required here to handle the diamond problem in the class Write_rows_log_event, Update_rows_log_event and Delete_rows_log_event. The diamond structure is explained in Write_rows_log_event, Update_rows_log_event, Delete_rows_log_event

Member Typedef Documentation

◆ flag_set

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
RLE_NO_FLAGS 

◆ enum_error

Enumeration of the errors that can be returned.

Enumerator
ERR_OPEN_FAILURE 

Failure to open table.

ERR_OK 

No error.

ERR_TABLE_LIMIT_EXCEEDED 

No more room for tables.

ERR_OUT_OF_MEM 

Out of memory.

ERR_BAD_TABLE_DEF 

Table definition does not match.

ERR_RBR_TO_SBR 

daisy-chanining RBR to SBR not allowed

◆ row_lookup_mode

Enumerator
ROW_LOOKUP_UNDEFINED 
ROW_LOOKUP_NOT_NEEDED 
ROW_LOOKUP_INDEX_SCAN 
ROW_LOOKUP_TABLE_SCAN 
ROW_LOOKUP_HASH_SCAN 

Constructor & Destructor Documentation

◆ Rows_log_event() [1/4]

Rows_log_event::Rows_log_event ( Rows_log_event &&  )
deletenoexcept

◆ Rows_log_event() [2/4]

Rows_log_event::Rows_log_event ( const Rows_log_event )
delete

◆ ~Rows_log_event()

Rows_log_event::~Rows_log_event ( )
override

◆ Rows_log_event() [3/4]

Rows_log_event::Rows_log_event ( THD thd_arg,
TABLE tbl_arg,
const mysql::binlog::event::Table_id table_id,
MY_BITMAP const *  cols,
bool  is_transactional,
mysql::binlog::event::Log_event_type  event_type,
const unsigned char *  extra_row_ndb_info 
)
protected

◆ Rows_log_event() [4/4]

Rows_log_event::Rows_log_event ( const char *  row_data,
const mysql::binlog::event::Format_description_event description_event 
)
protected

Member Function Documentation

◆ add_key_to_distinct_keyset()

int Rows_log_event::add_key_to_distinct_keyset ( )
private

Populates the m_distinct_keys with unique keys to be modified during HASH_SCAN over keys.

Returns
0 success, or the error code.
Return values
0success

◆ add_row_data()

int Rows_log_event::add_row_data ( uchar data,
size_t  length 
)
inline

◆ clear_flags()

void Rows_log_event::clear_flags ( flag_set  flags_arg)
inline

◆ close_record_scan()

int Rows_log_event::close_record_scan ( )
private

Does the cleanup.

  • closes the index if opened by open_record_scan
  • closes the table if opened for scanning.

◆ decide_row_lookup_algorithm_and_key()

void Rows_log_event::decide_row_lookup_algorithm_and_key ( )
protected

◆ do_add_row_data()

int Rows_log_event::do_add_row_data ( uchar data,
size_t  length 
)
protectedvirtual

◆ do_after_row_operations()

virtual int Rows_log_event::do_after_row_operations ( const Relay_log_info *const  log,
int  error 
)
privatepure virtual

◆ do_apply_event()

int Rows_log_event::do_apply_event ( Relay_log_info const *  rli)
overrideprivatevirtual

Primitive to apply an event to the database.

This is where the change to the database is made.

Note
The primitive is protected instead of private, since there is a hierarchy of actions to be performed in some cases.
See also
Format_description_log_event::do_apply_event()
Parameters
rliPointer to relay log info structure
Return values
0Event applied successfully
errnoError code if event application failed

When using RBR and MyISAM MERGE tables the base tables that make up the MERGE table can be appended to the list of tables to lock.

Thus, we just check compatibility for those that tables that have a correspondent table map event (ie, those that are actually going to be accessed while applying the event). That's why the loop stops at rli->tables_to_lock_count .

NOTE: The base tables are added here are removed when close_thread_tables is called.

Skip update rows events that don't have data for this slave's table.

If there are no columns marked in the read_set for this table, that means that we cannot lookup any row using the available BI in the binary log. Thence, we immediately raise an error: HA_ERR_END_OF_FILE.

Reimplemented from Log_event.

◆ do_apply_row()

int Rows_log_event::do_apply_row ( Relay_log_info const *  rli)
private

Commodity wrapper around do_exec_row(), that deals with resetting the thd reference in the table.

◆ do_before_row_operations()

virtual int Rows_log_event::do_before_row_operations ( const Relay_log_info *const  log)
privatepure virtual

◆ do_exec_row()

virtual int Rows_log_event::do_exec_row ( const Relay_log_info *const  rli)
privatepure virtual

◆ do_hash_row()

int Rows_log_event::do_hash_row ( Relay_log_info const *  rli)
private

Populates the m_hash when using HASH_SCAN.

Thence, it:

  • unpacks the before image (BI)
  • saves the positions
  • saves the positions into the hash map, using the BI checksum as key
  • unpacks the after image (AI) if needed, so that m_curr_row_end gets updated correctly.
Parameters
rliThe reference to the relay log info object.
Returns
0 on success. Otherwise, the error code.

◆ do_hash_scan_and_update()

int Rows_log_event::do_hash_scan_and_update ( Relay_log_info const *  rli)
private

Implementation of the hash_scan and update algorithm.

It collects rows positions in a hashtable until the last row is unpacked. Then it scans the table to update and when a record in the table matches the one in the hashtable, the update/delete is performed.

◆ do_index_scan_and_update()

int Rows_log_event::do_index_scan_and_update ( Relay_log_info const *  rli)
private

Implementation of the index scan and update algorithm.

It uses PK, UK or regular Key to search for the record to update. When found it updates it.

◆ do_post_row_operations()

void Rows_log_event::do_post_row_operations ( Relay_log_info const *  rli,
int  err 
)
private

Private member function called after updating/deleting a row.

It performs some assertions and more importantly, it updates m_curr_row so that the next row is processed during the row execution main loop (Rows_log_event::do_apply_event()).

Parameters
rliPointer to relay log info structure.
errthe current error code.

◆ do_scan_and_update()

int Rows_log_event::do_scan_and_update ( Relay_log_info const *  rli)
private

This member function scans the table and applies the changes that had been previously hashed.

As such, m_hash MUST be filled by do_hash_row before calling this member function.

Parameters
rliThe reference to the relay log info object.
Returns
0 on success. Otherwise, the error code.

The do..while loop takes care of the scenario of same row being updated more than once within a single Update_rows_log_event by performing the hash lookup for the updated_row(by taking the AI stored in table->record[0] after the ha_update_row()) when table has no primary key.

This can happen when update is called from a stored function. Ex: CREATE FUNCTION f1 () RETURNS INT BEGIN UPDATE t1 SET a = 2 WHERE a = 1; UPDATE t1 SET a = 3 WHERE a = 2; RETURN 0; END

If there are collisions we need to be sure that this is indeed the record we want. Loop through all records for the given key and explicitly compare them against the record we got from the storage engine.

We found the entry we needed, just apply the changes.

At this point, both table->record[0] and table->record[1] have the SE row that matched the one in the hash table.

Thence if this is a DELETE we wouldn't need to mess around with positions anymore, but since this can be an update, we need to provide positions so that AI is unpacked correctly to table->record[0] in UPDATE implementation of do_exec_row().

if the rbr_exec_mode is set to Idempotent, we cannot expect the hash to be empty. In such cases we count the number of idempotent errors and check if it is equal to or greater than the number of rows left in the hash.

Reset the last positions, because the positions are lost while handling entries in the hash.

◆ do_shall_skip()

Log_event::enum_skip_reason Rows_log_event::do_shall_skip ( Relay_log_info rli)
overrideprivatevirtual

Decide if this event shall be skipped or not and the reason for skipping it.

The default implementation decide that the event shall be skipped if either:

  • the server id of the event is the same as the server id of the server and rli->replicate_same_server_id is true, or
  • if rli->slave_skip_counter is greater than zero.
See also
do_apply_event
do_update_pos
Return values
Log_event::EVENT_SKIP_NOTThe event shall not be skipped and should be applied.
Log_event::EVENT_SKIP_IGNOREThe event shall be skipped by just ignoring it, i.e., the slave skip counter shall not be changed. This happends if, for example, the originating server id of the event is the same as the server id of the slave.
Log_event::EVENT_SKIP_COUNTThe event shall be skipped because the slave skip counter was non-zero. The caller shall decrease the counter by one.

Reimplemented from Log_event.

◆ do_table_scan_and_update()

int Rows_log_event::do_table_scan_and_update ( Relay_log_info const *  rli)
private

Implementation of the legacy table_scan and update algorithm.

For each unpacked row it scans the storage engine table for a match. When a match is found, the update/delete operations are performed.

unpack the before image

save a copy so that we can compare against it later

◆ do_update_pos()

int Rows_log_event::do_update_pos ( Relay_log_info rli)
overrideprivatevirtual

The method either increments the relay log position or commits the current statement and increments the master group position if the event is STMT_END_F flagged and the statement corresponds to the autocommit query (i.e replicated without wrapping in BEGIN/COMMIT)

Return values
0Success
non-zeroError in the statement commit

Reimplemented from Log_event.

◆ get_cols()

MY_BITMAP const * Rows_log_event::get_cols ( ) const
inline

◆ get_cols_ai()

MY_BITMAP const * Rows_log_event::get_cols_ai ( ) const
inline

◆ get_data_size()

size_t Rows_log_event::get_data_size ( )
overridevirtual

Reimplemented from Log_event.

◆ get_db()

const char * Rows_log_event::get_db ( )
inlineoverridevirtual

Reimplemented from Log_event.

◆ get_flags()

flag_set Rows_log_event::get_flags ( flag_set  flags_arg) const
inline

◆ get_general_type_code()

virtual mysql::binlog::event::Log_event_type Rows_log_event::get_general_type_code ( )
pure virtual

◆ get_table_id()

const mysql::binlog::event::Table_id & Rows_log_event::get_table_id ( ) const
inline

◆ handle_idempotent_and_ignored_errors()

int Rows_log_event::handle_idempotent_and_ignored_errors ( Relay_log_info const *  rli,
int *  err 
)
private

Private member function called while handling idempotent errors.

Parameters
rliPointer to relay log info structure.
[in,out]errthe error to handle. If it is listed as idempotent/ignored related error, then it is cleared.
Returns
true if the slave should stop executing rows.

◆ is_auto_inc_in_extra_columns()

bool Rows_log_event::is_auto_inc_in_extra_columns ( const Relay_log_info *const  rli)
protected

Helper function to check whether there is an auto increment column on the table where the event is to be applied.

GIPKs when not present in the source table are also considered a auto inc column in a extra column.

Parameters
rlithe relay log object associated to the replicated table
Returns
true if there is an autoincrement field on the extra columns, false otherwise.

◆ is_rbr_logging_format()

bool Rows_log_event::is_rbr_logging_format ( ) const
inlineoverrideprotectedvirtual

Return true if the event has to be logged using RBR for DMLs.

Reimplemented from Log_event.

◆ is_trx_retryable_upon_engine_error()

bool Rows_log_event::is_trx_retryable_upon_engine_error ( int  error)
staticprotected

Helper function to check whether the storage engine error allows for the transaction to be retried or not.

Parameters
errorStorage engine error
Return values
trueif the error is retryable.
falseif the error is non-retryable.

◆ next_record_scan()

int Rows_log_event::next_record_scan ( bool  first_read)
private

Fetches next row.

If it is a HASH_SCAN over an index, it populates table->record[0] with the next row corresponding to the index. If the indexes are in non-contigous ranges it fetches record corresponding to the key value in the next range.

Parameters
first_readsignifying if this is the first time we are reading a row over an index.
Returns
error code when there are no more records to be fetched or some other error occurred,
  • 0 otherwise.

◆ open_record_scan()

int Rows_log_event::open_record_scan ( )
private

Initializes scanning of rows.

Opens an index and initializes an iterator over a list of distinct keys (m_distinct_keys) if it is a HASH_SCAN over an index or the table if its a HASH_SCAN over the table.

◆ operator=() [1/2]

Rows_log_event & Rows_log_event::operator= ( const Rows_log_event )
delete

◆ operator=() [2/2]

Rows_log_event & Rows_log_event::operator= ( Rows_log_event &&  )
deletenoexcept

◆ pack_info()

int Rows_log_event::pack_info ( Protocol protocol)
overridevirtual

Stores a string representation of this event in the Protocol.

This is used by SHOW BINLOG EVENTS.

Return values
0success
nonzeroerror

Reimplemented from Log_event.

◆ read_write_bitmaps_cmp()

virtual bool Rows_log_event::read_write_bitmaps_cmp ( const TABLE table) const
pure virtual

Compares the table's read/write_set with the columns included in this event's before-image and/or after-image.

Each subclass (Write/Update/Delete) implements this function by comparing on the image(s) pertinent to the subclass.

Parameters
[in]tableThe table to compare this events bitmaps against.
Return values
trueif sets match
falseotherwise (following bitmap_cmp return logic).

Implemented in Write_rows_log_event, Update_rows_log_event, and Delete_rows_log_event.

◆ row_operations_scan_and_key_setup()

int Rows_log_event::row_operations_scan_and_key_setup ( )
protected

◆ row_operations_scan_and_key_teardown()

int Rows_log_event::row_operations_scan_and_key_teardown ( int  error)
protected

◆ set_flags()

void Rows_log_event::set_flags ( flag_set  flags_arg)
inline

◆ skip_after_image_for_update_event()

virtual int Rows_log_event::skip_after_image_for_update_event ( const Relay_log_info rli,
const uchar curr_bi_start 
)
inlineprivatevirtual

Seek past the after-image of an update event, in case a row was processed without reading the after-image.

An update event may process a row without reading the after-image, e.g. in case of ignored or idempotent errors. To ensure that the read position for the next row is correct, we need to seek past the after-image.

Parameters
rliThe applier context
curr_bi_startThe read position of the beginning of the before-image. (The function compares this with m_curr_row to know if the after-image has been read or not.)
Return values
0Success
ER_*Error code returned by unpack_current_row

Reimplemented in Update_rows_log_event.

◆ unpack_current_row()

int Rows_log_event::unpack_current_row ( const Relay_log_info *const  rli,
MY_BITMAP const *  cols,
bool  is_after_image,
bool  only_seek = false 
)
protected

Unpack the current row image from the event into m_table->record[0].

Parameters
rliThe applier context.
colsThe bitmap of columns included in the update.
is_after_imageShould be true if this is an after-image, false if it is a before-image.
only_seekunpack_row()
Return values
0Success
ER_*On error, it is guaranteed that the error has been reported through my_error, and the corresponding ER_* code is returned. Currently the error codes are: EE_OUTOFMEMORY, ER_REPLICA_CORRUPT_EVENT, or various JSON errors when applying JSON diffs (ER_COULD_NOT_APPLY_JSON_DIFF, ER_INVALID_JSON_BINARY_DATA, and maybe others).

◆ update_generated_columns()

int Rows_log_event::update_generated_columns ( MY_BITMAP const &  fields_to_update)
protected

Updates the generated columns of the TABLE object referenced by m_table, that have an active bit in the parameter bitset fields_to_update.

Parameters
fields_to_updateA bitset where the bit at the index of generated columns to update must be set to 1
Returns
0 if the operation terminated successfully, 1 otherwise.

◆ write_data_body()

bool Rows_log_event::write_data_body ( Basic_ostream ostream)
overridevirtual

Reimplemented from Log_event.

◆ write_data_header()

bool Rows_log_event::write_data_header ( Basic_ostream ostream)
overridevirtual

Reimplemented from Log_event.

Friends And Related Function Documentation

◆ Old_rows_log_event

friend class Old_rows_log_event
friend

Member Data Documentation

◆ m_bitbuf

uint32 Rows_log_event::m_bitbuf[128/(sizeof(uint32) *8)]
protected

◆ m_bitbuf_ai

uint32 Rows_log_event::m_bitbuf_ai[128/(sizeof(uint32) *8)]
protected

◆ m_cols

MY_BITMAP Rows_log_event::m_cols
protected

◆ m_cols_ai

MY_BITMAP Rows_log_event::m_cols_ai
protected

Bitmap for columns available in the after image, if present.

These fields are only available for Update_rows events. Observe that the width of both the before image COLS vector and the after image COLS vector is the same: the number of columns of the table on the master.

◆ m_column_view

ColumnViewPtr Rows_log_event::m_column_view {nullptr}
private

Wrapper around TABLE *m_table that abstracts the table field set iteration logic, since it is not mandatory that all table fields are to be replicated.

For details,

See also
ReplicatedColumnsView class documentation.

A smart pointer is used here as the developer might want to instantiate the view using different classes in runtime depending on the given context.

◆ m_curr_row

const uchar* Rows_log_event::m_curr_row
protected

◆ m_curr_row_end

const uchar* Rows_log_event::m_curr_row_end
protected

◆ m_distinct_key_spare_buf

uchar* Rows_log_event::m_distinct_key_spare_buf
protected

A spare buffer which will be used when saving the distinct keys for doing an index scan with HASH_SCAN search algorithm.

◆ m_distinct_keys

std::set<uchar *, Key_compare> Rows_log_event::m_distinct_keys
protected

◆ m_hash

Hash_slave_rows Rows_log_event::m_hash
protected

Hash table that will hold the entries for while using HASH_SCAN algorithm to search and update/delete rows.

◆ m_itr

std::set<uchar*,Key_compare>::iterator Rows_log_event::m_itr
protected

◆ m_key

uchar* Rows_log_event::m_key
protected

◆ m_key_index

uint Rows_log_event::m_key_index
protected

◆ m_key_info

KEY* Rows_log_event::m_key_info
protected

◆ m_local_cols

MY_BITMAP Rows_log_event::m_local_cols
protected

Bitmap denoting columns available in the image as they appear in the table setup.

On some setups, the number and order of columns may differ from master to slave so, a bitmap for local available columns is computed using ReplicatedColumnsView utility class.

◆ m_local_cols_ai

MY_BITMAP Rows_log_event::m_local_cols_ai
protected

Bitmap denoting columns available in the after-image as they appear in the table setup.

On some setups, the number and order of columns may differ from master to slave so, a bitmap for local available columns is computed using ReplicatedColumnsView utility class.

◆ m_psi_progress

Rows_applier_psi_stage Rows_log_event::m_psi_progress
protected

◆ m_row_count

uint Rows_log_event::m_row_count

◆ m_rows_buf

uchar* Rows_log_event::m_rows_buf
protected

◆ m_rows_cur

uchar* Rows_log_event::m_rows_cur
protected

◆ m_rows_end

uchar* Rows_log_event::m_rows_end
protected

◆ m_rows_lookup_algorithm

uint Rows_log_event::m_rows_lookup_algorithm
protected

The algorithm to use while searching for rows using the before image.

◆ m_table

TABLE* Rows_log_event::m_table
protected

◆ write_set_backup

MY_BITMAP Rows_log_event::write_set_backup
private

This bitmap is used as a backup for the write set while we calculate the values for any hidden generated columns (functional indexes).

In order to calculate the values, the columns must be marked in the write set. After the values are calculated, we set the write set back to its original value.


The documentation for this class was generated from the following files: