xtrabackup binary最重要的两个过程是backup和prepare,对应的函数分别是xtrabackup_backup_func()和xtrabackup_prepare_func(),这里做一些阅读代码时的笔记。

xtrabackup backup的线程模型:
1. 一个log拷贝线程;
2. n个ibd文件拷贝线程;
3. 一个io监控线程;
4. 通过suspend_start/suspend_end文件来标注是否启动终止线程;
 
typedef struct {
    datafiles_iter_t *it;
    uint num;
    uint *count;
    os_ib_mutex_t  count_mutex;
    os_thread_id_t  id;
}data_thread_ctxt_t;
数据线程上下文
 
切换工作目录;
 
 116 /** Set if InnoDB must operate in read-only mode. We don't do any
 117 recovery and open all tables in RO mode instead of RW mode. We don't
 118 sync the max trx id to disk either. */
xb_set_innodb_read_only()  将innodb设成只读模式
srv_backup_mode=TRUE;  将innodb设成backup模式;
 
设置innodb的一系列参数
innodb_init_param()
 
xb_normalize_init_values(void)
 
修改srv_unix_file_flush_method
 
根据bp大小,调整srv_max_n_threads参数
 
1017 /*********************************************************************//**
1018 Initializes the synchronization primitives, memory system, and the thread
1019 local storage. */
srv_general_init()
 
ut_crc32_init()
 
xb_filters_init()
 
2567 /************************************************************************
2568 Initializes the I/O and tablespace cache subsystems. */
xb_fil_io_init(void)
 
 838 /******************************************************//**
 839 Initializes the log. */
log_init(void)
 
 585 /*********************************************************************//**
 586 Creates the lock system at database start. */
lock_sys_create()
 
open_or_create_log_file
 
创建xtrabackup_extra_lsndir/extrabackup_traget_dir
 
表空间memory cache
fil_system_t* f_system = fil_system;
 
recv_find_max_checkpoint(&max_cp_group, &max_cp_field)
 
log_group_read_checkpoint_info(max_cp_group, max_cp_field)
 
checkpoint_lsn_start/checkpoint_no_start
确认一致的checkpoint状态;
 
创建XB_LOG_FILENAME文件,写入文件头信息;
 
创建io_watching_thread;
 
从checkpoint位置开始copy log文件;
xtrabackup_copy_logfile(checkpoint_lsn_start, FALSE)
 
log_copying/log_copying_stop
 
创建日志copy线程
os_thread_create(log_copying_thread, NULL, &log_copying_thread_id);
 
2591 /****************************************************************************
2592 Populates the tablespace memory cache by scanning for and opening data files.
2593 @returns DB_SUCCESS or error code.*/
xb_load_tablespaces()
 
挂起,等待XB_FN_SUSPENDED_AT_START文件被删除
xtrabackup_suspend
 
xb_page_bitmap_init()
 
根据xtrabackup_parallel设置,创建data_copy_thread_func线程
 
等待所有data_copy_thread_func线程退出
 
挂起,等待XB_FN_SUSPENDED_AT_END文件被删除
xtrabackup_suspend
 
读取最新的checkpoint, 记录在metadata的to_lsn字段;
通过设置log_copying=FALSE && set log_copying_stop,停止log_copying_thread;
 
创建一个文件XB_FN_LOG_COPIED,通知外部脚本,log_copying_thread已经结束;
 
写metadata;
 
 
prepare_func
 
1. 切换到xtrabackup_real_target_dir
2. 读取XTRABACKUP_METADATA_FILENAME,获取原信息;
    metadata_type
3. xtrabackup_init_temp_log()
4. innodb_init_param()
 
2670 /************************************************************************
2671 Initialize the tablespace memory cache and populate it by scanning for and
2672 opening data files.
2673 @returns DB_SUCCESS or error code.*/
xb_data_files_init()
 
应用增量到全量
xtrabackup_apply_deltas()
 
重设innodb初始化参数
innodb_init_param()
 
 
innodb_init()
 
遍历文件
mtr_start -> mtr_commit
 
 
trx_sys_print_mysql_binlog_offset()
将binlog位置信息输出到 xtrabackup_binlog_pos_innodb文件中
 
xtrabackup_close_temp_log(TRUE)
 
输出记录metadata_log
 
 
backup
$./xtrabackup_56 --defaults-file=/u01/my3928/my.cnf --backup --target_dir=/u01/xianlin.lh/backup_dir/
./xtrabackup_56 version 2.1.8 for MySQL server 5.6.15 Linux (x86_64) (revision id: undefined)
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /u01/my3928/data
xtrabackup: using the following InnoDB configuration:
xtrabackup: innodb_data_home_dir = /u01/my3928/data
xtrabackup: innodb_data_file_path = ibdata1:4G;ibdata2:16M:autoextend
xtrabackup: innodb_log_group_home_dir = /u01/my3928/data
xtrabackup: innodb_log_files_in_group = 4
xtrabackup: innodb_log_file_size = 1073741824
2014-05-05 17:29:35 2ac06bc4a2c0 InnoDB: Using Linux native AIO
xtrabackup: using O_DIRECT
>> log scanned up to (1451746590)
[01] Copying /u01/my3928/data/ibdata1 to /u01/xianlin.lh/backup_dir/ibdata1
>> log scanned up to (1451746590)
>> log scanned up to (1451746590)
>> log scanned up to (1451746590)
>> log scanned up to (1451746590)
>> log scanned up to (1451746590)
>> log scanned up to (1451746590)
>> log scanned up to (1451746590)
>> log scanned up to (1451746590)
>> log scanned up to (1451746590)
>> log scanned up to (1451746590)
>> log scanned up to (1451746590)
>> log scanned up to (1451746590)
>> log scanned up to (1451746590)
>> log scanned up to (1451746590)
>> log scanned up to (1451746590)
>> log scanned up to (1451746590)
>> log scanned up to (1451746590)
>> log scanned up to (1451746590)
[01] ...done
[01] Copying /u01/my3928/data/ibdata2 to /u01/xianlin.lh/backup_dir/ibdata2
[01] ...done
[01] Copying ./test/t2.ibd to /u01/xianlin.lh/backup_dir/test/t2.ibd
[01] ...done
[01] Copying ./test/t4.ibd to /u01/xianlin.lh/backup_dir/test/t4.ibd
[01] ...done
[01] Copying ./test/t3.ibd to /u01/xianlin.lh/backup_dir/test/t3.ibd
[01] ...done
[01] Copying ./test/sbtest1.ibd to /u01/xianlin.lh/backup_dir/test/sbtest1.ibd
>> log scanned up to (1451746590)
>> log scanned up to (1451746590)
[01] ...done
[01] Copying ./test/t1.ibd to /u01/xianlin.lh/backup_dir/test/t1.ibd
[01] ...done
[01] Copying ./mysql/innodb_index_stats.ibd to /u01/xianlin.lh/backup_dir/mysql/innodb_index_stats.ibd
[01] ...done
[01] Copying ./mysql/slave_worker_info.ibd to /u01/xianlin.lh/backup_dir/mysql/slave_worker_info.ibd
[01] ...done
[01] Copying ./mysql/innodb_table_stats.ibd to /u01/xianlin.lh/backup_dir/mysql/innodb_table_stats.ibd
[01] ...done
[01] Copying ./mysql/slave_relay_log_info.ibd to /u01/xianlin.lh/backup_dir/mysql/slave_relay_log_info.ibd
[01] ...done
[01] Copying ./mysql/slave_master_info.ibd to /u01/xianlin.lh/backup_dir/mysql/slave_master_info.ibd
[01] ...done
>> log scanned up to (1451746590)
xtrabackup: The latest check point (for incremental): '1451746590'
xtrabackup: Stopping log copying thread.
.>> log scanned up to (1451746590)
 
xtrabackup: Transaction log of lsn (1451746590) to (1451746590) was copied.
 
 
创建备份的流程
 
1 backup_type = full-backuped
2 from_lsn = 0
3 to_lsn = 1451746590
4 last_lsn = 1451746590
5 compact = 0
 
prepare
$./xtrabackup_56 --defaults-file=/u01/my3928/my.cnf --prepare --target-dir=/u01/xianlin.lh/backup_dir/
./xtrabackup_56 version 2.1.8 for MySQL server 5.6.15 Linux (x86_64) (revision id: undefined)
xtrabackup: cd to /u01/xianlin.lh/backup_dir/
xtrabackup: This target seems to be not prepared yet.
xtrabackup: xtrabackup_logfile detected: size=2097152, start_lsn=(1451746590)
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:4G;ibdata2:16M:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group = 1
xtrabackup: innodb_log_file_size = 2097152
2014-05-05 18:38:32 2b7f2f5202c0 InnoDB: Using Linux native AIO
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:4G;ibdata2:16M:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group = 1
xtrabackup: innodb_log_file_size = 2097152
2014-05-05 18:38:32 2b7f2f5202c0 InnoDB: Using Linux native AIO
xtrabackup: Starting InnoDB instance for recovery.
xtrabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter)
InnoDB: The InnoDB memory heap is disabled
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Compressed tables use zlib 1.2.3
InnoDB: Using Linux native AIO
InnoDB: Using CPU crc32 instructions
InnoDB: Initializing buffer pool, size = 100.0M
InnoDB: Completed initialization of buffer pool
InnoDB: Highest supported file format is Barracuda.
InnoDB: The log sequence numbers 552524932 and 552524932 in ibdata files do not match the log sequence number 1451746590 in the ib_logfiles!
InnoDB: Database was not shutdown normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages
InnoDB: from the doublewrite buffer...
InnoDB: Last MySQL binlog file position 0 26767310, file name mysql-bin.000023
InnoDB: 128 rollback segment(s) are active.
InnoDB: Waiting for purge to start
2014-05-05 18:38:33 2b7f49056700 InnoDB: Warning: table 'test/sbtest1'
InnoDB: in InnoDB data dictionary has unknown flags 50.
InnoDB: 5.6.15 started; log sequence number 1451746590
 
[notice (again)]
  If you use binary log and don't use any hack of group commit,
  the binary log position seems to be:
InnoDB: Last MySQL binlog file position 0 26767310, file name mysql-bin.000023
 
xtrabackup: starting shutdown with innodb_fast_shutdown = 1
InnoDB: FTS optimize thread exiting.
InnoDB: Starting shutdown...
InnoDB: Shutdown completed; log sequence number 1451747281
 
prepare的流程:
 
 
  1 backup_type = full-prepared
  2 from_lsn = 0
  3 to_lsn = 1451746590
  4 last_lsn = 1451746590
  5 compact = 0 

阅读xtrabackup代码的一点笔记的更多相关文章

  1. [转&精]IO_STACK_LOCATION与IRP的一点笔记

    IO_STACK_LOCATION和IRP算是驱动中两个很基础的东西,为了理解这两个东西,找了一点资料. 1. IRP可以看成是Win32窗口程序中的消息(Message),DEVICE_OBJECT ...

  2. 关于SS的一点笔记

    过年的时候抽了点时间了解了下ss的协议.整理了一点笔记,一直没有时间发.今天发一下,免得忘了. SS的结构本身比较简单,他的基本结构如下: ss通常分为client和server两部分 client是 ...

  3. 使用SftpDrive+SourceInsight阅读开源代码

    在虚拟机环境下使用Linux编写和阅读代码,我之前一直是通过Xshell利用ssh登录至虚拟机从而在命令行下使用vim来进行的.目前有阅读开源代码的需要,虽然vim+ctags+cscope可以完成这 ...

  4. PHP代码安全学习笔记V1.0

    PHP代码安全学习笔记V1.0http://www.docin.com/p-778369487.html

  5. 关于最小生成树,拓扑排序、强连通分量、割点、2-SAT的一点笔记

    关于最小生成树,拓扑排序.强连通分量.割点.2-SAT的一点笔记 前言:近期在复习这些东西,就xjb写一点吧.当然以前也写过,但这次偏重不太一样 MST 最小瓶颈路:u到v最大权值最小的路径.在最小生 ...

  6. 阅读 Device Driver Programmer Guide 笔记

    阅读 Device Driver Programmer Guide 笔记 xilinx驱动命名规则 以X开头 源文件命名规则 以x打头 底层头文件与高级头文件 重点来了,关于指针的使用 其中 XDev ...

  7. 阅读Cortex-A53 Technical Reference Manual笔记

    1. 前言 一颗芯片最主要的就是CPU核了,处理CPU Core之外,还存在很多其他IP,包括Graphical.Multimedia.Memory Controller.USB Controller ...

  8. 使用vscode阅读C代码outline不显示问题

    1 问题:使用vscode code 阅读C代码 outline 显示No symbols found in document 'xxxx' 2 参考网上解决方法,进行如下操作 2.1  安装C/C+ ...

  9. 阅读webpack代码笔记:antd-layout的webpack.config.prod.js

    'use strict'; const autoprefixer = require('autoprefixer');//自动补全css前缀 const path = require('path'); ...

随机推荐

  1. springboot将项目打成war包

    1. 将项目的打包方式改为war包 <groupId>com.cc</groupId> <artifactId>aaaaaa</artifactId> ...

  2. Python + Djang+ Visual Studio Code(VSCode)

    使用 Visual Studio Code(VSCode)搭建简单的 Python + Django 开发环境 https://www.cnblogs.com/Dy1an/p/10130518.htm ...

  3. python3 爬虫相关-requests和BeautifulSoup

    前言 时间的关系,这篇文章只记录了相关库的使用,没有进行深入分析,各位看官请见谅(还是因为懒.....) requests使用 发送无参数的get请求 r = requests.get('http:/ ...

  4. oracle用expdp定时备份所有步骤详解[转]

    用oracle命令备份数据库,生成dmp文件,保存了整一套的用户及表数据信息.还原简单.加上widnows的批处理bat命令,实现每天0点备份,现把经验送上给大家! 工具/原料   oracle11g ...

  5. StringUtils的工具类isBlank与isEmply

    1. public static boolean isEmpty(String str)   判断某字符串是否为空,为空的标准是 str==null 或 str.length()==0   下面是 S ...

  6. hasura graphql 角色访问控制

    目前从官方文档以及测试可以看出不加任何header的请求访问的是所有的数据,对于具有访问 控制的请求需要添加请求头,实际生产的使用需要集合web hook 的实现访问控制. 参考配置 访问请求 目前数 ...

  7. Linux环境编程之同步(四):Posix信号量

    信号量是一种用于提供不同进程间或一个给定进程的不同线程间同步手段的原语.有三种类型:Posix有名信号量,使用Posix IPC名字标识.Posix基于内存的信号量,存放在共享内存区中:System ...

  8. Android开发入门

    教我徒弟Android开发入门(一) 教我徒弟Android开发入门(二) 教我徒弟Android开发入门(三) 出处:http://www.cnblogs.com/kexing/tag/Androi ...

  9. Brackets编辑器使用

    常用快捷操作 Ctrl + b 当选中一个文本时,离该文本最近的相同的文本会被高亮显示,这样,相同的2个文本就全部获得了焦点,可以同时更改高亮文本.(对,只会找寻最近的且只找到一个就不找了!惰性查找. ...

  10. How To Enable EPEL Repository in RHEL/CentOS 7/6/5?

    What is EPEL EPEL (Extra Packages for Enterprise Linux) is open source and free community based repo ...