MySQL 8.4.3
Source Code Documentation
|
#include "sql/log_event.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include "my_config.h"
#include <sys/time.h>
#include <algorithm>
#include <iterator>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include "base64.h"
#include "decimal.h"
#include "m_string.h"
#include "my_bitmap.h"
#include "my_byteorder.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_io.h"
#include "my_macros.h"
#include "my_systime.h"
#include "my_table_map.h"
#include "my_time.h"
#include "mysql.h"
#include "mysql/binlog/event/debug_vars.h"
#include "mysql/binlog/event/export/binary_log_funcs.h"
#include "mysql/binlog/event/table_id.h"
#include "mysql/binlog/event/wrapper_functions.h"
#include "mysql/components/services/bits/psi_statement_bits.h"
#include "mysql/components/services/log_builtins.h"
#include "mysql/components/services/log_shared.h"
#include "mysql/my_loglevel.h"
#include "mysql/psi/mysql_mutex.h"
#include "mysql/serialization/serializer_default.h"
#include "mysql/serialization/write_archive_binary.h"
#include "mysql/strings/dtoa.h"
#include "mysql/strings/int2str.h"
#include "mysql/strings/m_ctype.h"
#include "mysql/udf_registration_types.h"
#include "mysql_time.h"
#include "nulls.h"
#include "psi_memory_key.h"
#include "query_options.h"
#include "scope_guard.h"
#include "sql-common/my_decimal.h"
#include "sql/auth/auth_acls.h"
#include "sql/binlog_reader.h"
#include "sql/field_common_properties.h"
#include "sql/psi_memory_resource.h"
#include "sql/raii/thread_stage_guard.h"
#include "sql/rpl_handler.h"
#include "sql/rpl_tblmap.h"
#include "sql/sql_show_processlist.h"
#include "sql/system_variables.h"
#include "sql/tc_log.h"
#include "sql/xa/sql_cmd_xa.h"
#include "sql_const.h"
#include "sql_string.h"
#include "strmake.h"
#include "strxmov.h"
#include "template_utils.h"
#include <errno.h>
#include <fcntl.h>
#include <cstdint>
#include <new>
#include "my_base.h"
#include "my_command.h"
#include "my_dir.h"
#include "my_sqlcommand.h"
#include "mysql/binlog/event/binary_log.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/changestreams/misc/replicated_columns_view_factory.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_mta_submode.h"
#include "sql/rpl_replica.h"
#include "sql/rpl_reporting.h"
#include "sql/rpl_rli.h"
#include "sql/rpl_rli_pdb.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_gipk.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 "string_with_len.h"
#include "thr_lock.h"
#include "mysql/binlog/event/codecs/binary.h"
#include "mysql/binlog/event/codecs/factory.h"
#include "mysql/binlog/event/compression/payload_event_buffer_istream.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 | ILLEGAL_CHARSET_INFO_NUMBER (~0U) |
#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... form. 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 bool | is_load_data_file_allowed (THD *thd, Relay_log_info const *rli) |
This function is used inside Append_block_log_event and Execute_load_query_log_event apply member functions to determine if a file is to be created (Append_block_log_event) or has been created (Execute_load_query_log_event). More... | |
static const uchar * | set_extra_data (uchar *arr, int reset_limit) |
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_ref *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) |
static bool | shall_delete_event_after_apply (Log_event *ev) |
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) |
std::pair< bool, mysql::binlog::event::Log_event_basic_info > | extract_log_event_basic_info (Log_event *log_event) |
Extract basic info about an event: type, query, is it ignorable. More... | |
std::pair< bool, mysql::binlog::event::Log_event_basic_info > | extract_log_event_basic_info (const char *buf, size_t length, const mysql::binlog::event::Format_description_event *fd_event) |
Extract basic info about an event: type, query, is it ignorable. More... | |
Variables | |
Error_log_throttle | slave_ignored_err_throttle (window_size, INFORMATION_LEVEL, ER_SERVER_REPLICA_IGNORED_TABLE, "Repl", "Error log throttle: %lu time(s) Error_code: 1237" " \"Replica 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 |
static int | dbug_extra_row_ndb_info_val_limit = 0 |
#define FMT_G_BUFSIZE | ( | PREC | ) | (3 + (PREC) + 5 + 1) |
#define ILLEGAL_CHARSET_INFO_NUMBER (~0U) |
#define log_cs &my_charset_latin1 |
#define LOG_SUBSYSTEM_TAG "Repl" |
#define window_size Log_throttle::LOG_THROTTLE_WINDOW_SIZE |
enum enum_tbl_map_status |
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.
keyinfo | reference to key. |
cols | the bitmap signaling which columns have available data. |
|
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.
|
static |
|
static |
Delete all temporary files used for SQL_LOAD.
|
static |
|
inline |
|
static |
|
inline |
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).
table | the table reference on the slave. |
cols | the bitmap signaling columns available in the BI. |
|
inlinestatic |
|
inlinestatic |
|
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.
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
static |
This function is used inside Append_block_log_event and Execute_load_query_log_event apply member functions to determine if a file is to be created (Append_block_log_event) or has been created (Execute_load_query_log_event).
thd | The applier thread context. |
rli | The applier relay log info global context. |
|
inlinestatic |
|
inlinestatic |
|
static |
|
inline |
Returns true when the lex context determines an atomic DDL.
The result is optimistic as there can be more properties to check out.
CREATE TABLE ... START TRANSACTION is not treated as atomic here, because the table is not really committed at the end of CREATE TABLE processing. It gets committed by a explicit call to COMMIT after INSERTing rows into the table.
lex | pointer to LEX object of being executed statement |
|
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.
|
static |
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 | ||
) |
|
static |
Compare full record only if:
|
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.
0 | Ok. |
non-zero | Error at the commit. |
|
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:
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.
table | reference to the table. |
bi_cols | a bitmap that filters out columns that should not be considered while searching the key. Columns that should be considered are set. |
key_type | the type of key to search for. |
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.
arr | Buffer to use |
reset_limit | the limit upon which the counters reset |
|
static |
Set the rewritten database, or current database if it should not be rewritten, into THD.
thd | THD handle |
db | database name |
db_len | the length of database name |
true | if the passed db is rewritten. |
false | if the passed db is not rewritten. |
|
static |
|
static |
Creates a temporary name for load data infile:.
buf | Store new filename here |
file_id | File_id (part of file name) |
event_server_id | Event_id (part of file name) |
ext | Extension for file name |
|
inlinestatic |
Error reporting facility for Rows_log_event::do_apply_event.
level | error, warning or info |
ha_error | HA_ERR_ code |
rli | pointer to the active Relay_log_info instance |
thd | pointer to the slave thread's thd |
table | pointer to the event's table object |
type | the type of the event |
log_name | the master binlog file name |
pos | the master binlog file pos (the next after the event) |
stores an integer into packed format.
[out] | str_buf | a buffer where the packed integer will be stored. |
[in] | length | the integer will be packed. |
|
inline |
|
static |
|
static |
Utility function for the next method (Query_log_event::write()) .
|
inlinestatic |
Write data into str_buf with Type|Length|Value(TLV) format.
[out] | str_buf | a buffer where the field is stored. |
[in] | type | type of the field |
[in] | value | value of the field |
|
inlinestatic |
Write data into str_buf with Type|Length|Value(TLV) format.
[out] | str_buf | a buffer where the field is stored. |
[in] | type | type of the field |
[in] | length | length of the field value |
[in] | value | value of the field |
unsigned int binlog_checksum_type_length[] |
const char* binlog_checksum_type_names[] = {"NONE", "CRC32", NullS} |
BINLOG_CHECKSUM variable.
|
static |
|
static |
PSI_memory_key key_memory_log_event |
Error_log_throttle slave_ignored_err_throttle(window_size, INFORMATION_LEVEL, ER_SERVER_REPLICA_IGNORED_TABLE, "Repl", "Error log throttle: %lu time(s) Error_code: 1237" " \"Replica SQL thread ignored the query because of" " replicate-*-table rules\" got suppressed.") | ( | window_size | , |
INFORMATION_LEVEL | , | ||
ER_SERVER_REPLICA_IGNORED_TABLE | , | ||
"Repl" | , | ||
"Error log throttle: %lu time(s) Error_code: 1237" " \"Replica SQL thread ignored the query because of" " replicate-*-table rules\" got suppressed." | |||
) |