MySQL  8.0.18
Source Code Documentation
log_event.cc File Reference
#include "sql/log_event.h"
#include "my_config.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include "base64.h"
#include "decimal.h"
#include "libbinlogevents/export/binary_log_funcs.h"
#include "libbinlogevents/include/debug_vars.h"
#include "libbinlogevents/include/table_id.h"
#include "libbinlogevents/include/wrapper_functions.h"
#include "m_ctype.h"
#include "my_bitmap.h"
#include "my_byteorder.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_io.h"
#include "my_loglevel.h"
#include "my_macros.h"
#include "my_table_map.h"
#include "my_time.h"
#include "mysql.h"
#include "mysql/components/services/log_builtins.h"
#include "mysql/components/services/log_shared.h"
#include "mysql/components/services/psi_statement_bits.h"
#include "mysql/psi/mysql_mutex.h"
#include "mysql/udf_registration_types.h"
#include "mysql_time.h"
#include "psi_memory_key.h"
#include "query_options.h"
#include "sql/auth/auth_acls.h"
#include "sql/binlog_reader.h"
#include "sql/my_decimal.h"
#include "sql/rpl_handler.h"
#include "sql/rpl_tblmap.h"
#include "sql/system_variables.h"
#include "sql/tc_log.h"
#include "sql_const.h"
#include "sql_string.h"
#include "template_utils.h"
#include <errno.h>
#include <fcntl.h>
#include <cstdint>
#include <new>
#include "libbinlogevents/include/binary_log.h"
#include "my_base.h"
#include "my_command.h"
#include "my_dir.h"
#include "my_sqlcommand.h"
#include "mysql/plugin.h"
#include "mysql/psi/mysql_cond.h"
#include "mysql/psi/mysql_file.h"
#include "mysql/psi/mysql_stage.h"
#include "mysql/psi/mysql_statement.h"
#include "mysql/psi/mysql_transaction.h"
#include "mysql/psi/psi_statement.h"
#include "mysqld_error.h"
#include "prealloced_array.h"
#include "sql/auth/auth_common.h"
#include "sql/auth/sql_security_ctx.h"
#include "sql/basic_ostream.h"
#include "sql/binlog.h"
#include "sql/current_thd.h"
#include "sql/dd/types/abstract_table.h"
#include "sql/debug_sync.h"
#include "sql/derror.h"
#include "sql/enum_query_type.h"
#include "sql/field.h"
#include "sql/handler.h"
#include "sql/item.h"
#include "sql/item_func.h"
#include "sql/key.h"
#include "sql/log.h"
#include "sql/mdl.h"
#include "sql/mysqld.h"
#include "sql/protocol.h"
#include "sql/rpl_msr.h"
#include "sql/rpl_mts_submode.h"
#include "sql/rpl_reporting.h"
#include "sql/rpl_rli.h"
#include "sql/rpl_rli_pdb.h"
#include "sql/rpl_slave.h"
#include "sql/sp_head.h"
#include "sql/sql_base.h"
#include "sql/sql_bitmap.h"
#include "sql/sql_class.h"
#include "sql/sql_cmd.h"
#include "sql/sql_data_change.h"
#include "sql/sql_db.h"
#include "sql/sql_digest_stream.h"
#include "sql/sql_error.h"
#include "sql/sql_exchange.h"
#include "sql/sql_lex.h"
#include "sql/sql_list.h"
#include "sql/sql_load.h"
#include "sql/sql_locale.h"
#include "sql/sql_parse.h"
#include "sql/sql_plugin.h"
#include "sql/sql_show.h"
#include "sql/sql_tablespace.h"
#include "sql/table.h"
#include "sql/transaction.h"
#include "sql/transaction_info.h"
#include "sql/tztime.h"
#include "thr_lock.h"
#include "sql/rpl_gtid.h"
#include "sql/rpl_record.h"
#include "sql/rpl_utility.h"
#include "sql/xa_aux.h"

Macros

#define LOG_SUBSYSTEM_TAG   "Repl"
 
#define window_size   Log_throttle::LOG_THROTTLE_WINDOW_SIZE
 
#define log_cs   &my_charset_latin1
 
#define FMT_G_BUFSIZE(PREC)   (3 + (PREC) + 5 + 1)
 

Enumerations

enum  enum_tbl_map_status {
  OK_TO_PROCESS = 0, FILTERED_OUT = 1, SAME_ID_MAPPING_DIFFERENT_TABLE = 2, SAME_ID_MAPPING_SAME_TABLE = 3,
  FILTERED_WITH_XA_ACTIVE = 4
}
 

Functions

static int rows_event_stmt_cleanup (Relay_log_info const *rli, THD *thd)
 The function is called at Rows_log_event statement commit time, normally from Rows_log_event::do_update_pos() and possibly from Query_log_event::do_apply_event() of the COMMIT. More...
 
static const char * HA_ERR (int i)
 
static void slave_rows_error_report (enum loglevel level, int ha_error, Relay_log_info const *rli, THD *thd, TABLE *table, const char *type, const char *log_name, ulong pos)
 Error reporting facility for Rows_log_event::do_apply_event. More...
 
static bool set_thd_db (THD *thd, const char *db, size_t db_len)
 Set the rewritten database, or current database if it should not be rewritten, into THD. More...
 
static void clear_all_errors (THD *thd, Relay_log_info *rli)
 
int idempotent_error_code (int err_code)
 
int ignored_error_code (int err_code)
 Ignore error code specified on command line. More...
 
static int convert_handler_error (int error, THD *thd, TABLE *table)
 
bool concurrency_error_code (int error)
 
bool unexpected_error_code (int unexpected_error)
 
static void pretty_print_str (String *packet, const char *str, size_t len)
 
static void pretty_print_str (String *packet, const String *str)
 
static char * slave_load_file_stem (char *buf, uint file_id, int event_server_id, const char *ext)
 Creates a temporary name for load data infile:. More...
 
static void cleanup_load_tmpdir ()
 Delete all temporary files used for SQL_LOAD. More...
 
template<typename T >
bool net_field_length_checked (const uchar **packet, size_t *max_length, T *out)
 Read an integer in net_field_length format, guarding against read out of bounds and advancing the position. More...
 
template bool net_field_length_checked< size_t > (const uchar **packet, size_t *max_length, size_t *out)
 
template bool net_field_length_checked< ulonglong > (const uchar **packet, size_t *max_length, ulonglong *out)
 
char * str_to_hex (char *to, const char *from, size_t len)
 Transforms a string into "" or its expression in 0x... More...
 
int append_query_string (const THD *thd, const CHARSET_INFO *csinfo, String const *from, String *to)
 Append a version of the 'from' string suitable for use in a query to the 'to' string. More...
 
static bool schedule_next_event (Log_event *ev, Relay_log_info *rli)
 
static void write_str_with_code_and_len (uchar **dst, const char *src, size_t len, uint code)
 Utility function for the next method (Query_log_event::write()) . More...
 
bool is_sql_command_atomic_ddl (const LEX *lex)
 Returns true when the lex context determines an atomic DDL. More...
 
static bool is_sql_require_primary_key_needed (const LEX *lex)
 Returns whether or not the statement held by the LEX object parameter requires Q_SQL_REQUIRE_PRIMARY_KEY to be logged together with the statement. More...
 
static bool is_default_table_encryption_needed (const LEX *lex)
 Returns whether or not the statement held by the LEX object parameter requires Q_DEFAULT_TABLE_ENCRYPTION to be logged together with the statement. More...
 
bool is_atomic_ddl (THD *thd, bool using_trans_arg)
 The function lists all DDL instances that are supported for crash-recovery (WL9175). More...
 
static bool is_silent_error (THD *thd)
 
bool slave_execute_deferred_events (THD *thd)
 Exec deferred Int-, Rand- and User- var events prefixing a Query-log-event event. More...
 
static const ucharset_extra_data (uchar *arr)
 set_extra_data More...
 
static void check_extra_row_ndb_info (uchar *extra_row_ndb_info)
 check_extra_row_ndb_info More...
 
int get_rpl_part_id (partition_info *part_info)
 This method is used to extract the partition_id from a partitioned table. More...
 
static bool is_any_column_signaled_for_table (TABLE *table, MY_BITMAP *cols)
 Checks if any of the columns in the given table is signaled in the bitmap. More...
 
static bool are_all_columns_signaled_for_key (KEY *keyinfo, MY_BITMAP *cols)
 Checks if the fields in the given key are signaled in the bitmap. More...
 
static uint search_key_in_table (TABLE *table, MY_BITMAP *bi_cols, uint key_type)
 Searches the table for a given key that can be used according to the existing values, ie, columns set in the bitmap. More...
 
static bool record_compare (TABLE *table, MY_BITMAP *cols)
 
static enum_tbl_map_status check_table_map (Relay_log_info const *rli, RPL_TABLE_LIST *table_list)
 
static void store_compressed_length (String &str_buf, ulonglong length)
 stores an integer into packed format. More...
 
static bool write_tlv_field (String &str_buf, enum Table_map_log_event::Optional_metadata_field_type type, uint length, const uchar *value)
 Write data into str_buf with Type|Length|Value(TLV) format. More...
 
static bool write_tlv_field (String &str_buf, enum Table_map_log_event::Optional_metadata_field_type type, const String &value)
 Write data into str_buf with Type|Length|Value(TLV) format. More...
 
static bool is_character_type (uint type)
 
static bool is_enum_or_set_type (uint type)
 
static bool is_numeric_field (const Field *field)
 
static bool is_character_field (const Field *field)
 
static bool is_enum_field (const Field *field)
 
static bool is_set_field (const Field *field)
 
static bool is_enum_or_set_field (const Field *field)
 
static bool is_geometry_field (const Field *field)
 
static int last_uniq_key (TABLE *table, uint keyno)
 
static bool write_str_at_most_255_bytes (Basic_ostream *ostream, const char *str, uint length)
 
size_t my_strmov_quoted_identifier (THD *thd, char *buffer, const char *identifier, size_t length)
 
size_t my_strmov_quoted_identifier_helper (int q, char *buffer, const char *identifier, size_t length)
 

Variables

Error_log_throttle slave_ignored_err_throttle (window_size, INFORMATION_LEVEL, ER_SERVER_SLAVE_IGNORED_TABLE, "Repl", "Error log throttle: %lu time(s) Error_code: 1237" " \lave SQL thread ignored the query because of" " replicate-*-table rules\got suppressed.")
 
PSI_memory_key key_memory_log_event
 
PSI_memory_key key_memory_Incident_log_event_message
 
PSI_memory_key key_memory_Rows_query_log_event_rows_query
 
const char * binlog_checksum_type_names [] = {"NONE", "CRC32", NullS}
 BINLOG_CHECKSUM variable. More...
 
unsigned int binlog_checksum_type_length []
 
TYPELIB binlog_checksum_typelib
 
static uchar dbug_extra_row_ndb_info_val = 0
 

Macro Definition Documentation

◆ FMT_G_BUFSIZE

#define FMT_G_BUFSIZE (   PREC)    (3 + (PREC) + 5 + 1)

◆ log_cs

#define log_cs   &my_charset_latin1

◆ LOG_SUBSYSTEM_TAG

#define LOG_SUBSYSTEM_TAG   "Repl"

◆ window_size

#define window_size   Log_throttle::LOG_THROTTLE_WINDOW_SIZE

Enumeration Type Documentation

◆ enum_tbl_map_status

Enumerator
OK_TO_PROCESS 
FILTERED_OUT 
SAME_ID_MAPPING_DIFFERENT_TABLE 
SAME_ID_MAPPING_SAME_TABLE 
FILTERED_WITH_XA_ACTIVE 

Function Documentation

◆ are_all_columns_signaled_for_key()

static bool are_all_columns_signaled_for_key ( KEY keyinfo,
MY_BITMAP cols 
)
static

Checks if the fields in the given key are signaled in the bitmap.

Validates whether the before image is usable for the given key. It can be the case that the before image does not contain values for the key (eg, master was using 'minimal' option for image logging and slave has different index structure on the table). Here is an example:

MASTER> SET @binlog_row_image='MINIMAL'; MASTER> CREATE TABLE t1 (a int, b int, c int, primary key(c)); SLAVE> CREATE TABLE t1 (a int, b int, c int, key(a,c)); MASTER> INSERT INTO t1 VALUES (1,2,3); MASTER> UPDATE t1 SET a=2 WHERE b=2;

When finding the row on the slave, one cannot use the index (a,c) to search for the row, because there is only data in the before image for column c. This function checks the fields needed for a given key and searches the bitmap to see if all the fields required are signaled.

Parameters
keyinforeference to key.
colsthe bitmap signaling which columns have available data.
Returns
true if all fields are signaled in the bitmap for the given key, false otherwise.

◆ check_extra_row_ndb_info()

static void check_extra_row_ndb_info ( uchar extra_row_ndb_info)
static

check_extra_row_ndb_info

Called during self-test to check that binlog row event extra data is self- consistent as defined by the set_extra_data function above.

Will assert(false) if not.

Parameters
extra_row_ndb_info

◆ check_table_map()

static enum_tbl_map_status check_table_map ( Relay_log_info const *  rli,
RPL_TABLE_LIST table_list 
)
static

◆ cleanup_load_tmpdir()

static void cleanup_load_tmpdir ( )
static

Delete all temporary files used for SQL_LOAD.

◆ clear_all_errors()

static void clear_all_errors ( THD thd,
Relay_log_info rli 
)
static

◆ concurrency_error_code()

bool concurrency_error_code ( int  error)
inline

◆ convert_handler_error()

static int convert_handler_error ( int  error,
THD thd,
TABLE table 
)
static

◆ HA_ERR()

static const char* HA_ERR ( int  i)
static

◆ idempotent_error_code()

int idempotent_error_code ( int  err_code)
inline

◆ is_any_column_signaled_for_table()

static bool is_any_column_signaled_for_table ( TABLE table,
MY_BITMAP cols 
)
static

Checks if any of the columns in the given table is signaled in the bitmap.

For each column in the given table checks if it is signaled in the bitmap. This is most useful when deciding whether a before image (BI) can be used or not for searching a row. If no column is signaled, then the image cannot be used for searching a record (regardless of using position(), index scan or table scan). Here is an example:

MASTER> SET @binlog_row_image='MINIMAL'; MASTER> CREATE TABLE t1 (a int, b int, c int, primary key(c)); SLAVE> CREATE TABLE t1 (a int, b int); MASTER> INSERT INTO t1 VALUES (1,2,3); MASTER> UPDATE t1 SET a=2 WHERE b=2;

For the update statement only the PK (column c) is logged in the before image (BI). As such, given that the slave has no column c, it will not be able to find the row, because BI has no values for the columns the slave knows about (column a and b).

Parameters
tablethe table reference on the slave.
colsthe bitmap signaling columns available in the BI.
Returns
true if BI contains usable colums for searching, false otherwise.

◆ is_character_field()

static bool is_character_field ( const Field field)
inlinestatic

◆ is_character_type()

static bool is_character_type ( uint  type)
inlinestatic

◆ is_default_table_encryption_needed()

static bool is_default_table_encryption_needed ( const LEX lex)
static

Returns whether or not the statement held by the LEX object parameter requires Q_DEFAULT_TABLE_ENCRYPTION to be logged together with the statement.

◆ is_enum_field()

static bool is_enum_field ( const Field field)
inlinestatic

◆ is_enum_or_set_field()

static bool is_enum_or_set_field ( const Field field)
inlinestatic

◆ is_enum_or_set_type()

static bool is_enum_or_set_type ( uint  type)
inlinestatic

◆ is_geometry_field()

static bool is_geometry_field ( const Field field)
inlinestatic

◆ is_numeric_field()

static bool is_numeric_field ( const Field field)
inlinestatic

◆ is_set_field()

static bool is_set_field ( const Field field)
inlinestatic

◆ is_silent_error()

static bool is_silent_error ( THD thd)
static

◆ is_sql_command_atomic_ddl()

bool is_sql_command_atomic_ddl ( const LEX lex)
inline

Returns true when the lex context determines an atomic DDL.

The result is optimistic as there can be more properties to check out.

Parameters
lexpointer to LEX object of being executed statement

◆ is_sql_require_primary_key_needed()

static bool is_sql_require_primary_key_needed ( const LEX lex)
static

Returns whether or not the statement held by the LEX object parameter requires Q_SQL_REQUIRE_PRIMARY_KEY to be logged together with the statement.

◆ last_uniq_key()

static int last_uniq_key ( TABLE table,
uint  keyno 
)
static

◆ net_field_length_checked< size_t >()

template bool net_field_length_checked< size_t > ( const uchar **  packet,
size_t *  max_length,
size_t *  out 
)

◆ net_field_length_checked< ulonglong >()

template bool net_field_length_checked< ulonglong > ( const uchar **  packet,
size_t *  max_length,
ulonglong out 
)

◆ pretty_print_str() [1/2]

static void pretty_print_str ( String packet,
const char *  str,
size_t  len 
)
static

◆ pretty_print_str() [2/2]

static void pretty_print_str ( String packet,
const String str 
)
inlinestatic

◆ record_compare()

static bool record_compare ( TABLE table,
MY_BITMAP cols 
)
static

Compare full record only if:

  • there are no blob fields (otherwise we would also need to compare blobs contents as well);
  • there are no varchar fields (otherwise we would also need to compare varchar contents as well);
  • there are no null fields, otherwise NULLed fields contents (i.e., the don't care bytes) may show arbitrary values, depending on how each engine handles internally.
  • if all the bitmap is set (both are full rows)

◆ rows_event_stmt_cleanup()

static int rows_event_stmt_cleanup ( Relay_log_info const *  rli,
THD thd 
)
static

The function is called at Rows_log_event statement commit time, normally from Rows_log_event::do_update_pos() and possibly from Query_log_event::do_apply_event() of the COMMIT.

The function commits the last statement for engines, binlog and releases resources have been allocated for the statement.

Return values
0Ok.
non-zeroError at the commit.

◆ schedule_next_event()

static bool schedule_next_event ( Log_event ev,
Relay_log_info rli 
)
static

◆ search_key_in_table()

static uint search_key_in_table ( TABLE table,
MY_BITMAP bi_cols,
uint  key_type 
)
static

Searches the table for a given key that can be used according to the existing values, ie, columns set in the bitmap.

The caller can specify which type of key to find by setting the following flags in the key_type parameter:

  • PRI_KEY_FLAG Returns the primary key.
  • UNIQUE_KEY_FLAG Returns a unique key (flagged with HA_NOSAME)
  • MULTIPLE_KEY_FLAG Returns a key that is not unique (flagged with HA_NOSAME and without HA_NULL_PART_KEY) nor PK.

The above flags can be used together, in which case, the search is conducted in the above listed order. Eg, the following flag:

(PRI_KEY_FLAG | UNIQUE_KEY_FLAG | MULTIPLE_KEY_FLAG)

means that a primary key is returned if it is suitable. If not then the unique keys are searched. If no unique key is suitable, then the keys are searched. Finally, if no key is suitable, MAX_KEY is returned.

Parameters
tablereference to the table.
bi_colsa bitmap that filters out columns that should not be considered while searching the key. Columns that should be considered are set.
key_typethe type of key to search for.
Returns
MAX_KEY if no key, according to the key_type specified is suitable. Returns the key otherwise.

◆ set_extra_data()

static const uchar* set_extra_data ( uchar arr)
static

set_extra_data

Called during self-test to generate various self-consistent binlog row event extra thread data structures which can be checked when reading the binlog.

Parameters
arrBuffer to use

◆ set_thd_db()

static bool set_thd_db ( THD thd,
const char *  db,
size_t  db_len 
)
static

Set the rewritten database, or current database if it should not be rewritten, into THD.

Parameters
thdTHD handle
dbdatabase name
db_lenthe length of database name
Return values
trueif the passed db is rewritten.
falseif the passed db is not rewritten.

◆ slave_load_file_stem()

static char* slave_load_file_stem ( char *  buf,
uint  file_id,
int  event_server_id,
const char *  ext 
)
static

Creates a temporary name for load data infile:.

Parameters
bufStore new filename here
file_idFile_id (part of file name)
event_server_idEvent_id (part of file name)
extExtension for file name
Returns
Pointer to start of extension

◆ slave_rows_error_report()

static void slave_rows_error_report ( enum loglevel  level,
int  ha_error,
Relay_log_info const *  rli,
THD thd,
TABLE table,
const char *  type,
const char *  log_name,
ulong  pos 
)
inlinestatic

Error reporting facility for Rows_log_event::do_apply_event.

Parameters
levelerror, warning or info
ha_errorHA_ERR_ code
rlipointer to the active Relay_log_info instance
thdpointer to the slave thread's thd
tablepointer to the event's table object
typethe type of the event
log_namethe master binlog file name
posthe master binlog file pos (the next after the event)

◆ store_compressed_length()

static void store_compressed_length ( String str_buf,
ulonglong  length 
)
inlinestatic

stores an integer into packed format.

Parameters
[out]str_bufa buffer where the packed integer will be stored.
[in]lengththe integer will be packed.

◆ unexpected_error_code()

bool unexpected_error_code ( int  unexpected_error)
inline

◆ write_str_at_most_255_bytes()

static bool write_str_at_most_255_bytes ( Basic_ostream ostream,
const char *  str,
uint  length 
)
static

◆ write_str_with_code_and_len()

static void write_str_with_code_and_len ( uchar **  dst,
const char *  src,
size_t  len,
uint  code 
)
static

Utility function for the next method (Query_log_event::write()) .

◆ write_tlv_field() [1/2]

static bool write_tlv_field ( String str_buf,
enum Table_map_log_event::Optional_metadata_field_type  type,
uint  length,
const uchar value 
)
inlinestatic

Write data into str_buf with Type|Length|Value(TLV) format.

Parameters
[out]str_bufa buffer where the field is stored.
[in]typetype of the field
[in]lengthlength of the field value
[in]valuevalue of the field

◆ write_tlv_field() [2/2]

static bool write_tlv_field ( String str_buf,
enum Table_map_log_event::Optional_metadata_field_type  type,
const String value 
)
inlinestatic

Write data into str_buf with Type|Length|Value(TLV) format.

Parameters
[out]str_bufa buffer where the field is stored.
[in]typetype of the field
[in]valuevalue of the field

Variable Documentation

◆ binlog_checksum_type_length

unsigned int binlog_checksum_type_length[]
Initial value:
= {sizeof("NONE") - 1,
sizeof("CRC32") - 1, 0}

◆ binlog_checksum_type_names

const char* binlog_checksum_type_names[] = {"NONE", "CRC32", NullS}

BINLOG_CHECKSUM variable.

◆ dbug_extra_row_ndb_info_val

uchar dbug_extra_row_ndb_info_val = 0
static

◆ key_memory_log_event

PSI_memory_key key_memory_log_event

◆ slave_ignored_err_throttle

Error_log_throttle slave_ignored_err_throttle(window_size, INFORMATION_LEVEL, ER_SERVER_SLAVE_IGNORED_TABLE, "Repl", "Error log throttle: %lu time(s) Error_code: 1237" " \Slave SQL thread ignored the query because of" " replicate-*-table rules\ got suppressed.")