curator-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Olli Miettinen <oll...@gmail.com>
Subject How to recover if ZK is unavailable at Curator start up?
Date Wed, 14 May 2014 08:10:55 GMT
Hello,

I'm using Curator Discovery Service to register my application's host IP
address to Zookeeper.
(Curator 2.4.2 and Zookeeper 3.4.5)

If Zookeeper cluster is unavailable to my application at start-up, an
exception is thrown from ServiceDiscovery.registerService() after retries
are finished.

I need my app to retry until it successfully registers to Discovery Service
so can't use the RetryPolicy as it seems to have a limited max number of
retries.

Should I maybe observe the ZK connection state and register to Discover
Service only after successfully connected?
Or catch the exception and implement my own retry of registering when
RetryPolicy runs out of retries?
Other suggestions?

This is my code:

CuratorFramework client = ...
ServiceDiscovery<InstanceDetails> serviceDiscovery =  ...
ServiceInstance<InstanceDetails> serviceInstance = ...

public void start() throws Exception {
    client.start();
    serviceDiscovery.start();
    serviceDiscovery.registerService(serviceInstance);
    // ...
}

Here's the exception I get at serviceDiscovery.registerService()

2014-05-13 16:04:25,315 [main] DEBUG org.apache.curator.RetryLoop : Retry
policy not allowing retry
Exception in thread "main"
org.apache.zookeeper.KeeperException$ConnectionLossException:
KeeperErrorCode = ConnectionLoss for /discovery/myapp/10.36.101.36
    at org.apache.zookeeper.KeeperException.create(KeeperException.java:99)
    at org.apache.zookeeper.KeeperException.create(KeeperException.java:51)
    at org.apache.zookeeper.ZooKeeper.create(ZooKeeper.java:783)
    at
org.apache.curator.framework.imps.CreateBuilderImpl$11.call(CreateBuilderImpl.java:676)
    at
org.apache.curator.framework.imps.CreateBuilderImpl$11.call(CreateBuilderImpl.java:660)
    at org.apache.curator.RetryLoop.callWithRetry(RetryLoop.java:107)
    at
org.apache.curator.framework.imps.CreateBuilderImpl.pathInForeground(CreateBuilderImpl.java:657)
    at
org.apache.curator.framework.imps.CreateBuilderImpl.protectedPathInForeground(CreateBuilderImpl.java:441)
    at
org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:431)
    at
org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:44)
    at
org.apache.curator.x.discovery.details.ServiceDiscoveryImpl.internalRegisterService(ServiceDiscoveryImpl.java:176)
    at
org.apache.curator.x.discovery.details.ServiceDiscoveryImpl.registerService(ServiceDiscoveryImpl.java:150)
    at
com.mycompany.zookeeper.discovery.MyDiscoveryClient.start(MyDiscoveryClient.java:51)

Thanks for any advice,
Olli

Mime
View raw message