zookeeper-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lahiru Gunathilake <glah...@gmail.com>
Subject Re: ZK session expiration and recovery
Date Wed, 23 Jul 2014 18:54:11 GMT
Hi Ahmed,

Yes you can, when you create a zk object register a watch and listen to
expire event and connect back. Following code might be useful, but I
haven't tried this but I have listened to syncConnected event it worked
fine.

zk = new ZooKeeper(zkhostPort, 6000, this);

synchronized public void process(WatchedEvent watchedEvent) {
synchronized (mutex) {
Event.KeeperState state = watchedEvent.getState();
switch (state) {
case Expired:
// do reconnect the zk
break;
}
}
}

In this case if it expires this will get triggered and reconnect. But when
you reconnect remember to handle the SyncConnected too.

Lahiru


On Wed, Jul 23, 2014 at 2:44 PM, Ahmed H. <ahmed.hammad@gmail.com> wrote:

> Is there another approach? Not sure adding more components is an option for
> me right now, but it could be in the future. I looked into it briefly, and
> it seems like it might work.
>
> Is there a way for a Zookeeper client to get notified when the connection
> drops or when the session expires?
>
>
> On Fri, Jul 18, 2014 at 11:07 AM, Jordan Zimmerman <
> jordan@jordanzimmerman.com> wrote:
>
> > You might consider using Curator (http://curator.apache.org). One of
> it’s
> > main features is ZooKeeper connection management.
> >
> > -JZ
> >
> >
> > On July 18, 2014 at 9:59:56 AM, Ahmed H. (ahmed.hammad@gmail.com) wrote:
> >
> > Hello,
> >
> >
> > I am having some issues where the Zookeeper connection loss occurs. This
> > affects various things in my application, namely watchers, which result
> in
> > errors like the one below:
> >
> > 23:13:01,593 ERROR [org.apache.zookeeper.ClientCnxn]
> > (pool-5-thread-1-EventThread) Error while calling watcher :
> > org.apache.zookeeper.KeeperException$SessionExpiredException:
> > KeeperErrorCode = Session expired for /controller/resync
> > at org.apache.zookeeper.KeeperException.create(KeeperException.java:118)
> > [zookeeper-3.3.4.jar:3.3.3-1203054]
> > at org.apache.zookeeper.KeeperException.create(KeeperException.java:42)
> > [zookeeper-3.3.4.jar:3.3.3-1203054]
> > at org.apache.zookeeper.ZooKeeper.getChildren(ZooKeeper.java:1249)
> > [zookeeper-3.3.4.jar:3.3.3-1203054]
> > at sun.reflect.GeneratedMethodAccessor56.invoke(Unknown Source)
> > [:1.7.0_51]
> > at
> >
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> >
> > [rt.jar:1.7.0_51]
> > at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_51]
> > at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:93)
> > [clojure-1.5.1.jar:]
> > at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:28)
> > [clojure-1.5.1.jar:]
> > at zookeeper$children.doInvoke(zookeeper.clj:230) at
> > clojure.lang.RestFn.invoke(RestFn.java:464) [clojure-1.5.1.jar:]
> > at resync$resync_group_watcher.invoke(resync.clj:26)
> > at zookeeper.internal$make_watcher$reify__10446.process(internal.clj:56)
> > at
> >
> org.apache.zookeeper.ClientCnxn$EventThread.processEvent(ClientCnxn.java:531)
> >
> > [zookeeper-3.3.4.jar:3.3.3-1203054]
> > at org.apache.zookeeper.ClientCnxn$EventThread.run(ClientCnxn.java:507)
> > [zookeeper-3.3.4.jar:3.3.3-1203054]
> >
> >
> > I guess I have a few questions that might help me mitigate this issue. I
> > could try to fix whatever is causing the session expiration. This issue
> > occurs when we have a lot of activity on the machine, which leads me to
> > believe that it might be caused by GC activity (based on the ZK guide).
> > This might work, but it seems to me like we would just be masking the
> > issue
> > and eventually, it might happen again.
> >
> >
> > The other issue is that our client never recovers. It's completely dead.
> > Is
> > there a way to make it auto reconnect after it dies? Does Zookeeper
> > support
> > such functionality?
> >
> >
> > Are there any other things I should be aware of or any recommendations
> you
> > have for setting up a Zookeeper environment? For the record, we are
> > running
> > version 3.4.5 in a single node setup.
> >
> > Thanks
> >
> >
>



-- 
System Analyst Programmer
PTI Lab
Indiana University

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message