天天看點

mysql非正常停止(當機、crash) binlog的恢複過程

通過binlog 復原 已sync的redo日志 
#0  trx_undo_set_state_at_prepare (trx=0x7fffed2d5478, undo=0xfad8cd8, rollback=true, mtr=0x7fffffffc640) at /mysql-boost-5.7.32/mysql-5.7.32/storage/innobase/trx/trx0undo.cc:1904
#1  0x0000000001ab981f in trx_rollback_low (trx=0x7fffed2d5478) at /mysql-boost-5.7.32/mysql-5.7.32/storage/innobase/trx/trx0roll.cc:242
#2  0x0000000001ab9a0b in trx_rollback_for_mysql (trx=0x7fffed2d5478) at /mysql-boost-5.7.32/mysql-5.7.32/storage/innobase/trx/trx0roll.cc:297
#3  0x000000000189fb53 in innobase_rollback_trx (trx=0x7fffed2d5478) at /mysql-boost-5.7.32/mysql-5.7.32/storage/innobase/handler/ha_innodb.cc:4593
#4  0x00000000018b794f in innobase_rollback_by_xid (hton=0x2d75fd0, xid=0x7ffe78172030) at /mysql-boost-5.7.32/mysql-5.7.32/storage/innobase/handler/ha_innodb.cc:17276
#5  0x00000000016288dd in xarecover_handlerton (unused=0x0, plugin=0x7fffffffcf98, arg=0x7fffffffd060) at /mysql-boost-5.7.32/mysql-5.7.32/sql/xa.cc:135
#6  0x00000000015470c3 in plugin_foreach_with_mask (thd=0x0, funcs=0x7fffffffd010, type=1, state_mask=4294967287, arg=0x7fffffffd060) at /mysql-boost-5.7.32/mysql-5.7.32/sql/sql_plugin.c
c:2524
#7  0x0000000001547183 in plugin_foreach_with_mask (thd=0x0, func=0x16285ea <xarecover_handlerton(THD*, plugin_ref, void*)>, type=1, state_mask=8, arg=0x7fffffffd060) at /mysql-boost-5.7
.32/mysql-5.7.32/sql/sql_plugin.cc:2539
#8  0x0000000001628bba in ha_recover (commit_list=0x7fffffffd160) at /mysql-boost-5.7.32/mysql-5.7.32/sql/xa.cc:203
/*recover binlog ,入口*/
#9  0x00000000017c6a4c in MYSQL_BIN_LOG::recover (this=0x2cd9140 <mysql_bin_log>, log=0x7fffffffd2b0, fdle=0x2ec8210, valid_pos=0x7fffffffd9f8) at /mysql-boost-5.7.32/mysql-5.7.32/sql/bi
nlog.cc:9939
#10 0x00000000017c342a in MYSQL_BIN_LOG::open_binlog (this=0x2cd9140 <mysql_bin_log>, opt_name=0x2d75f90 "mysql-bin") at /mysql-boost-5.7.32/mysql-5.7.32/sql/binlog.cc:8502
#11 0x00000000017ccd67 in MYSQL_BIN_LOG::open (this=0x2cd9140 <mysql_bin_log>, opt_name=0x2d75f90 "mysql-bin") at /mysql-boost-5.7.32/mysql-5.7.32/sql/binlog.h:662
#12 0x0000000000e7e715 in init_server_components () at /mysql-boost-5.7.32/mysql-5.7.32/sql/mysqld.cc:4232
#13 0x0000000000e7f67c in mysqld_main (argc=100, argv=0x2d742e8) at /mysql-boost-5.7.32/mysql-5.7.32/sql/mysqld.cc:4759
#14 0x0000000000e770cd in main (argc=3, argv=0x7fffffffe3b8) at /mysql-boost-5.7.32/mysql-5.7.32/sql/main.cc:32
           
/*
      If the binary log was not properly closed it means that the server
      may have crashed. In that case, we need to call MYSQL_BIN_LOG::recover
      to:

        a) collect logged XIDs;
        b) complete the 2PC of the pending XIDs;
        c) collect the last valid position.

      Therefore, we do need to iterate over the binary log, even if
      total_ha_2pc == 1, to find the last valid group of events written.
      Later we will take this value and truncate the log if need be.
    */
    if ((ev= Log_event::read_log_event(&log, 0, &fdle,
                                       opt_master_verify_checksum)) &&
        ev->get_type_code() == binary_log::FORMAT_DESCRIPTION_EVENT &&
        (ev->common_header->flags & LOG_EVENT_BINLOG_IN_USE_F ||
         DBUG_EVALUATE_IF("eval_force_bin_log_recovery", true, false)))
    {
      sql_print_information("Recovering after a crash using %s", opt_name);
      valid_pos= my_b_tell(&log);
      error= recover(&log, (Format_description_log_event *)ev, &valid_pos);
    }
           

繼續閱讀