Demystifying MySQL Replication Crash Safety
Presented at Percona Live Europe 2018 in Frankfurt by Jean-François Gagné Senior Infrastructure Engineer / System and MySQL Expert jeanfrancois AT messagebird DOT com
Demystifying MySQL Replication Crash Safety Presented at Percona - - PowerPoint PPT Presentation
Demystifying MySQL Replication Crash Safety Presented at Percona Live Europe 2018 in Frankfurt by Jean-Franois Gagn Senior Infrastructure Engineer / System and MySQL Expert jeanfrancois AT messagebird DOT com Introducing MessageBird 225+
Presented at Percona Live Europe 2018 in Frankfurt by Jean-François Gagné Senior Infrastructure Engineer / System and MySQL Expert jeanfrancois AT messagebird DOT com
2
MessageBird is a cloud communications platform founded in Amsterdam 2011. Examples of our messaging and voice SaaS:
SMS in and out, call in (IVR) and out (alert), SIP, WhatsApp, Facebook, Telegram, Twitter, WeChat, … Omni-Channel Conversation
Details at www.messagebird.com
225+ Direct-to-Carrier Agreements
With operators from around the world
15,000+ Customers
In over 60+ countries
180+ Employees
Engineering office in Amsterdam Sales and support offices worldwide
We are expanding :
{Software, Front-End, Infrastructure, Data, Security, Telecom, QA} Engineers {Team, Tech, Product} Leads, Product Owners, Customer Support {Commercial, Connectivity, Partnership} Managers www.messagebird.com/careers
3
(OK if rewinds its state after recovery, as long as it is eventually consistent)
(Discussion limited to transactional SE: InnoDB, TokuDB, MyRocks; obviously not MyISAM)
(Proving replication crash un-safety is easy, proving safety is hard)
5
6
(with complexity added by Logical Lock parallel replication)
(but it can be made unsafe by “tuning” the configuration)
7
slave1 [localhost] {msandbox} ((none)) > show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event [...] Master_Log_File: mysql-bin.000001 <-------+-- master info (persisted state) Read_Master_Log_Pos: 25489 <-------+ Relay_Log_File: mysql-relay.000002 <--+ Relay_Log_Pos: 10788 <--+ Relay_Master_Log_File: mysql-bin.000001 <--+-- relay log info (persisted state) [...] | Exec_Master_Log_Pos: 10575 <--+ [...] 1 row in set (0.00 sec)
Ø This is why replication is not crash-safe in MySQL 5.5
8
9
(default 0 in My|SQL 5.5 and 5.6; and in 5.7 and 8.0 it is 1 which is full ACID)
10
12
(relay-log-recovery does not delete anything: easy to test with skip-slave-start) Ø Said otherwise, the previous relay logs are skipped ! (those relay logs are considered improper for SQL Thread consumption)
OK for 1st implementation but a waste of perfectly good relay logs
13
K
L
J
J
Bug#74323: Avoid overloading the master NIC on relay-log-recovery of a lagging slave Bug#74321: Execute relay-log-recovery only when needed
Ø IO and SQL Thread states are now partially in the binlogs (and relay logs)
Ø As this tracking is in the binlogs, this is impeded when sync_binlog != 1 Bug#70659: Make crash safe slave with gtid + less durable settings
14
Ø Missed opportunity for OS crash safety with sync_binlog != 1 L L L Bug#92109: Make GTID replication crash safe with less durable setting
15
16
Ø InnoDB will also lose transactions on an OS crash Ø After an OS crash, InnoDB will be out-of-sync with the binlogs Ø And we cannot trust the binlogs on such master (trx gap or ghost trx)
17
18
19
(in illustration, the slave will skip new 50 to 58 as it has the old one)
20
https://jfg-mysql.blogspot.com/2018/10/consequences-sync-binlog-neq-1-part-1.html
(more posts to be published in the series)
Ø After an OS crash, make sure no slaves reconnect to the recovered master (OFFLINE_MODE = ON in config file – failing-over to a slave is the way forward)
Ø After an OS crash, consider purging all binlogs on the recovered slave
Ø After an OS crash make sure no slaves reconnect to the recovered IM Ø And consider purging all binary logs on it
21
22
(OFF by default in 5.7 and 8.0 K, with ON requiring log-slave-updates L) (Bug#75396: Allow slave_preserve_commit_order without log-slave-updates)
(maybe B and D are in the same schema with DATABASE type)
(https://dev.mysql.com/worklog/task/?id=5599: for more details)
23
24
25
(sync_binlog != 1 should not be needed in 95% of cases) (Group Commit and MTS make this optimisation almost obsolete)
26
Bug#92882: MTS not replication crash-safe with GTID and all the right parameters (Only applies to Operating System crashes)
(This might be a regression from the fix of Bug#77496) (Easy workaround: stop slave; reset slave; start slave;)
27
Question about Semi-Synchronous Replication: the Answer with All the Details
https://www.percona.com/community-blog/2018/08/23/question-about-semi-synchronous- replication-answer-with-all-the-details/
28
https://kristiannielsen.livejournal.com/19223.html
29
https://github.com/github/orchestrator/blob/master/docs/pseudo-gtid.md
32
and maybe a “stop slave; reset slave; start slave;” (Bug#92882)
33
J
J
J
K
34
L
L
35
https://hackmongo.com/post/crash-safe-mysql-replication-a-visual-guide/ (diagrams in this talk are inspired by this post)
https://medium.com/booking-com-infrastructure/better-crash-safe-replication-for-mysql-a336a69b317f
https://jfg-mysql.blogspot.com/2016/01/replication-crash-safety-with-mts.html
https://jfg-mysql.blogspot.com/2016/08/discussion-about-sync-master-info-and-replication-parameters.html
https://jfg-mysql.blogspot.com/2018/10/consequences-sync-binlog-neq-1-part-1.html
36
https://www.percona.com/community-blog/2018/08/23/question-about-semi-synchronous-replication-answer-with-all-the-details/
https://kristiannielsen.livejournal.com/19223.html
https://github.com/github/orchestrator/blob/master/docs/pseudo-gtid.md https://speakerdeck.com/shlominoach/pseudo-gtid-and-easy-mysql-replication-topology-management
https://www.slideshare.net/JeanFranoisGagn/the-full-mysql-and-mariadb-parallel-replication-tutorial
https://jfg-mysql.blogspot.com/2018/10/arg-relay-log-space-limit-is-still-not-dynamic.html
https://medium.com/booking-com-infrastructure/evaluating-mysql-parallel-replication-part-2-slave-group-commit-459026a141d2
https://medium.com/booking-com-infrastructure/evaluating-mysql-parallel-replication-part-4-more-benchmarks-in-production-49ee255043ab
Presented at Percona Live Europe 2018 in Frankfurt by Jean-François Gagné Senior Infrastructure Engineer / System and MySQL Expert jeanfrancois AT messagebird DOT com