so you have two problems going on. both have the same root: zookeeper_init returns before a connection and session is established with zookeeper, so you will not be able to fill in myid until a connection is made. you can do something with a mutex in the watcher to wait for a connection, or you could do something simple like:

while(zoo_state(zh_1) != ZOO_CONNECTED_STATE) {
   sleep(1);
 }
 myid = *zoo_client_id(zh_1);

the second part of the problem is related. you need to make sure you are connected before you do the close.

ben

Leonard Cuff wrote:
In the FAQ, there is a question
4. Is there an easy way to expire a session for testing?

And the last part of the answer reads:
       In the case of testing we want to cause a problem, so to explicitly
        expire a session an application connects to ZooKeeper, saves the
        session id and password, creates another ZooKeeper handle with that
        id and password, and then closes the new handle. Since both handles
        reference the same session, the close on second handle will
invalidate the session causing a SESSION_EXPIRED on the first handle.


(I assume when it says ³creates another ZooKeeper handle² I¹m assuming it
means do that by calling init_zookeeper. Is that correct?


Here¹s my skeleton code, which doesn¹t work. ...


clientid_t   myid;
clientid_t   another_id;
zhandle_t    zh_1;
zhandle_t    zh_2;
zoo_deterministic_conn_order(1);
zh_1 = zookeeper_init ( servers, watcher, 10000, &myid, 0, 0);
if ( !zh_1 ) { ...error...
}
// Catch sigusr1 and set the havoc flag
if ( cry_havoc_and_let_loose_the_dogs_of_war ) {
        memcpy ( &another_id, &myid, sizeof (clientid_t));
        zh_2 = zookeeper_init ( servers, destroy_watcher, 10000,
&another_id, 0, 0);
            if ( ! zh_2 ) {
                .... errror ...
} if ( !nzh ) {
                ... error ...
} zookeeper_close ( zh_2); // Shouldn't I get a session expire
shortly after this?
}

But I don¹t get a session expire.  Can someone tell me what I¹m doing wrong?

TIA,

Leonard

Leonard Cuff
lc...@valueclick.com

³This email and any files included with it may contain privileged,
proprietary and/or confidential information that is for the sole use of the
intended recipient(s).  Any disclosure, copying, distribution, posting, or
use of the information contained in or attached to this email is prohibited
unless permitted by the sender.  If you have received this email in error,
please immediately notify the sender via return e-mail, telephone, or fax
and destroy this original transmission and its included files without
reading or saving it in any manner. Thank you.²






This email and any files included with it may contain privileged,
proprietary and/or confidential information that is for the sole use
of the intended recipient(s).  Any disclosure, copying, distribution,
posting, or use of the information contained in or attached to this
email is prohibited unless permitted by the sender.  If you have
received this email in error, please immediately notify the sender
via return email, telephone, or fax and destroy this original transmission
and its included files without reading or saving it in any manner.
Thank you.

Reply via email to