mysql5.7 dml 語句記錄binlog 與redo日誌
阿新 • • 發佈:2021-02-20
技術標籤:mysql 原始碼筆記mysql
//寫redo日誌,和 生成binlog的程式碼
int handler::ha_write_row(uchar *buf)
{
int error;
Log_func *log_func= Write_rows_log_event::binlog_row_logging_function;
DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
m_lock_type == F_WRLCK);
DBUG_ENTER("handler::ha_write_row" );
DBUG_EXECUTE_IF("inject_error_ha_write_row",
DBUG_RETURN(HA_ERR_INTERNAL_ERROR); );
DBUG_EXECUTE_IF("simulate_storage_engine_out_of_memory",
DBUG_RETURN(HA_ERR_SE_OUT_OF_MEMORY); );
MYSQL_INSERT_ROW_START(table_share->db.str, table_share-> table_name.str);
mark_trx_read_write();
DBUG_EXECUTE_IF("handler_crashed_table_on_usage",
my_error(HA_ERR_CRASHED, MYF(ME_ERRORLOG), table_share->table_name.str);
set_my_errno(HA_ERR_CRASHED);
DBUG_RETURN(HA_ERR_CRASHED););
/*寫redo程式碼*/
MYSQL_TABLE_IO_WAIT(PSI_TABLE_WRITE_ROW, MAX_KEY, error,
{ error= write_row(buf); })
MYSQL_INSERT_ROW_DONE(error);
if (unlikely(error))
DBUG_RETURN(error);
/*寫binlog程式碼 生成binlog的程式碼*/
if (unlikely((error= binlog_log_row(table, 0, buf, log_func))))
DBUG_RETURN(error); /* purecov: inspected */
DEBUG_SYNC_C("ha_write_row_end");
DBUG_RETURN(0);
}
/*寫binlog 去掉巨集的程式碼*/
{ if (m_psi != __null) {
switch (m_psi_batch_mode) {
case PSI_BATCH_MODE_NONE: {
PSI_table_locker *sub_locker= __null;
PSI_table_locker_state reentrant_safe_state;
sub_locker= pfs_start_table_io_wait_v1 (& reentrant_safe_state, m_psi, PSI_TABLE_WRITE_ROW, 64U );
{ error= write_row(buf); }
if (sub_locker !=__null)
pfs_end_table_io_wait_v1 (sub_locker, 1);
break;
}
case PSI_BATCH_MODE_STARTING: {
m_psi_locker= pfs_start_table_io_wait_v1 (& m_psi_locker_state, m_psi, PSI_TABLE_WRITE_ROW, 64U);
{ error= write_row(buf); }
if (!error) m_psi_numrows++;
m_psi_batch_mode= PSI_BATCH_MODE_STARTED; break;
}
case PSI_BATCH_MODE_STARTED:
default:
{ do { } while(0); { error= write_row(buf); }
if (!error) m_psi_numrows++; break; }
}
} else {
{ error= write_row(buf); }
}
}
//把內部形成的binlog 新增到thd
#0 MYSQL_BIN_LOG::flush_and_set_pending_rows_event (this=0x2d9af00 <mysql_bin_log>, thd=0x7ffe80000b70, event=0x0, is_transactional=true) at sql/binlog.cc:7379
#1 0x000000000181914e in THD::binlog_flush_pending_rows_event (this=0x7ffe80000b70, stmt_end=true, is_transactional=true) at sql/binlog.cc:11823
#2 0x00000000018198a1 in THD::binlog_query (this=0x7ffe80000b70, qtype=THD::ROW_QUERY_TYPE, query_arg=0x7ffe8000ef10 "insert into mytest04(msisdn,fav_brand,fav_big_type,fav_type,flag_code,fav_order,fav_period,free_value,start_time,end_time,group_id,free_value2,product_code,end_time2,marktmp,marktmp2,marktmp3)values(?"..., query_len=302, is_trans=true, direct=false, suppress_use=false,errcode=0) at sql/binlog.cc:12097
#3 0x000000000178a2ef in Sql_cmd_insert::mysql_insert (this=0x7ffe801bfb70, thd=0x7ffe80000b70, table_list=0x7ffe801be0d8) at sql/sql_insert.cc:859
#4 0x0000000001790862 in Sql_cmd_insert::execute (this=0x7ffe801bfb70, thd=0x7ffe80000b70) at sql/sql_insert.cc:3127
#5 0x000000000156d9db in mysql_execute_command (thd=0x7ffe80000b70, first_level=true) at sql/sql_parse.cc:3596
#6 0x00000000015a9fd4 in Prepared_statement::execute (this=0x7ffe80013030, expanded_query=0x7fffec4d9500, open_cursor=false) at sql/sql_prepare.cc:3977
#7 0x00000000015a8dfb in Prepared_statement::execute_loop (this=0x7ffe80013030, expanded_query=0x7fffec4d9500, open_cursor=false, packet=0x7ffe80ad3a3a "", packet_end=0x7ffe80ae029f "") at sql/sql_prepare.cc:3585
#8 0x00000000015a6784 in mysqld_stmt_execute (thd=0x7ffe80000b70, stmt_id=1, flags=0, params=0x7ffe80ad3a3a "", params_length=51301) at sql/sql_prepare.cc:2573
#9 0x00000000015686b6 in dispatch_command (thd=0x7ffe80000b70, com_data=0x7fffec4d9e10, command=COM_STMT_EXECUTE) at sql/sql_parse.cc:1418
#10 0x00000000015678a4 in do_command (thd=0x7ffe80000b70) at sql/sql_parse.cc:1025
#11 0x00000000016976a5 in handle_connection (arg=0xfd36080) at sql/conn_handler/connection_handler_per_thread.cc:306
#12 0x0000000001d3718a in pfs_spawn_thread (arg=0xfd34340) at storage/perfschema/pfs.cc:2190
#13 0x00007ffff7bc6e65 in start_thread () from /lib64/libpthread.so.0
#14 0x00007ffff660788d in clone () from /lib64/libc.so.6