MySQL 8.4.3
Source Code Documentation
binlog.cc File Reference
#include "sql/binlog.h"
#include "my_config.h"
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "m_string.h"
#include "map_helpers.h"
#include "my_alloc.h"
#include "my_macros.h"
#include "my_systime.h"
#include "my_thread.h"
#include "mysql/my_loglevel.h"
#include "mysql/strings/int2str.h"
#include "nulls.h"
#include "sql/check_stack.h"
#include "sql/clone_handler.h"
#include "sql/raii/thread_stage_guard.h"
#include "sql_string.h"
#include "strmake.h"
#include "template_utils.h"
#include <unistd.h>
#include <algorithm>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <queue>
#include <sstream>
#include <string>
#include "dur_prop.h"
#include "include/mysqld_errmsg.h"
#include "mf_wcomp.h"
#include "mutex_lock.h"
#include "my_base.h"
#include "my_bitmap.h"
#include "my_byteorder.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_dir.h"
#include "my_sqlcommand.h"
#include "my_stacktrace.h"
#include "my_thread_local.h"
#include "mysql/binlog/event/compression/buffer/grow_calculator.h"
#include "mysql/binlog/event/compression/compressor.h"
#include "mysql/binlog/event/compression/payload_event_buffer_istream.h"
#include "mysql/binlog/event/compression/zstd_comp.h"
#include "mysql/binlog/event/control_events.h"
#include "mysql/binlog/event/debug_vars.h"
#include "mysql/binlog/event/rows_event.h"
#include "mysql/binlog/event/statement_events.h"
#include "mysql/binlog/event/table_id.h"
#include "mysql/components/services/log_builtins.h"
#include "mysql/plugin.h"
#include "mysql/psi/mysql_file.h"
#include "mysql/service_mysql_alloc.h"
#include "mysql/strings/m_ctype.h"
#include "mysql/thread_type.h"
#include "mysqld_error.h"
#include "partition_info.h"
#include "prealloced_array.h"
#include "scope_guard.h"
#include "sql/binlog/decompressing_event_object_istream.h"
#include "sql/binlog/global.h"
#include "sql/binlog/group_commit/bgc_ticket_manager.h"
#include "sql/binlog/recovery.h"
#include "sql/binlog/services/iterator/file_storage.h"
#include "sql/binlog_ostream.h"
#include "sql/binlog_reader.h"
#include "sql/create_field.h"
#include "sql/current_thd.h"
#include "sql/debug_sync.h"
#include "sql/derror.h"
#include "sql/discrete_interval.h"
#include "sql/field.h"
#include "sql/handler.h"
#include "sql/item_func.h"
#include "sql/key.h"
#include "sql/log.h"
#include "sql/log_event.h"
#include "sql/mysqld.h"
#include "sql/mysqld_thd_manager.h"
#include "sql/protocol.h"
#include "sql/psi_memory_key.h"
#include "sql/psi_memory_resource.h"
#include "sql/query_options.h"
#include "sql/raii/sentry.h"
#include "sql/rpl_filter.h"
#include "sql/rpl_gtid.h"
#include "sql/rpl_handler.h"
#include "sql/rpl_mi.h"
#include "sql/rpl_record.h"
#include "sql/rpl_replica.h"
#include "sql/rpl_replica_commit_order_manager.h"
#include "sql/rpl_rli.h"
#include "sql/rpl_rli_pdb.h"
#include "sql/rpl_transaction_ctx.h"
#include "sql/rpl_trx_boundary_parser.h"
#include "sql/rpl_utility.h"
#include "sql/sql_backup_lock.h"
#include "sql/sql_base.h"
#include "sql/sql_bitmap.h"
#include "sql/sql_class.h"
#include "sql/sql_const.h"
#include "sql/sql_data_change.h"
#include "sql/sql_error.h"
#include "sql/sql_lex.h"
#include "sql/sql_list.h"
#include "sql/sql_parse.h"
#include "sql/sql_show.h"
#include "sql/system_variables.h"
#include "sql/table.h"
#include "sql/transaction_info.h"
#include "sql/xa.h"
#include "sql/xa/sql_cmd_xa.h"
#include "sql_partition.h"
#include "string_with_len.h"
#include "thr_lock.h"

Classes

class  MYSQL_BIN_LOG::Binlog_ofile
 Logical binlog file which wraps and hides the detail of lower layer storage implementation. More...
 
class  Thd_backup_and_restore
 Helper class to switch to a new thread and then go back to the previous one, when the object is destroyed using RAII. More...
 
class  binlog_cache_data
 Caches for non-transactional and transactional data before writing it to the binary log. More...
 
struct  binlog_cache_data::cache_state
 
struct  binlog_cache_data::Flags
 
class  binlog_stmt_cache_data
 
class  binlog_trx_cache_data
 
class  binlog_cache_mngr
 
class  Binlog_event_writer
 Auxiliary class to copy serialized events to the binary log and correct some of the fields that are not known until just before writing the event. More...
 
class  Binlog_cache_compressor
 Controls the execution flow when we compress the transaction cache into memory and write back the compressed data to the transaction cache. More...
 
class  anonymous_namespace{binlog.cc}::Row_data_memory
 Class to handle temporary allocation of memory for row data. More...
 

Namespaces

namespace  anonymous_namespace{binlog.cc}
 

Macros

#define FLAGSTR(V, F)   ((V) & (F) ? #F " " : "")
 
#define YESNO(X)   ((X) ? "yes" : "no")
 
#define MY_OFF_T_UNDEF   (~(my_off_t)0UL)
 
#define LIMIT_UNSAFE_WARNING_ACTIVATION_TIMEOUT   50
 
#define LIMIT_UNSAFE_WARNING_ACTIVATION_THRESHOLD_COUNT   50
 

Enumerations

enum  enum_read_gtids_from_binlog_status {
  GOT_GTIDS , GOT_PREVIOUS_GTIDS , NO_GTIDS , ERROR ,
  TRUNCATED
}
 

Functions

static int binlog_init (void *p)
 
static int binlog_start_trans_and_stmt (THD *thd, Log_event *start_event)
 Function to start a statement and optionally a transaction for the binary log. More...
 
static int binlog_close_connection (handlerton *hton, THD *thd)
 
static int binlog_savepoint_set (handlerton *hton, THD *thd, void *sv)
 
static int binlog_savepoint_rollback (handlerton *hton, THD *thd, void *sv)
 
static bool binlog_savepoint_rollback_can_release_mdl (handlerton *, THD *thd)
 Check whether binlog state allows to safely release MDL locks after rollback to savepoint. More...
 
static int binlog_commit (handlerton *, THD *, bool)
 This function is called once after each statement. More...
 
static int binlog_rollback (handlerton *, THD *thd, bool all)
 This function is called when a transaction or a statement is rolled back. More...
 
static int binlog_prepare (handlerton *hton, THD *thd, bool all)
 
static int binlog_set_prepared_in_tc (handlerton *hton, THD *thd)
 
static void exec_binlog_error_action_abort (const char *err_string)
 When a fatal error occurs due to which binary logging becomes impossible and the user specified binlog_error_action= ABORT_SERVER the following function is invoked. More...
 
static void binlog_prepare_row_images (const THD *thd, TABLE *table)
 
static bool is_loggable_xa_prepare (THD *thd)
 Predicate function yields true when XA transaction is being logged having a proper state ready for prepare or commit in one phase. More...
 
void anonymous_namespace{binlog.cc}::finish_transaction_in_engines (THD *thd, bool all, bool run_after_commit)
 Finishes the transaction in the engines. More...
 
bool normalize_binlog_name (char *to, const char *from, bool is_relay_log)
 Turns a relative log binary log path into a full path, based on the opt_bin_logname or opt_relay_logname. More...
 
static std::pair< bool, int > check_purge_conditions (const MYSQL_BIN_LOG &log)
 Checks whether purge conditions are met to be able to run purge for binary log files. More...
 
static time_t calculate_auto_purge_lower_time_bound ()
 This function abstracts the calculation of the binary log files retention lower bound. More...
 
static bool check_auto_purge_conditions ()
 Checks if automatic purge conditions are met and therefore the purge is allowed to be done. More...
 
static binlog_cache_mngrthd_get_cache_mngr (const THD *thd)
 
void check_binlog_cache_size (THD *thd)
 Checks if the BINLOG_CACHE_SIZE's value is greater than MAX_BINLOG_CACHE_SIZE. More...
 
void check_binlog_stmt_cache_size (THD *thd)
 Checks if the BINLOG_STMT_CACHE_SIZE's value is greater than MAX_BINLOG_STMT_CACHE_SIZE. More...
 
bool binlog_enabled ()
 Check whether binlog_hton has valid slot and enabled. More...
 
static void binlog_trans_log_savepos (THD *thd, my_off_t *pos)
 
static int binlog_dummy_recover (handlerton *, XA_recover_txn *, uint, MEM_ROOT *)
 
static int binlog_deinit (void *)
 
enum xa_option_words get_xa_opt (THD *thd)
 
static uint purge_log_get_error_code (int res)
 purge logs, master and slave sides both, related error code converter. More...
 
static bool purge_error_message (THD *thd, int res)
 
bool is_transaction_empty (THD *thd)
 Check if the the transaction is empty. More...
 
int check_trx_rw_engines (THD *thd, Transaction_ctx::enum_trx_scope trx_scope)
 Check if the transaction has no rw flag set for any of the storage engines. More...
 
bool is_empty_transaction_in_binlog_cache (const THD *thd)
 Check if at least one of transacaction and statement binlog caches contains an empty transaction, other one is empty or contains an empty transaction, which has two binlog events "BEGIN" and "COMMIT". More...
 
bool trans_has_updated_trans_table (const THD *thd)
 This function checks if a transactional table was updated by the current transaction. More...
 
bool stmt_has_updated_trans_table (Ha_trx_info_list const &ha_list)
 This function checks if a transactional table was updated by the current statement. More...
 
bool ending_trans (THD *thd, const bool all)
 This function checks if a transaction, either a multi-statement or a single statement transaction is about to commit or not. More...
 
bool ending_single_stmt_trans (THD *thd, const bool all)
 This function checks if a single statement transaction is about to commit or not. More...
 
bool trans_cannot_safely_rollback (const THD *thd)
 This function checks if a transaction cannot be rolled back safely. More...
 
bool stmt_cannot_safely_rollback (const THD *thd)
 This function checks if current statement cannot be rollded back safely. More...
 
bool purge_source_logs_to_file (THD *thd, const char *to_log)
 Execute a PURGE BINARY LOGS TO <log> command. More...
 
bool purge_source_logs_before_date (THD *thd, time_t purge_time)
 Execute a PURGE BINARY LOGS BEFORE <date> command. More...
 
int query_error_code (const THD *thd, bool not_killed)
 
static bool copy_file (IO_CACHE *from, IO_CACHE *to, my_off_t offset, my_off_t end_pos=0)
 Copy content of 'from' file from offset to 'to' file. More...
 
int log_loaded_block (IO_CACHE *file)
 Load data's io cache specific hook to be executed before a chunk of data is being read into the cache's buffer The function instantiates and writes into the binlog replication events along LOAD DATA processing. More...
 
template<class BINLOG_FILE_READER >
bool show_binlog_events (THD *thd, MYSQL_BIN_LOG *binary_log)
 
bool mysql_show_binlog_events (THD *thd)
 Execute a SHOW BINLOG EVENTS statement. More...
 
static bool is_number (const char *str, ulong *res, bool allow_wildcards)
 Check if a string is a valid number. More...
 
static int find_uniq_filename (char *name, uint32 new_index_number)
 Find a unique filename for 'filename. More...
 
static bool read_gtids_and_update_trx_parser_from_relaylog (const char *filename, Gtid_set *retrieved_gtids, bool verify_checksum, mysql::binlog::event::Transaction_boundary_parser *trx_parser, Gtid_monitoring_info *partial_trx)
 Add the GTIDs from the given relaylog file and also update the IO thread transaction parser. More...
 
static enum_read_gtids_from_binlog_status read_gtids_from_binlog (const char *filename, Gtid_set *all_gtids, Gtid_set *prev_gtids, Gtid *first_gtid, Tsid_map *tsid_map, bool verify_checksum, bool is_relay_log)
 Reads GTIDs from the given binlog file. More...
 
static int compare_log_name (const char *log_1, const char *log_2)
 
static int call_after_sync_hook (THD *queue_head)
 Auxiliary function used in ordered_commit. More...
 
static void register_binlog_handler (THD *thd, bool trx)
 
static bool has_write_table_with_auto_increment (Table_ref *tables)
 
static bool has_write_table_with_auto_increment_and_query_block (Table_ref *tables)
 
static bool has_write_table_auto_increment_not_first_in_pk (Table_ref *tables)
 
static bool has_nondeterministic_default (const TABLE *table)
 Checks if a table has a column with a non-deterministic DEFAULT expression. More...
 
static bool has_write_table_with_nondeterministic_default (const Table_ref *tables)
 Checks if a Table_ref contains a table that has been opened for writing, and that has a column with a non-deterministic DEFAULT expression. More...
 
static bool has_acl_table_read (THD *thd, const Table_ref *tl_list)
 Checks if we have reads from ACL tables in table list. More...
 
static bool fulltext_unsafe_set (TABLE_SHARE *s)
 
const char * get_locked_tables_mode_name (enum_locked_tables_mode locked_tables_mode)
 Getter for the enum enum_locked_tables_mode. More...
 
static bool handle_gtid_consistency_violation (THD *thd, int error_code, int log_error_code)
 Given that a possible violation of gtid consistency has happened, checks if gtid-inconsistencies are forbidden by the current value of ENFORCE_GTID_CONSISTENCY and GTID_MODE. More...
 
static const char * show_query_type (THD::enum_binlog_query_type qtype)
 
static void reset_binlog_unsafe_suppression ()
 Auxiliary function to reset the limit unsafety warning suppression. More...
 
static void print_unsafe_warning_to_log (int unsafe_type, char *buf, const char *query)
 Auxiliary function to print warning in the error log. More...
 
static void do_unsafe_limit_checkout (char *buf, int unsafe_type, const char *query)
 Auxiliary function to check if the warning for limit unsafety should be thrown or suppressed. More...
 
 mysql_declare_plugin (binlog)
 

Variables

static ulonglong limit_unsafe_suppression_start_time = 0
 
static bool unsafe_warning_suppression_is_activated = false
 
static int limit_unsafe_warning_count = 0
 
static handlertonbinlog_hton
 
bool opt_binlog_order_commits = true
 
const char * log_bin_index = nullptr
 
const char * log_bin_basename = nullptr
 
ulong rpl_read_size
 
MYSQL_BIN_LOG mysql_bin_logsync_binlog_period
 
static const char * g_stage_name []
 Names for the stages. More...
 
struct st_mysql_storage_engine binlog_storage_engine
 
 mysql_declare_plugin_end
 

Macro Definition Documentation

◆ FLAGSTR

#define FLAGSTR (   V,
 
)    ((V) & (F) ? #F " " : "")

◆ YESNO

#define YESNO (   X)    ((X) ? "yes" : "no")

Function Documentation

◆ mysql_declare_plugin()

mysql_declare_plugin ( binlog  )

Variable Documentation

◆ mysql_declare_plugin_end

mysql_declare_plugin_end