List:Cluster« Previous MessageNext Message »
From:George Neill Date:January 24 2012 3:01pm
Subject:Re: ndb_init and ndb_end
View as plain text  
Jonas,

On Tue, Jan 24, 2012 at 12:22 AM, Jonas Oreland <jonas.oreland@stripped>wrote:

> On 01/23/12 22:07, George Neill wrote:
>
>>  <cluster@stripped>Hi Folks,
>>
>>
>> Still in learning mode with the NDB API.   I have a couple more questions
>> I
>> hope someone can help me out with!
>>
>> 1) It is my understanding that ndb_init() and ndb_end(int) should only be
>> called ONCE per process, is that correct?
>>
>> 2) I have a question about ndb_end(int) and it's proper usage.
>>
>> Here's my situation,
>>
>> I am compiling/testing the ndbrecord api example.  I noticed this
>> particular example allocates the Ndb_cluster_connection object from the
>> stack.  In this example, there exists a ndb_init() function call just
>> after
>> main(),but there's no corresponding ndb_end(int) call before exit.   I
>> have
>> added a ndb_end(0); right before the return 0; from main().
>>
>> Now when I run the example, I see this,
>>
>> fetch_key: Success!
>> update2_key: Success!
>> delete_key: Success!
>> Error in my_thread_global_end(): 5 threads didn't exit
>>
>> The "Error" line is what my question is about.   There appears to be an
>> stack unwinding issue as ndb_end(int) gets called before the
>> Ndb_cluster_connection destructor does.
>>
>> Is this the way it was intended to work, or is it a bug?
>>
>> For now I have just wrapped the ndb_init/ndb_end(int) calls in a class and
>> instantiated it in main() (removing the ndb_init/ndb_end calls in the
>> example).
>>
>> class ndbInitialize
>> {
>>   public:
>>   ndbInitialize() { ndb_init(); }
>>  ~ndbInitialize() { ndb_end(0); }
>> };
>>
>> I am interested if anyone else has ran in to this situation and how they
>> have solved it.
>>
>
> i "normally" just avoid putting Ndb_cluster_connection on the stack in
> main()
> and call ndb_init/ndb_end explicitly from main...having the
> cluster-connection
> allocated like that...feels like a example program construct...
>

Thanks for responding!

I believe calling ndb_init/end in this fashion when allocated off of the
stack will always be an issue. However, if you always declare from the heap
and delete the Ndb_cluster_connection object before you call ndb_end(int)
you'll probably be okay.  I guess that's why I am asking, it caught me
off-guard.  A handful of the examples allocate from the stack, but neglect
calling ndb_end(int).

>
> your solution is quite elegant...
>

Thanks. I am thinking It should work as long as the destructors are called
in the reverse order of which they were instantiated.  But it doesn't
address only being called once for the process (if infact it should only be
called once in the process).

Later,
George

Thread
ndb_init and ndb_endGeorge Neill23 Jan
  • Re: ndb_init and ndb_endJonas Oreland24 Jan
    • Re: ndb_init and ndb_endGeorge Neill24 Jan