Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make gtid enabled slave with less durable settings crash safe
Summary: With less durable settins (sync_binlog !=1 and innodb_flush_log_at_trx_commit !=1), a slave with GTIDs/MTS is not crash safe. Two possible scenarios causing slave inconsistency 1) slave's binary log is behind innodb transaction log. 2) slave's binary log is ahead of innodb transaction log. The slave_gtid_info transaction table consistently stores gtid information and handles scenario 1. But in case of scenario 2, even though the slave_gtid_info is consistent with innodb, slave will skip executing some transactions if it's GTID is logged in the binlog even though it is not committed in innodb. This diff fixes scenario 2 by changing gtid_executed when a slave is initialized based on the binlog file and binlog position which are logged inside innodb trx log. When gtid_executed is set to an old value which is consistent with innodb, slave doesn't miss any transactions. Changing gtid_executed after crash recovery should be done only on slaves with gtid enabled. Crash recovery on master should not do this because it will create duplicate GTID log events for different transactions causing data inconsistency on slaves. Note that slaves may have duplicate GTID log events, but those GTIDs corresponds to same transaction. Leaving the extra binlog events on the slave doesn't create any problems because any slave receiving those extra events skip executing any duplicate GTIDs. Note that binlog file and binlog position in innodb header may be behind binlog since there may be some transaction that are rolled forward during crash recovery, but slave_gtid_info table handles those cases by skipping the transactions but printing them to the binlog. Test Plan: repeatedly crashed a slave with innodb_flush_log_at_trx_commit=0 mtr_run --repeat=32 rpl_gtid_mts_stress_crash Reviewers: rudradevbasak, jtolmer, yoshinori, tianx Reviewed By: jtolmer, tianx
- Loading branch information