Bug #13512 ndb_restore dumps core if there are no free mysqld
Submitted: 27 Sep 2005 1:54 Modified: 6 Oct 2005 1:26
Reporter: Mark Kirkwood Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Cluster: Cluster (NDB) storage engine Severity:S2 (Serious)
Version:5.0.12 OS:FreeBSD (FreeBSD 5.4 and 6.0)
Assigned to: Jonas Oreland CPU Architecture:Any

[27 Sep 2005 1:54] Mark Kirkwood
Description:
If a restore is attempted but there are no free [mysqld] then the restore bails with:

$ ndb_restore -r -m -n 2 -b 1 /data0/dump/BACKUP-1-SMAL/
Ndb version in backup files: Version 5.0.12
Configuration error: Could not alloc node id at localhost port 1186: No free node id found for mysqld(API).
Segmentation fault: 11 (core dumped)

tracing using gdb reveals:

$ gdb ndb_restore ndb_restore.core 
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-marcel-freebsd"...
Core was generated by `ndb_restore'.
Program terminated with signal 11, Segmentation fault.
Reading symbols from /lib/libcrypt.so.3...done.
Loaded symbols for /lib/libcrypt.so.3
Reading symbols from /usr/lib/libpthread.so.2...done.
Loaded symbols for /usr/lib/libpthread.so.2
Reading symbols from /usr/lib/libstdc++.so.5...done.
Loaded symbols for /usr/lib/libstdc++.so.5
Reading symbols from /lib/libm.so.4...done.
Loaded symbols for /lib/libm.so.4
Reading symbols from /lib/libc.so.6...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /libexec/ld-elf.so.1...done.
Loaded symbols for /libexec/ld-elf.so.1
#0  0x08053843 in Ndb::setCatalogName (this=0x0, 
    a_catalog_name=0x80f5e20 "benchw") at Ndb.cpp:1061
1061        theImpl->m_dbname.assign(a_catalog_name);
[New LWP 100226]
(gdb) bt
#0  0x08053843 in Ndb::setCatalogName (this=0x0, 
    a_catalog_name=0x80f5e20 "benchw") at Ndb.cpp:1061
#1  0x080538a2 in Ndb::setDatabaseName (this=0x0, 
    a_catalog_name=0x80f5e20 "benchw") at Ndb.cpp:1091
#2  0x0804ddef in BackupRestore::table (this=0x80f4a80, table=@0x8113280)
    at BaseString.hpp:193
#3  0x0804c5ef in main (argc=0, argv=0x80fc234) at Restore.hpp:292
(gdb) 

How to repeat:

Config 
----------
$ cat /data0/mymgmt/5.0/config.ini
[ndbd default]
noofreplicas=1
datamemory=256M
indexmemory=64M
maxnoofconcurrentoperations=120000
maxnooflocaloperations=120000
maxnooforderedindexes=512

[ndb_mgmd default]
datadir=/data0/mymgmt/5.0

[ndb_mgmd]
id=1
hostname=localhost

[ndbd]
id=2
hostname=localhost
datadir=/data0/myndb/5.0

# Note only 1 mysqld is defined.
# If you have more, then to elicit the bug you must start *all* of them
# before trying to restore!
#
[mysqld]
id=4
hostname=localhost

[tcp default]
portnumber=2202 

Wipe out the cluster:
--------------------------------

$ ndb_mgm -e shutdown
$ mysqladmin -u root shutdown
$ cd /data0/myndb/5.0; rm -rf *

Then startup and attempt restore (I am assuming you have a vaild backup!):
---------------------------------

$ /usr/local/mysql/5.0/libexec/ndb_mgmd -f /data0/mymgmt/5.0/config.ini
$ /usr/local/mysql/5.0/libexec/ndbd
$ mysqld_safe --defaults-file=/data0/myclust/5.0/my.cnf --datadir=/data0/myclust/5..0 &
$ ndb_restore -r -m -n 2 -b 1 /data0/dump/BACKUP-1-SMAL/
Ndb version in backup files: Version 5.0.12
Configuration error: Could not alloc node id at localhost port 1186: No free node id found for mysqld(API).
Segmentation fault: 11 (core dumped)

Suggested fix:
Have not looked at the code yet (will later today).
[28 Sep 2005 7:23] Mark Kirkwood
I think that the proble might be this:

*** ndb/tools/restore/consumer_restore.cpp.orig Wed Sep 28 19:20:13 2005
--- ndb/tools/restore/consumer_restore.cpp      Wed Sep 28 19:20:50 2005
***************
*** 35,41 ****
    m_cluster_connection = new Ndb_cluster_connection(g_connect_string);
    if(m_cluster_connection->connect(12, 5, 1) != 0)
    {
!     return -1;
    }

    m_ndb = new Ndb(m_cluster_connection);
--- 35,41 ----
    m_cluster_connection = new Ndb_cluster_connection(g_connect_string);
    if(m_cluster_connection->connect(12, 5, 1) != 0)
    {
!     return false;
    }

    m_ndb = new Ndb(m_cluster_connection);
[28 Sep 2005 9:56] 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/internals/30428
[28 Sep 2005 12:40] Jonas Oreland
pushed into 5.0.14
Thanks for excellent bug report with patch!
[6 Oct 2005 1:26] Paul Dubois
Noted in 5.0.14 changelog.