Merge lp:~sergei.glushchenko/percona-server/mysqlbinlog-stdin-5.1 into lp:percona-server/5.1

Proposed by Sergei Glushchenko
Status: Merged
Approved by: Alexey Kopytov
Approved revision: no longer in the source branch.
Merged at revision: 429
Proposed branch: lp:~sergei.glushchenko/percona-server/mysqlbinlog-stdin-5.1
Merge into: lp:percona-server/5.1
Diff against target: 97 lines (+61/-2)
3 files modified
Percona-Server/client/mysqlbinlog.cc (+3/-2)
Percona-Server/mysql-test/r/percona_bug933969.result (+16/-0)
Percona-Server/mysql-test/t/percona_bug933969.test (+42/-0)
To merge this branch: bzr merge lp:~sergei.glushchenko/percona-server/mysqlbinlog-stdin-5.1
Reviewer Review Type Date Requested Status
Alexey Kopytov (community) Approve
Review via email: mp+93810@code.launchpad.net

Description of the change

Bug #933969: mysqlbinlog doesn't accept stdin
mysqlbinlog can't handle stdin when "|" used.
mysqlbinlog fails after making an attempt to execute seek on pipe handle.
Buffered read used in mysqlbinlog and it's possible to seek inside buffer
window. But in check_header routine seek(0) made before any read
operation, when buffer is empty. Due to it actual seek is performed.
Solution is to avoid seek(0) operation in check_header before any read is
performed, e.g. when we are at the beginning of the file.

To post a comment you must log in.
Revision history for this message
Sergei Glushchenko (sergei.glushchenko) wrote :
Revision history for this message
Alexey Kopytov (akopytov) wrote :
review: Needs Fixing
Revision history for this message
Alexey Kopytov (akopytov) :
review: Approve
Revision history for this message
Sergei Glushchenko (sergei.glushchenko) wrote :

The new fix makes mysqlbinlog not to seek to start pos before header checked.

Revision history for this message
Sergei Glushchenko (sergei.glushchenko) wrote :
Revision history for this message
Alexey Kopytov (akopytov) wrote :

Approved. But you don't really need a typecast in "(my_off_t)0". And, if you do it, there must be a space before 0. Minor thing of course, feel free to leave it as is, just something to keep in mind in future.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Percona-Server/client/mysqlbinlog.cc'
2--- Percona-Server/client/mysqlbinlog.cc 2011-07-11 16:13:27 +0000
3+++ Percona-Server/client/mysqlbinlog.cc 2012-02-23 08:49:20 +0000
4@@ -1752,7 +1752,7 @@
5 }
6
7 pos= my_b_tell(file);
8- my_b_seek(file, (my_off_t)0);
9+ DBUG_ASSERT(pos == 0);
10 if (my_b_read(file, header, sizeof(header)))
11 {
12 error("Failed reading header; probably an empty file.");
13@@ -1912,7 +1912,7 @@
14 /* read from normal file */
15 if ((fd = my_open(logname, O_RDONLY | O_BINARY, MYF(MY_WME))) < 0)
16 return ERROR_STOP;
17- if (init_io_cache(file, fd, 0, READ_CACHE, start_position_mot, 0,
18+ if (init_io_cache(file, fd, 0, READ_CACHE, (my_off_t) 0, 0,
19 MYF(MY_WME | MY_NABP)))
20 {
21 my_close(fd, MYF(MY_WME));
22@@ -1920,6 +1920,7 @@
23 }
24 if ((retval= check_header(file, print_event_info, logname)) != OK_CONTINUE)
25 goto end;
26+ my_b_seek(file, start_position_mot);
27 }
28 else
29 {
30
31=== added file 'Percona-Server/mysql-test/r/percona_bug933969.result'
32--- Percona-Server/mysql-test/r/percona_bug933969.result 1970-01-01 00:00:00 +0000
33+++ Percona-Server/mysql-test/r/percona_bug933969.result 2012-02-23 08:49:20 +0000
34@@ -0,0 +1,16 @@
35+RESET MASTER;
36+DROP TABLE IF EXISTS t1;
37+CREATE TABLE t1 (word VARCHAR(20));
38+INSERT INTO t1 VALUES ("hamite");
39+INSERT INTO t1 VALUES ("hoho");
40+INSERT INTO t1 VALUES ("znamenito");
41+INSERT INTO t1 VALUES ("mrachny");
42+INSERT INTO t1 VALUES ("mrak");
43+INSERT INTO t1 VALUES ("zhut");
44+INSERT INTO t1 VALUES ("parnisha");
45+INSERT INTO t1 VALUES ("krrasota!");
46+INSERT INTO t1 VALUES ("podumayesh");
47+INSERT INTO t1 VALUES ("ogo!");
48+FLUSH LOGS;
49+DROP TABLE t1;
50+RESET MASTER;
51
52=== added file 'Percona-Server/mysql-test/t/percona_bug933969.test'
53--- Percona-Server/mysql-test/t/percona_bug933969.test 1970-01-01 00:00:00 +0000
54+++ Percona-Server/mysql-test/t/percona_bug933969.test 2012-02-23 08:49:20 +0000
55@@ -0,0 +1,42 @@
56+###################### percona_bug933969.test ########################
57+# Bug #933969: mysqlbinlog doesn't accept stdin #
58+# #
59+# The goal of this testcase is to test that mysqlbinlog handle #
60+# stdin correctly when stdin is pipe. #
61+# i.e. "cat log | mysqlbinlog -" don't cause mysqlbinlog failure #
62+######################################################################
63+-- source include/have_log_bin.inc
64+-- source include/not_windows.inc
65+-- source include/not_embedded.inc
66+
67+# deletes all the binary logs
68+RESET MASTER;
69+
70+--disable_warnings
71+DROP TABLE IF EXISTS t1;
72+--enable_warnings
73+
74+# produce some statements for binlog
75+
76+CREATE TABLE t1 (word VARCHAR(20));
77+
78+INSERT INTO t1 VALUES ("hamite");
79+INSERT INTO t1 VALUES ("hoho");
80+INSERT INTO t1 VALUES ("znamenito");
81+INSERT INTO t1 VALUES ("mrachny");
82+INSERT INTO t1 VALUES ("mrak");
83+INSERT INTO t1 VALUES ("zhut");
84+INSERT INTO t1 VALUES ("parnisha");
85+INSERT INTO t1 VALUES ("krrasota!");
86+INSERT INTO t1 VALUES ("podumayesh");
87+INSERT INTO t1 VALUES ("ogo!");
88+
89+FLUSH LOGS;
90+
91+# run mysqlbinlog and make sure it ends normally
92+
93+let $MYSQLD_DATADIR= `SELECT @@datadir`;
94+--system cat $MYSQLD_DATADIR/master-bin.000001 | $MYSQL_BINLOG - >/dev/null
95+
96+DROP TABLE t1;
97+RESET MASTER;

Subscribers

People subscribed via source and target branches