MySQL  8.0.17
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 "lex_string.h"
#include "map_helpers.h"
#include "my_alloc.h"
#include "my_loglevel.h"
#include "my_macros.h"
#include "my_systime.h"
#include "my_thread.h"
#include "sql/check_stack.h"
#include "sql/clone_handler.h"
#include "sql_string.h"
#include "template_utils.h"
#include <algorithm>
#include <list>
#include <map>
#include <new>
#include <string>
#include "control_events.h"
#include "debug_vars.h"
#include "dur_prop.h"
#include "m_ctype.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/components/services/log_builtins.h"
#include "mysql/plugin.h"
#include "mysql/psi/mysql_file.h"
#include "mysql/service_mysql_alloc.h"
#include "mysql/thread_type.h"
#include "mysqld_error.h"
#include "partition_info.h"
#include "prealloced_array.h"
#include "rows_event.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/query_options.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_rli.h"
#include "sql/rpl_rli_pdb.h"
#include "sql/rpl_slave.h"
#include "sql/rpl_slave_commit_order_manager.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_partition.h"
#include "statement_events.h"
#include "table_id.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  Adjust_offset
 Adjust log offset in the binary log file for all running slaves This class implements call back function for do_for_all_thd(). More...
 
class  Log_in_use
 This class implements Call back function for do_for_all_thd(). More...
 

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
}
 Reads GTIDs from the given binlog file. More...
 

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 *, 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 xa_status_code binlog_xa_commit (handlerton *hton, XID *xid)
 
static xa_status_code binlog_xa_rollback (handlerton *hton, XID *xid)
 
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 int binlog_recover (Binlog_file_reader *binlog_file_reader, my_off_t *valid_pos)
 MYSQLD server recovers from last crashed binlog. More...
 
static void binlog_prepare_row_images (const THD *thd, TABLE *table)
 
static bool has_commit_order_manager (THD *thd)
 
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 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)
 
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...
 
int do_binlog_xa_commit_rollback (THD *thd, XID *xid, bool commit)
 Logging XA commit/rollback of a prepared transaction. More...
 
xa_status_code binlog_xa_commit_or_rollback (THD *thd, XID *xid, bool commit)
 Logging XA commit/rollback of a prepared transaction in the case it was disconnected and resumed (recovered), or executed by a slave applier. More...
 
static uint purge_log_get_error_code (int res)
 purge logs, master and slave sides both, related error code convertor. More...
 
static void adjust_linfo_offsets (my_off_t purge_offset)
 
static int log_in_use (const char *log_name)
 
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 *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_master_logs (THD *thd, const char *to_log)
 Execute a PURGE BINARY LOGS TO <log> command. More...
 
bool purge_master_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)
 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 fuction instantianates 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, 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, Sid_map *sid_map, bool verify_checksum, bool is_relay_log)
 
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...
 
void register_binlog_handler (THD *thd, bool trx)
 
static bool has_write_table_with_auto_increment (TABLE_LIST *tables)
 
static bool has_write_table_with_auto_increment_and_select (TABLE_LIST *tables)
 
static bool has_write_table_auto_increment_not_first_in_pk (TABLE_LIST *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_LIST *tables)
 Checks if a TABLE_LIST contains a table that has been opened for writing, and that has a column with a non-deterministic DEFAULT expression. 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