Bug #16167 stdio buffering issue in mysqlslap
Submitted: 3 Jan 2006 22:32 Modified: 14 Feb 2006 2:47
Reporter: Kristian Nielsen Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S2 (Serious)
Version:Latest BitKeeper mysql-5.1-new OS:
Assigned to: Reggie Burnett CPU Architecture:Any

[3 Jan 2006 22:32] Kristian Nielsen
Description:
mysqlslap does not flush stdio buffers before fork().

This means that output is duplicated if stdout is buffered (the buffer content is output both in parent and in child). Stdout is usually unbuffered when run in a terminal, but is buffered when output is redirected.

The output captured by mysqltest for the mysqlslap test case is buffered and hence wrong, but the mysqlslap.result file contains the errorneous output, hence the test succeeds :-(. But on platforms with different stdio buffering it fails (ie. QNX).

How to repeat:
In a terminal window:

$ mysqlslap -uroot --socket=/tmp/knielsen/master.sock --password= --only-print --iterations=1  --query="select * from t1" --create="CREATE TABLE t1 (id int);" --delimiter=";"
DROP SCHEMA IF EXISTS `mysqlslap`;
CREATE SCHEMA `mysqlslap`;
use mysqlslap;
CREATE TABLE t1 (id int);
select * from t1;
DROP SCHEMA IF EXISTS `mysqlslap`;

$ mysqlslap -uroot --socket=/tmp/knielsen/master.sock --password= --only-print --iterations=1  --query="select * from t1" --create="CREATE TABLE t1 (id int);" --delimiter=";"|cat
DROP SCHEMA IF EXISTS `mysqlslap`;
CREATE SCHEMA `mysqlslap`;
use mysqlslap;
CREATE TABLE t1 (id int);
select * from t1;
DROP SCHEMA IF EXISTS `mysqlslap`;
CREATE SCHEMA `mysqlslap`;
use mysqlslap;
CREATE TABLE t1 (id int);
DROP SCHEMA IF EXISTS `mysqlslap`;

The second invocation is buffered (because of piping into cat), and produces extra output.

Suggested fix:
The stdout / stderr need to be fflush()'ed before fork(). Possibly the log file and/or other handles need fflush()'ing as well. And the mysqlslap.result file must be fixed to contain the proper expected output, not the wrong duplicated output.

I will temporarily disable the mysqlslap test case for 5.1 in mysql-test/t/disabled.def. Please re-enable the test case as part of the fix to this bug.
[3 Jan 2006 22:38] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/566
[14 Feb 2006 2:47] Brian Aker
This was fixed sometime ago.  The test case is enabled.