Doublebinlog for MySQL

为确保严格的数据库安全性,本文介绍了一种名为双写Binlog的补丁方案。该方案通过复制所有写入和同步操作来保护二进制日志文件的安全性。即使原始文件损坏,备份文件也能保证数据完整。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Background

         In some projects that require very strict data safety, DBAs will except there is a solution to ensure the safety of binlog. That means after the worst case, OS crash or disk damage, there is a way to find out a whole copy of binlog.

        Doublebinlog patch is done for this requirement. It offers a switch to enable the behavior: any write and fsync operation on binary logs are duplicated in another file. So if the original binlog file is destroyed by disk damage, the bak file can be used.

 

Usage

         Two static variables and a dynamic variable:

       If “log-bin” is set “/log/mysql3306/binlog/binlog”, add two line under [mysqld] in my.cnf

    double_file_src_prefix = /log/mysql3306/binlog/binlog

    double_file_dst_dir    = /log/mysql3306/extra_binlog

 

    a) Be sure mysqld has the privilege of /log/mysql3306/extra_binlog

    b) "set global double_file_switch=1" can enable the strategy, default is off

c) After set double_file_switch=0, "flush logs" is recommended.

 

         The logic is that, if an file operation on a file and the filename has the prefix as double_file_src_prefix, all the operaion will duplicated in another file, which locates in the directory double_file_dst_dir.

 

Design

  In order to avoid modifying the logic, we hook in the file operations such as write/pwrite/fsync/lseek.

1)    When a file is open or create, we check whether it matches the prefix, if yes, the same operation is done in the duplicated file. This will return two file description (fd), src_fd defined as key, dest_fd defined as value, a hash table is used to save the relationship.

2)     When wrte/pwrite/fsync/lseek operate on an fd, search it in the hash table, if there is an item match, get the value as dest_fd, the same operation is done on it.

3)    When close(src_fd), we close(dest_fd) too, and then remove the relationship from hash table.

4)     It is confirmed that when doing fsync, duplicated file is done before original file, so if the server crash, duplicated file will be larger than original, which means the slave will not get “dirty” binary events.

 

 Patch File Download  (based on Percona Server 5518)  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值