You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@zookeeper.apache.org by Lahiru Gunathilake <gl...@gmail.com> on 2014/06/20 15:42:24 UTC
Time issue in zookeeper client
Hi All,
I am using zookeeper to register cluster nodes. In my system the default
scenario we have multiple thrift services(different services and default
mode 1 thrift service for each in a single jvm ) registering them selves
(default try out mode), In that case one service makes parent nodes others
just checks the existence of parent and in-case it doesn't exist they will
make the parent nodes and register with the ephemaral node.
When I start my jvm I see the last thrift service always consistently fail
and when I add a thread sleep it worked. When I start the last service in a
separate jvm it works. Is there anything I am doing wrong.
Code looks as below for failing service. Other services does the same.
zk = new ZooKeeper(zkhostPort, 6000, this); // no watcher is required,
this will only use to store some data
String gfacServer =
ServerSettings.getSetting(Constants.ZOOKEEPER_GFAC_SERVER_NODE);
Thread.sleep(1000); // this fixed my issue but not sure why
its failing
Stat zkStat = zk.exists(gfacServer, false);
if (zkStat == null) {
zk.create(gfacServer, new byte[0],
ZooDefs.Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
}
String instantNode = gfacServer + File.separator +
String.valueOf(new Random().nextInt(Integer.MAX_VALUE));
zkStat = zk.exists(instantNode, false);
if (zkStat == null) {
zk.create(instantNode,
airavataServerHostPort.getBytes(),
ZooDefs.Ids.OPEN_ACL_UNSAFE,
CreateMode.EPHEMERAL); // other component
will watch these childeren creation deletion to monitor the status of the
node
}
Am I doing anything wrong ?
Regards
Lahiru
--
System Analyst Programmer
PTI Lab
Indiana University
Re: Time issue in zookeeper client
Posted by Lahiru Gunathilake <gl...@gmail.com>.
Hi Jordan,
I am going to use Curator to select the leader when I implement my workers.
At this point I am just registering my workers and any worker can register
without a leader when they start them. I understood what are you saying, so
at this point I will listen to SyncConnected event and then proceed.
Thanks a lot for the response.
Regards
Lahiru
On Fri, Jun 20, 2014 at 9:52 AM, Jordan Zimmerman <
jordan@jordanzimmerman.com> wrote:
> When you allocate a ZooKeeper instance, you must wait for
> the SyncConnected event. If you try to create a node before you receive
> this event you’ll get a connection error. It’s because of this (and many
> other reasons) that I wrote Curator. If you’re using ZooKeeper in the JVM I
> encourage you to use Apache Curator: http://curator.apache.org
>
> -Jordan
>
>
> From: Lahiru Gunathilake glahiru@gmail.com
> Reply: user@zookeeper.apache.org user@zookeeper.apache.org
> Date: June 20, 2014 at 8:42:54 AM
> To: user@zookeeper.apache.org user@zookeeper.apache.org
> Subject: Time issue in zookeeper client
>
> Hi All,
>
> I am using zookeeper to register cluster nodes. In my system the default
> scenario we have multiple thrift services(different services and default
> mode 1 thrift service for each in a single jvm ) registering them selves
> (default try out mode), In that case one service makes parent nodes others
> just checks the existence of parent and in-case it doesn't exist they will
> make the parent nodes and register with the ephemaral node.
>
> When I start my jvm I see the last thrift service always consistently fail
> and when I add a thread sleep it worked. When I start the last service in
> a
> separate jvm it works. Is there anything I am doing wrong.
>
> Code looks as below for failing service. Other services does the same.
>
> zk = new ZooKeeper(zkhostPort, 6000, this); // no watcher is required,
> this will only use to store some data
> String gfacServer =
> ServerSettings.getSetting(Constants.ZOOKEEPER_GFAC_SERVER_NODE);
> Thread.sleep(1000); // this fixed my issue but not sure why
> its failing
> Stat zkStat = zk.exists(gfacServer, false);
> if (zkStat == null) {
> zk.create(gfacServer, new byte[0],
> ZooDefs.Ids.OPEN_ACL_UNSAFE,
> CreateMode.PERSISTENT);
> }
> String instantNode = gfacServer + File.separator +
> String.valueOf(new Random().nextInt(Integer.MAX_VALUE));
> zkStat = zk.exists(instantNode, false);
> if (zkStat == null) {
> zk.create(instantNode,
> airavataServerHostPort.getBytes(),
> ZooDefs.Ids.OPEN_ACL_UNSAFE,
> CreateMode.EPHEMERAL); // other component
> will watch these childeren creation deletion to monitor the status of the
> node
> }
>
> Am I doing anything wrong ?
>
> Regards
> Lahiru
> --
> System Analyst Programmer
> PTI Lab
> Indiana University
>
>
--
System Analyst Programmer
PTI Lab
Indiana University
Re: Time issue in zookeeper client
Posted by Jordan Zimmerman <jo...@jordanzimmerman.com>.
When you allocate a ZooKeeper instance, you must wait for the SyncConnected event. If you try to create a node before you receive this event you’ll get a connection error. It’s because of this (and many other reasons) that I wrote Curator. If you’re using ZooKeeper in the JVM I encourage you to use Apache Curator: http://curator.apache.org
-Jordan
From: Lahiru Gunathilake glahiru@gmail.com
Reply: user@zookeeper.apache.org user@zookeeper.apache.org
Date: June 20, 2014 at 8:42:54 AM
To: user@zookeeper.apache.org user@zookeeper.apache.org
Subject: Time issue in zookeeper client
Hi All,
I am using zookeeper to register cluster nodes. In my system the default
scenario we have multiple thrift services(different services and default
mode 1 thrift service for each in a single jvm ) registering them selves
(default try out mode), In that case one service makes parent nodes others
just checks the existence of parent and in-case it doesn't exist they will
make the parent nodes and register with the ephemaral node.
When I start my jvm I see the last thrift service always consistently fail
and when I add a thread sleep it worked. When I start the last service in a
separate jvm it works. Is there anything I am doing wrong.
Code looks as below for failing service. Other services does the same.
zk = new ZooKeeper(zkhostPort, 6000, this); // no watcher is required,
this will only use to store some data
String gfacServer =
ServerSettings.getSetting(Constants.ZOOKEEPER_GFAC_SERVER_NODE);
Thread.sleep(1000); // this fixed my issue but not sure why
its failing
Stat zkStat = zk.exists(gfacServer, false);
if (zkStat == null) {
zk.create(gfacServer, new byte[0],
ZooDefs.Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
}
String instantNode = gfacServer + File.separator +
String.valueOf(new Random().nextInt(Integer.MAX_VALUE));
zkStat = zk.exists(instantNode, false);
if (zkStat == null) {
zk.create(instantNode,
airavataServerHostPort.getBytes(),
ZooDefs.Ids.OPEN_ACL_UNSAFE,
CreateMode.EPHEMERAL); // other component
will watch these childeren creation deletion to monitor the status of the
node
}
Am I doing anything wrong ?
Regards
Lahiru
--
System Analyst Programmer
PTI Lab
Indiana University