Bug #34317 mysqlbinlog produces bad output for LOAD DATA INFILE in 3.23 binlog
Submitted: 5 Feb 2008 17:59 Modified: 6 Feb 2008 22:00
Reporter: Sven Sandberg Email Updates:
Status: Won't fix Impact on me:
None 
Category:MySQL Server: Replication Severity:S3 (Non-critical)
Version:5.1 OS:Any
Assigned to: CPU Architecture:Any
Tags: 3.23, LOAD DATA INFILE, Load_log_event, mysqlbinlog

[5 Feb 2008 17:59] Sven Sandberg
Description:
In binlogs from version 3.23, LOAD DATA INFILE statements were logged using Load_log_events. Load_log_events do not include the file contents. Rather, mysqlbinlog connects to the server, requests the file from server, and saves it to a temporary local file. mysqlbinlog outputs a LOAD DATA INFILE statement which reads the produced temporary file. The sequence is currently as follows:

 1. create temp file
 2. output LOAD DATA INFILE statement
 3. request dump from server and fill temp file with the contents

If the result of mysqlbinlog is piped to a client, it is possible that the client sees the LOAD DATA INFILE statement after 2 but before 3. In this case, it may read an empty or half-written file.

Note: this was found by inspecting the code. I have not tested that it fails, since it is hard to compile version 3.23.

How to repeat:
Inspect the code. Should be repeatable by inserting a delay between step 2 and 3.

Suggested fix:
Permute steps 2 and 3.
[6 Feb 2008 7:49] Sveta Smirnova
Thank you for the report.

Verified as described:

$/Users/apple/Applications/mysql-5.1/bin/mysqlbinlog  /Users/apple/Applications/mysql-3.23.38/data321/apple-bin.2421  | mysql51 test
ERROR 29 (HY000) at line 13: File '/Users/apple/Applications/mysql-5.1/data/test/test.txt' not found (Errcode: 2)

$/Users/apple/Applications/mysql-5.1/bin/mysqlbinlog  /Users/apple/Applications/mysql-3.23.38/data321/apple-bin.2421  
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#080128 12:21:48 server id 321  end_log_pos 0   Start: binlog v 1, server v 3.23.58-log created 080128 12:21:48 at startup
# at 73
#080206 10:40:53 server id 321  end_log_pos 0   Query   thread_id=19051 exec_time=0     error_code=0
use test/*!*/;
SET TIMESTAMP=1202283653/*!*/;
create table t1(id int)/*!*/;
# at 125
#080206 10:42:46 server id 321  end_log_pos 0   Query   thread_id=19059 exec_time=0
LOAD DATA INFILE 'test.txt' INTO TABLE `t1` FIELDS TERMINATED BY '\t' ENCLOSED BY '' ESCAPED BY '\\' LINES TERMINATED BY '\n' STARTING BY '' (id)/*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;