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
=== modified file 'Percona-Server/client/mysqlbinlog.cc'
--- Percona-Server/client/mysqlbinlog.cc 2011-07-11 16:13:27 +0000
+++ Percona-Server/client/mysqlbinlog.cc 2012-02-23 08:49:20 +0000
@@ -1752,7 +1752,7 @@
1752 }1752 }
17531753
1754 pos= my_b_tell(file);1754 pos= my_b_tell(file);
1755 my_b_seek(file, (my_off_t)0);1755 DBUG_ASSERT(pos == 0);
1756 if (my_b_read(file, header, sizeof(header)))1756 if (my_b_read(file, header, sizeof(header)))
1757 {1757 {
1758 error("Failed reading header; probably an empty file.");1758 error("Failed reading header; probably an empty file.");
@@ -1912,7 +1912,7 @@
1912 /* read from normal file */1912 /* read from normal file */
1913 if ((fd = my_open(logname, O_RDONLY | O_BINARY, MYF(MY_WME))) < 0)1913 if ((fd = my_open(logname, O_RDONLY | O_BINARY, MYF(MY_WME))) < 0)
1914 return ERROR_STOP;1914 return ERROR_STOP;
1915 if (init_io_cache(file, fd, 0, READ_CACHE, start_position_mot, 0,1915 if (init_io_cache(file, fd, 0, READ_CACHE, (my_off_t) 0, 0,
1916 MYF(MY_WME | MY_NABP)))1916 MYF(MY_WME | MY_NABP)))
1917 {1917 {
1918 my_close(fd, MYF(MY_WME));1918 my_close(fd, MYF(MY_WME));
@@ -1920,6 +1920,7 @@
1920 }1920 }
1921 if ((retval= check_header(file, print_event_info, logname)) != OK_CONTINUE)1921 if ((retval= check_header(file, print_event_info, logname)) != OK_CONTINUE)
1922 goto end;1922 goto end;
1923 my_b_seek(file, start_position_mot);
1923 }1924 }
1924 else1925 else
1925 {1926 {
19261927
=== added file 'Percona-Server/mysql-test/r/percona_bug933969.result'
--- Percona-Server/mysql-test/r/percona_bug933969.result 1970-01-01 00:00:00 +0000
+++ Percona-Server/mysql-test/r/percona_bug933969.result 2012-02-23 08:49:20 +0000
@@ -0,0 +1,16 @@
1RESET MASTER;
2DROP TABLE IF EXISTS t1;
3CREATE TABLE t1 (word VARCHAR(20));
4INSERT INTO t1 VALUES ("hamite");
5INSERT INTO t1 VALUES ("hoho");
6INSERT INTO t1 VALUES ("znamenito");
7INSERT INTO t1 VALUES ("mrachny");
8INSERT INTO t1 VALUES ("mrak");
9INSERT INTO t1 VALUES ("zhut");
10INSERT INTO t1 VALUES ("parnisha");
11INSERT INTO t1 VALUES ("krrasota!");
12INSERT INTO t1 VALUES ("podumayesh");
13INSERT INTO t1 VALUES ("ogo!");
14FLUSH LOGS;
15DROP TABLE t1;
16RESET MASTER;
017
=== added file 'Percona-Server/mysql-test/t/percona_bug933969.test'
--- Percona-Server/mysql-test/t/percona_bug933969.test 1970-01-01 00:00:00 +0000
+++ Percona-Server/mysql-test/t/percona_bug933969.test 2012-02-23 08:49:20 +0000
@@ -0,0 +1,42 @@
1###################### percona_bug933969.test ########################
2# Bug #933969: mysqlbinlog doesn't accept stdin #
3# #
4# The goal of this testcase is to test that mysqlbinlog handle #
5# stdin correctly when stdin is pipe. #
6# i.e. "cat log | mysqlbinlog -" don't cause mysqlbinlog failure #
7######################################################################
8-- source include/have_log_bin.inc
9-- source include/not_windows.inc
10-- source include/not_embedded.inc
11
12# deletes all the binary logs
13RESET MASTER;
14
15--disable_warnings
16DROP TABLE IF EXISTS t1;
17--enable_warnings
18
19# produce some statements for binlog
20
21CREATE TABLE t1 (word VARCHAR(20));
22
23INSERT INTO t1 VALUES ("hamite");
24INSERT INTO t1 VALUES ("hoho");
25INSERT INTO t1 VALUES ("znamenito");
26INSERT INTO t1 VALUES ("mrachny");
27INSERT INTO t1 VALUES ("mrak");
28INSERT INTO t1 VALUES ("zhut");
29INSERT INTO t1 VALUES ("parnisha");
30INSERT INTO t1 VALUES ("krrasota!");
31INSERT INTO t1 VALUES ("podumayesh");
32INSERT INTO t1 VALUES ("ogo!");
33
34FLUSH LOGS;
35
36# run mysqlbinlog and make sure it ends normally
37
38let $MYSQLD_DATADIR= `SELECT @@datadir`;
39--system cat $MYSQLD_DATADIR/master-bin.000001 | $MYSQL_BINLOG - >/dev/null
40
41DROP TABLE t1;
42RESET MASTER;

Subscribers

People subscribed via source and target branches