| Bug #53577 | usage count for ndb_init()/ndb_end() count | ||
|---|---|---|---|
| Submitted: | 11 May 2010 17:09 | Modified: | 25 Jun 2010 14:27 |
| Reporter: | Hartmut Holzgraefe | Email Updates: | |
| Status: | Verified | Impact on me: | |
| Category: | MySQL Cluster: NDB API | Severity: | S4 (Feature request) |
| Version: | mysql-telco-7.0, any | OS: | Any |
| Assigned to: | CPU Architecture: | Any | |
[11 May 2010 19:23]
Jonas Oreland
is it worth it, given that the method is not even thread safe? why not simply do it in their application?
[25 Jun 2010 14:27]
Hartmut Holzgraefe
If not for anything else then at least for consistency between ndb_init() and ndb_end(). Having one doing a check while the other doesn't ... well ... This is also not only a multi-thread issue, it is also going to bite in single threaded applications where two independent, optional components make use of NDBAPI. Having proper reference counting on init/end invocations is a must there even without the calls being mutex protected.

Description: ndb_init() is protected against being called multiple times but ndb_end() isn't When having multiple independent components using NDBAPI they'll all initialize fine but the first one calling ndb_end() will spoil the show for all the rest. How to repeat: check source in storage/ndb/src/common/util/ndb_init.cpp Suggested fix: Change the flag that protects ndb_init() from being executed multiple times into a reference counter: === modified file 'storage/ndb/src/common/util/ndb_init.cpp' --- storage/ndb/src/common/util/ndb_init.cpp 2009-09-09 12:34:25 +0000 +++ storage/ndb/src/common/util/ndb_init.cpp 2010-05-11 17:03:30 +0000 @@ -72,7 +72,6 @@ { if (ndb_init_called == 0) { - ndb_init_called = 1; if (my_init()) { const char* err = "my_init() failed - exit\n"; @@ -81,6 +80,7 @@ } ndb_init_internal(); } + ndb_init_called++; return 0; } @@ -100,11 +100,13 @@ void ndb_end(int flags) { - if (ndb_init_called == 1) + if (ndb_init_called > 0) { - my_end(flags); - ndb_end_internal(); - ndb_init_called = 0; + if (--ndb_init_called == 0) { + my_end(flags); + ndb_end_internal(); + ndb_init_called = 0; + } } }