MySQL Bug 72804In this blog post, we’ll look at a workaround for MySQL bug 72804.

Recently I worked on a ticket where a customer performed a point-in-time recovery PITR using a large set of binary logs. Normally we handle this by applying the last backup, then re-applying all binary logs created since the last backup. In the middle of the procedure, their new server crashed. We identified the binary log position and tried to restart the PITR from there. However, using the option --start-position, the restore failed with the error “The BINLOG statement of type Table_map was not preceded by a format description BINLOG statement.” This is a known bug and is reported as MySQL Bug #72804: “BINLOG statement can no longer be used to apply Query events.”

I created a small test to demonstrate a workaround that we implemented (and worked).

First, I ran a large import process that created several binary logs. I used a small value in  max_binlog_size and tested using the database “employees” (a standard database used for testing).Then I dropped the database.

To demonstrate the recovery process, I joined all the binary log files into one SQL file and started an import.

I intentionally generated a syntax error in the resulting file with the help of the GENERATE_ERROR.sh script (which just inserts a bogus SQL statement in a random row). The error message clearly showed where the import stopped: line 9020. I then created a file that cropped out the part that had already been imported (lines 1- 9020), and tried to import this new file.

Again, the import failed with exactly the same error as the customer. The reason for this error is that the BINLOG statement – which applies changes from the binary log – expects that the format description event gets run in the same session as the binary log import, but before it. The format description existed initially at the start of the import that failed at line 9020. The later import (from line 9021 on) doesn’t contain this format statement.

Fortunately, this format is the same for the same version! We can simply take it from the beginning the SQL log file (or the original binary file) and put into the file created after the crash without lines 1-9020.

With MySQL versions 5.6 and 5.7, this event is located in the first 11 rows:

The first six rows are meta information, and rows 6-11 are the format event itself. The only thing we need to export into our resulting file is these 11 lines:

After this, the import succeeded!

10 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Jean-François Gagné

Hi Svela, if I understand well, Bug#72804 can happen if you do not restart the import at a transaction boundary. In this case, wouldn’t your import be inconsistent (missing the previous statements in the transaction) ? If this is the case, I think it should be closed as “Not a Bug”.

For PITR, I prefer to use Binlog Server. I wrote a blog post in the past about this: [1]. The advantage of using Binlog Server is using all power of replication: easy restart, transaction skipping, parallel replication, possibility of using filtering, … I also understand that Facebook built their own Binlog Server exactly for that ([2]).

[1]: http://jfg-mysql.blogspot.nl/2015/10/binlog-servers-for-backups-and-point-in-time-recovery.html

[2]: https://www.percona.com/live/plam16/sessions/binlog-server-facebook

Best regards.

No, although I did not explicitly mention this, I am not trying to apply partial transaction.

Daniel Golding

I think you’ve misunderstood bug 72804. In the bug report he encodes a QUERY event in base64 and applies after a having already appied a binlog format description event. Which is currently not allowed.

In your hypothetical example, you were making a mistake by not having sent a format description event before your table_map event. Using –start-position with mysqlbinlog it should still emit a format_description_event before applying the event at the start position

The issue your customer had, where they were using the –start-position option with mysqlbinlog, that sounds like a bug with the version of mysqlbinlog they were using to me. I don’t know whether this once has been a problem

Happy to be corrected if I’m mistaken

Siddhesh Urkude

Bibliography MySQL concept is very interesting.
Nicely explained. Thanks for sharing.

Siddhesh-C Programming

Siddhesh Urkude

Sorry for my autocorrect

*Binlog

dinglin

Is it a bit dangerous that use the binlog_rest.sql directly? If there is a transaction just cross the 9020th line, this transaction will fail and rollback when it occur the error in 9020. After that, when we use the second part, the transaction is partial. So it may lead to data lost.

james

thanks a lot