ITPub博客

首页 > 数据库 > MySQL > MySQL恢复过程

MySQL恢复过程

原创 MySQL 作者:aoerqileng 时间:2023-01-03 16:17:41 0 删除 编辑

MySQL的xa recover 过程记录


1 首先需要了解的是MySQL在启动的时候,会创建trx_sys,trx_sys_init_at_db_start

在该函数中调用trx_lists_init_at_db_start,这个函数会去扫描undo 段,将未提交的事务添加到事务链表in_rw_trx_list中。


2 开启binlog xa恢复的过程调用堆栈如下

mysqld!ha_recover(st_hash*) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/sql/xa.cc:149)
mysqld!MYSQL_BIN_LOG::recover(st_io_cache*, Format_description_log_event*, unsigned long long*) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/sql/binlog.cc:9939)
mysqld!MYSQL_BIN_LOG::open_binlog(char const*) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/sql/binlog.cc:8507)
mysqld!MYSQL_BIN_LOG::open(char const*) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/sql/binlog.h:662)
mysqld!init_server_components() (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/sql/mysqld.cc:4228)
mysqld!mysqld_main(int, char**) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/sql/mysqld.cc:4755)
mysqld!main (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/sql/main.cc:32)
libdyld.dylib!start (Unknown Source:0)
plugin_foreach(NULL, xarecover_handlerton,
MYSQL_STORAGE_ENGINE_PLUGIN, &info);
调用xarecover_handlerton进行一些判断,哪些事务提交,哪些回滚。
事务进行提交的hton->commit_by_xid(hton, info->list + i);
innodb调用innobase_commit_by_xid(进行提交,之前的事务信息在启动的时候已经恢复,可以直接走提交的流程。
写入binlog的都是prepared 状态,所以xa recoever 提交的是prepared状态的事务


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/25719946/viewspace-2930599/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
二手知识受害者

注册时间:2011-11-02

  • 博文量
    68
  • 访问量
    47732