Bug #30552 ndbapi_scan.cpp example contains endless recursion
Submitted: 22 Aug 2007 3:31 Modified: 13 Apr 2010 22:32
Reporter: John David Duncan Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Cluster: NDB API Severity:S3 (Non-critical)
Version:mysql-5.1 OS:Any
Assigned to: John David Duncan CPU Architecture:Any
Tags: 5.1.20

[22 Aug 2007 3:31] John David Duncan
Description:
If the GARAGE table already exists when the example program is run, it will loop endlessly in mysql_query(CREATE TABLE ...) creating and then dropping the table.

How to repeat:
cd storage/ndb/ndbapi_examples 
make 
install ndbapi_scan/ndbapi_scan  ~/bin/ 

ndbapi_scan /tmp/mysql.sock mgmhost
ndbapi_scan /tmp/mysql.sock mgmhost

Suggested fix:
*** ndbapi_scan.cpp~    Tue Aug 21 20:19:53 2007
--- ndbapi_scan.cpp     Tue Aug 21 20:21:13 2007
***************
*** 144,150 ****
       * Recreate table *
       ******************/
      drop_table(mysql);
-     create_table(mysql);
    }
  }
  
--- 144,149 ----
[22 Aug 2007 7:54] Hartmut Holzgraefe
the recursive call does indeed do harm there ...
[22 Aug 2007 10:22] Hartmut Holzgraefe
looking at it again it is rather bad code anyway,
e.g. what if the user is simply not allowed to 
create the table (permissions)? 

-> non-terminating loop again ... :(
[22 Aug 2007 11:09] Hartmut Holzgraefe
and looking at my last comment again
i should re-check code before commenting 
on it from memory, the loop tests for 
ER_TABLE_EXISTS_ERROR just fine ... and
drop_table() bails out on errors ...
which makes me wonder though: why process
it in a loop then? the only accepted failure
is that the table already exists, and once 
that is known one drop/create iteration is
sufficient ... 
plus we have DROP IF EXISTS ... as we do
it on all mysqltest test cases ... why not
use that approach here, too?
[22 Aug 2007 14:48] John David Duncan
Also, the example program simply doesn't work.  It is supposed to delete all the pink cars, and update all the black cars to blue, but this doesn't happen.  (I know this is a separate issue -- but I may try to figure it out over the next few days and submit a patch)
[30 Aug 2007 23:26] John David Duncan
I filed a separate bug report to report (and fix) the issue in my last comment.  bug#30737
[27 Feb 2008 5:59] 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/43033

ChangeSet@1.2660, 2008-02-27 13:59:03+08:00, gni@dev3-221.dev.cn.tlan +1 -0
  BUG#30552 ndbapi_scan.cpp example contains endless recrsion.
[10 Apr 2008 6:49] Guangbao Ni
pushed into mysql-5.1-new-ndb-bj
[31 May 2008 10:26] Jon Stephens
Gni,

Is this being pushed into telco trees also?

Thanks!
[2 Jun 2008 1:01] Guangbao Ni
Hi Jon,
 Not pushed into telco trees still now. But the trees have been changed into bzr, so I will ask Martin, or Stewart for help, then push them into telcos.

/Guangbao
[18 Nov 2009 12:53] Yves Trudeau
The patch is still not in 7.0.8a. In addition, I needed to add 2 header files to make it compile. The following patch make it works:

--- ndbapi_scan.cpp~      2009-03-18 06:10:02.000000000 -0400
+++ ndbapi_scan.cpp    2009-10-10 09:57:04.071126546 -0400
@@ -73,6 +73,10 @@
 #include <iostream>
 #include <stdio.h>

+
+#include <string.h>
+#include <stdlib.h>
+
 /**
  * Helper sleep function
  */
@@ -144,7 +148,7 @@
      * Recreate table *
      ******************/
     drop_table(mysql);
-    create_table(mysql);
+    
   }
 }

Also, the output is now correct, a year ago the problem reported by John David was present it seems to be gone.
[24 Feb 2010 17:42] 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/101359

3103 John David Duncan	2010-02-24
      Fix for bug#30552 and bug#30737 
      Use lowercase table names so that the example will run on Mac & Windows.
[5 Mar 2010 23: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/102483

3131 John David Duncan	2010-03-05 [merge]
      Fix for bug#30552 and bug#30737 plus cleanup of NDB API examples
[5 Mar 2010 23:07] Bugs System
Pushed into 5.1.41-ndb-6.3.33 (revid:jdd@sun.com-20100305230516-oxekqu0eov1i32ur) (version source revid:jdd@sun.com-20100305230516-oxekqu0eov1i32ur) (merge vers: 5.1.41-ndb-6.3.33) (pib:16)
[6 Mar 2010 0:26] 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/102485

3429 John David Duncan	2010-03-05
           Fix for bug#30552 and bug#30737 plus cleanup of NDB API examples
[9 Mar 2010 12:32] Bugs System
Pushed into 5.1.41-ndb-7.0.14 (revid:jonas@mysql.com-20100309122618-bqu4zub69rlky588) (version source revid:jonas@mysql.com-20100309122618-bqu4zub69rlky588) (merge vers: 5.1.41-ndb-7.0.14) (pib:16)
[12 Apr 2010 16:10] Jon Stephens
Updated status.
[13 Apr 2010 22:32] Jon Stephens
Documented together with BUG#30737 in the NDB-6.3.33, 7.0.14, and 7.1.3 changelogs, as follows:

        A number of issues were corrected in the NDB API coding examples
        found in storage/ndb/ndbapi-examples directory in the MySQL
        Cluster source tree. These included possible endless recursion
        in ndbapi_scan.cpp as well as problems running the examples on
        Windows or Macintosh systems due to the letter case used for
        some table names.

In addition, all of these examples in the documentation have been updated from the sources.

Note: I verified manually that this fix is included in NDB-7.1.3.

Closed.