Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
Zookeeper, mail # user - session expiry


Copy link to this message
-
Re: session expiry
lei liu 2011-06-23, 05:54
Hi Mahadev, thank you very much.

yes, you are right, I just have one server.

I am new to zookeeper.

I think  my application should pay attention to below tow points when
session expire:

1. when  session expire, the ephemeral znode will be deleted.
2. when  session expire, the application should recreate ZooKeeper object.

Are there any other omissive thing about session expiry?

In addition to, could you tell me some articles aobut session expiry?

Thanks,

LiuLei
在 2011年6月23日 上午12:22,Mahadev Konar <[EMAIL PROTECTED]>写道:

> Liu,
>  Looks like you have just one server. The client does not expire the
> session unless its able to talk to a server. Also, please take a look
> at some examples/tests on better understanding of event handling and
> session expiry for ZK.
>
>
> 2011/6/22 lei liu <[EMAIL PROTECTED]>:
> > I create "group" znode, and add "A","B","C" three children to the znode.
> I
> > want to print all children of "group" znode periodically,example below
> code:
> > public class ListGroup extends ConnectionWatcher {
> >
> >    private static Random random = new Random();
> >
> >    public void register(Watcher watcher) {
> >        zk.register(watcher);
> >    }
> >
> >    public void nodify(String groupName) throws KeeperException,
> > InterruptedException {
> >        String path = "/" + groupName;
> >        List<String> children = zk.getChildren(path, true);
> >    }
> >
> >    public void list(String groupName) throws KeeperException,
> >            InterruptedException {
> >        String path = "/" + groupName;
> >        try {
> >            Stat stat = new Stat();
> >
> >            List<String> children = zk.getChildren(path, true);
> >            if (children.isEmpty()) {
> >                System.out.printf("No members in group %s\n", groupName);
> >
> >            }
> >            for (String child : children) {
> >                System.out.println(child);
> >            }
> >        } catch (KeeperException.NoNodeException e) {
> >            System.out.printf("Group %s does not exist\n", groupName);
> >            //System.exit(1);
> >        }
> >    }
> >
> >    public static void main(String[] args) throws Exception {
> >        ListGroup listGroup = new ListGroup();
> >        String connectString = "localhost:2181";
> >        listGroup.connect(connectString);
> >        listGroup.list("test");
> >        while(true) {
> >            try {
> >            listGroup.list("test");
> >            } catch(Exception e) {
> >                e.printStackTrace();
> >            }
> >            TimeUnit.SECONDS.sleep(random.nextInt(10));
> >        }
> >        //listGroup.close();
> >    }
> > }
> >
> > I run the ListGroup class then It output :"A B C" information, and then I
> > close the zookeeper server, the ListGroup class output below exception:
> > org.apache.zookeeper.KeeperException$ConnectionLossException:
> > KeeperErrorCode = ConnectionLoss for /test
> >    at
> org.apache.zookeeper.KeeperException.create(KeeperException.java:90)
> >    at
> org.apache.zookeeper.KeeperException.create(KeeperException.java:42)
> >    at org.apache.zookeeper.ZooKeeper.getChildren(ZooKeeper.java:1243)
> >    at org.apache.zookeeper.ZooKeeper.getChildren(ZooKeeper.java:1271)
> >    at hadoop.definitive.guide.ListGroup.list(ListGroup.java:30)
> >    at hadoop.definitive.guide.ListGroup.main(ListGroup.java:51)
> >
> > when I restart the zookeeper server, the ListGroup class continue to
> output
> > "A B C" information.
> >
> > I think the session is expiry before I restart the zookeeper server, I
> have
> > two questions:
> > 1.  Why ListGroup class don't throw the SessionExpiredException.
> > 2.  I think client can automatically reconnect to server , after  the
> > reconnection is successfull, the session whether is still valid?
> >
> > thanks,
> >
> >
> > LiuLei
> >
>
>
>
> --
> thanks
> mahadev
> @mahadevkonar
>