Bug #47423 mysqltest attaches to wrong database
Submitted: 17 Sep 2009 22:25 Modified: 18 Dec 2009 23:50
Reporter: Vladislav Vaintroub Email Updates:
Status: Closed Impact on me:
None 
Category:Tools: MTR / mysql-test-run Severity:S3 (Non-critical)
Version:5.1.40 OS:Windows
Assigned to: Vladislav Vaintroub CPU Architecture:Any

[17 Sep 2009 22:25] Vladislav Vaintroub
Description:
I have MySQL 5.1.38 installed. 

I enabled share memory and named pipe protocols, using

enable-named-pipe
shared-memory

in my.ini

MySQL service is started, i.e database is online.

I also compiled 5.1 from source and want to test it with mtr. It fails with 

Could not execute 'check-testcase' before testcase 'main.1st' (res: 1):
mysqltest: Logging to 'H:\bzr\mysql-5.1\mysql-test\var\tmp\check-mysqld_1.log'.
mysqltest: Results saved in 'H:/bzr/mysql-5.1/mysql-test/var/tmp/check-mysqld_1.
result'.
mysqltest: Connecting to server localhost:13000 (socket H:/bzr/mysql-5.1/mysql-t
est/var/tmp/mysqld.1.sock) as 'root', connection 'default', attempt 0 ...
mysqltest: ... Connected.
mysqltest: Start processing test commands from '.\include\check-testcase.test' .
..
mysqltest: At line 11: query 'call mtr.check_testcase()' failed: 1305: PROCEDURE
 mtr.check_testcase does not exist
not ok

If I do not run the installed instance (e.g stop MySQL service), then mtr succeeds.  I believe the conclusion is that mysqltest does not connect to the test database (which runs on port 13000), but to the installed instance which runs on port 3306 (and additionally can be connected via pipe or shared memory).

When I just start 
"mysqltest --port=13000 -uroot" , process explorer tells me mysqltest connects via shared memory to the installed instance( both it has open handles to Section and Event objects named MYSQL_8_DATA etc)

How to repeat:
Follow the steps described above

Suggested fix:
Prevent mysqtest using shared memory and pipe protocols under normal circumstances (maybe there are special cases, where shm or named pipe are required, I do not know), force TCP communication.
[21 Sep 2009 7:06] Sveta Smirnova
Thank you for the report.

Verified as described.

For "already running" MySQL server any port can be specified.
[27 Sep 2009 14:51] 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/84745

2837 Vladislav Vaintroub	2009-09-27
      Bug #47423 mysqltest attaches to wrong database 
      
      The reason for the bug is that mysqtest will try to connect via shared memory,
      with default shared memory base name "MySQL". If mysql is installed, and shared
      memory is enabled, mysql-test will attach to it.
      
      The fix is to use TCP connections, as port number for mtr is unique. In mtr scripts,
      this setting can be overwritten with connect(<something>,,,NAMEDPIPE) or
       connect(<something>,,,SHM)
[27 Sep 2009 16:01] 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/84755

2837 Vladislav Vaintroub	2009-09-27
      Bug #47423 mysqltest attaches to wrong database
      
      The reason for the bug is that mysqtest will try to connect via 
      shared memory, with default shared memory base name "MySQL". 
      If mysql is installed, and shared memory is enabled, mysqltest 
      will attach to it instead of its own instance.
      
      The fix is to use TCP connections, as port numbers used by mtr 
      are unique. In mtr scripts,connection protocol can be overwritten 
      with connect(<something>,,,PIPE) or connect(<something>,,,SHM).  
      This functionality (optional parameters for connect command was manually
      backported from 6.0(original patch  http://lists.mysql.com/commits/74749)
[28 Sep 2009 10:51] 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/84825

2837 Vladislav Vaintroub	2009-09-28
      Bug #47423 mtr connects to wrong database
      
      The reason for the bug is that mysqtest as well as other client tools
      running in test suite (mysqlbinlog, mysqldump) will first try to connect 
      whatever database has created shared memory with default base name 
      "MySQL" and use this. (Same effect could be seen on Unix if mtr would
      not care to calculate "port" and "socket" parameter).
      
      The fix ensures that all client tools and  running in mtr use unique  
      per-database shared memory base parameters, so there is no possibility
      to clash with already installed one. We use socket name for shared memory 
      base (it's known to be unique). This shared-memory-base is written to the
      MTR config file to the [client] and [mysqld] sections. Fix made also made 
      sure all client tools understand and correctly handle --shared-memory-base.
      Prior to this patch  it was not the case for  mysqltest, mysqlbinlog and 
      mysql_client_test.
      
      All new connections done from mtr scripts via connect() will by default 
      set shared-memory-base. And finally, there is a possibility to force 
      shared memory or pipe connection and overwrite shared memory/pipe base name
      from within mtr scripts via optional PIPE or SHM modifier. This functionality
      was manually backported from 6.0
      (original patch  http://lists.mysql.com/commits/74749)
     @ client/mysqlbinlog.cc
        Make sure mysqlbinlog understands and properly handles
        --shared-memory-base-name
     @ client/mysqltest.cc
        Make sure mysqltest understands and properly handles
        --shared-memory-base-name
        
        backport change by Davi Arnaut that adds additional 
        connect() modifiers PIPE and SHM.
        (http://lists.mysql.com/commits/74749)
     @ mysql-test/lib/My/ConfigFactory.pm
        Add shared-memory-base-name to [mysqld] and [client] sections.
     @ mysql-test/t/named_pipe.test
        Force named pipe connection for named_pipe test.
     @ tests/mysql_client_test.c
        Make sure mysql_client_test understands and properly handles
        --shared-memory-base-name. All calls to mysql_init() are
        replaced with mysql_client_init() wrapper that will set shared
        memory base option, if it was specified.
[30 Sep 2009 11:05] Bjørn Munch
I'm not familiar with this stuff on Windoes, but I have two comments:

1. You're inconsistent in the use of

#if HAVE_SMEM
vs.
#ifdef HAVE_SMEM

I think #ifdef would be the mormal way, unless there are cases where
it may be defined but 0.

BTW, is this only relevant on Windows?

2. Instead of adding a new mysql_client_init and a macro disallowing
calls to mysql_init(), wouldn't it be better to let the new function
take over the name and rename the old one?  Then you won't need to
change the (many) calling places and won't need this ugly macro.
[30 Sep 2009 11:58] Vladislav Vaintroub
@Bjorn,

#if HAVE_SMEM
vs.
#ifdef HAVE_SMEM

yeah, it is copy& paste from somewhere else. Will fix that. 
HAVE_SMEM is defined with #define HAVE_SMEM in config-win.h

Re. mysql_client_init(), I'm not absoluteky sure what you propose

If it is this
#define mysql_init(a) my_client_init(a)
instead of
#define mysql_init(a) Please use mysql_client_init instead

then I tend to disagree.. This will make the change smaller but has an obfsucating effect. if people see mysql_init(NULL) they expect a well know mysql_init() from the client API, and not a extended and re#defined (just for this file) version of it. 

Yes, shared memory is for Windows only. I think it was originally though to be cross-platform, but this never happened. HAVE_SMEM is btw not defined in embedded.
[30 Sep 2009 12:30] 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/85203

2837 Vladislav Vaintroub	2009-09-30
      Bug #47423 mtr connects to wrong database
      
      The reason for the bug is that mysqtest as well as other client tools
      running in test suite (mysqlbinlog, mysqldump) will first try to connect 
      whatever database has created shared memory with default base name 
      "MySQL" and use this. (Same effect could be seen on Unix if mtr would
      not care to calculate "port" and "socket" parameter).
      
      The fix ensures that all client tools and  running in mtr use unique  
      per-database shared memory base parameters, so there is no possibility
      to clash with already installed one. We use socket name for shared memory 
      base (it's known to be unique). This shared-memory-base is written to the
      MTR config file to the [client] and [mysqld] sections. Fix made also made 
      sure all client tools understand and correctly handle --shared-memory-base.
      Prior to this patch  it was not the case for  mysqltest, mysqlbinlog and 
      mysql_client_test.
      
      All new connections done from mtr scripts via connect() will by default 
      set shared-memory-base. And finally, there is a possibility to force 
      shared memory or pipe connection and overwrite shared memory/pipe base name
      from within mtr scripts via optional PIPE or SHM modifier. This functionality
      was manually backported from 6.0
      (original patch  http://lists.mysql.com/commits/74749)
     @ client/mysqlbinlog.cc
        Make sure mysqlbinlog understands and properly handles
        --shared-memory-base-name
     @ client/mysqltest.cc
        Make sure mysqltest understands and properly handles
        --shared-memory-base-name
        
        backport change by Davi Arnaut that adds additional 
        connect() modifiers PIPE and SHM.
        (http://lists.mysql.com/commits/74749)
     @ mysql-test/lib/My/ConfigFactory.pm
        Add shared-memory-base-name to [mysqld] and [client] sections.
     @ mysql-test/t/named_pipe.test
        Force named pipe connection for named_pipe test.
     @ tests/mysql_client_test.c
        Make sure mysql_client_test understands and properly handles
        --shared-memory-base-name. All calls to mysql_init() are
        replaced with mysql_client_init() wrapper that will set shared
        memory base option, if it was specified.
[30 Sep 2009 12:31] Vladislav Vaintroub
last commit fixes some places with #if HAVE_SMEM to #ifdef HAVE_SMEM
[30 Sep 2009 12:41] 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/85204

2837 Vladislav Vaintroub	2009-09-30
      Bug #47423 mtr connects to wrong database
      
      The reason for the bug is that mysqtest as well as other client tools
      running in test suite (mysqlbinlog, mysqldump) will first try to connect 
      whatever database has created shared memory with default base name 
      "MySQL" and use this. (Same effect could be seen on Unix if mtr would
      not care to calculate "port" and "socket" parameter).
      
      The fix ensures that all client tools and  running in mtr use unique  
      per-database shared memory base parameters, so there is no possibility
      to clash with already installed one. We use socket name for shared memory 
      base (it's known to be unique). This shared-memory-base is written to the
      MTR config file to the [client] and [mysqld] sections. Fix made also made 
      sure all client tools understand and correctly handle --shared-memory-base.
      Prior to this patch  it was not the case for  mysqltest, mysqlbinlog and 
      mysql_client_test.
      
      All new connections done from mtr scripts via connect() will by default 
      set shared-memory-base. And finally, there is a possibility to force 
      shared memory or pipe connection and overwrite shared memory/pipe base name
      from within mtr scripts via optional PIPE or SHM modifier. This functionality
      was manually backported from 6.0
      (original patch  http://lists.mysql.com/commits/74749)
[30 Sep 2009 12:45] Bjørn Munch
I'm OK with this now.
[3 Nov 2009 0:06] 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/89015

3157 Vladislav Vaintroub	2009-11-03
      Bug #47423 mtr connects to wrong database
            
      The reason for the bug is that mysqtest as well as other client tools
       running in test suite (mysqlbinlog, mysqldump) will first try to connect 
       whatever database has created shared memory with default base name 
      "MySQL" and use this. (Same effect could be seen on Unix if mtr would
      not care to calculate "port" and "socket" parameter).
            
      The fix ensures that all client tools and  running in mtr use unique  
      per-database shared memory base parameters, so there is no possibility
      to clash with already installed one. We use socket name for shared memory 
      base (it's known to be unique). This shared-memory-base is written to the
      MTR config file to the [client] and [mysqld] sections. Fix made also made 
      sure all client tools understand and correctly handle --shared-memory-base.
      Prior to this patch  it was not the case for  mysqltest, mysqlbinlog and 
      mysql_client_test.
            
      All new connections done from mtr scripts via connect() will by default 
      set shared-memory-base. And finally, there is a possibility to force 
      shared memory or pipe connection and overwrite shared memory/pipe base name
      from within mtr scripts via optional PIPE or SHM modifier. This functionality
      was manually backported from 6.0
       (original patch  http://lists.mysql.com/commits/74749)
[4 Nov 2009 9:24] Bugs System
Pushed into 5.1.41 (revid:joro@sun.com-20091104092152-qz96bzlf2o1japwc) (version source revid:kristofer.pettersson@sun.com-20091103162305-08l4gkeuif2ozsoj) (merge vers: 5.1.41) (pib:13)
[5 Nov 2009 2:05] Paul DuBois
Test suite change. No changelog entry needed.

Setting report to NDI pending push to 5.5.x+.
[11 Nov 2009 6:54] Bugs System
Pushed into 6.0.14-alpha (revid:alik@sun.com-20091110093407-rw5g8dys2baqkt67) (version source revid:alik@sun.com-20091109080109-7dxapd5y5pxlu08w) (merge vers: 6.0.14-alpha) (pib:13)
[11 Nov 2009 6:58] Bugs System
Pushed into 5.5.0-beta (revid:alik@sun.com-20091109115615-nuohp02h8mdrz8m2) (version source revid:alik@sun.com-20091105091401-4fwfzjh1rldc6esy) (merge vers: 5.5.0-beta) (pib:13)
[11 Nov 2009 14:54] Paul DuBois
Changes to test suite. No changelog entry needed.
[18 Dec 2009 10:38] Bugs System
Pushed into 5.1.41-ndb-7.1.0 (revid:jonas@mysql.com-20091218102229-64tk47xonu3dv6r6) (version source revid:jonas@mysql.com-20091218095730-26gwjidfsdw45dto) (merge vers: 5.1.41-ndb-7.1.0) (pib:15)
[18 Dec 2009 10:54] Bugs System
Pushed into 5.1.41-ndb-6.2.19 (revid:jonas@mysql.com-20091218100224-vtzr0fahhsuhjsmt) (version source revid:jonas@mysql.com-20091217101452-qwzyaig50w74xmye) (merge vers: 5.1.41-ndb-6.2.19) (pib:15)
[18 Dec 2009 11:08] Bugs System
Pushed into 5.1.41-ndb-6.3.31 (revid:jonas@mysql.com-20091218100616-75d9tek96o6ob6k0) (version source revid:jonas@mysql.com-20091217154335-290no45qdins5bwo) (merge vers: 5.1.41-ndb-6.3.31) (pib:15)
[18 Dec 2009 11:22] Bugs System
Pushed into 5.1.41-ndb-7.0.11 (revid:jonas@mysql.com-20091218101303-ga32mrnr15jsa606) (version source revid:jonas@mysql.com-20091218064304-ezreonykd9f4kelk) (merge vers: 5.1.41-ndb-7.0.11) (pib:15)