You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@zookeeper.apache.org by Daniel Kashtan <dj...@gmail.com> on 2015/08/28 23:47:34 UTC

How to catch NodeExistsException

I have this code using Curator:

try
{
   client.create().forPath(path);
}
catch (KeeperException.NodeExistsException ex)
{
   LOG.debug("caught NodeExistsException");
}

The trouble is that it is never caught and zookeeper pollutes my production
logs with what are probably harmless exceptions. I assume that my code
executes just fine but later on the ZooKeeper server throws the exception
as it does work in the background. Is there a way to gracefully catch those
exceptions so they don't pile up in my production logs?

I have tried in the past to fix my code so these exceptions are never
thrown, but I have not found much in the documentation or on google on how
to deal with these exceptions. Is it a known problem? I would love to solve
these issues too if possible.

-- 
-Daniel

Re: How to catch NodeExistsException

Posted by Jordan Zimmerman <jo...@jordanzimmerman.com>.
creatingParentsIfNeeded() protects a common pattern where you have, say, a lock recipe and the base path is “/a/nested/path”. creatingParentsIfNeeded() will create the parent paths without worrying about exceptions.

Also, which recipes would be relevant to my current 
problem? 
Please give more details on your problem.

-JZ

On August 30, 2015 at 7:45:13 PM, Daniel Kashtan (djkashtan@gmail.com) wrote:

Is creatingParentsIfNeeded() a valid way to protect against  
NodeExistExceptions? Also, which recipes would be relevant to my current  
problem?  

On Fri, Aug 28, 2015 at 10:23 PM, Jordan Zimmerman <  
jordan@jordanzimmerman.com> wrote:  

> FYI - Curator has its own mailing list at user@curator.apache.org  
>  
> For Curator, I suggest you use this form:  
>  
> client.create().creatingParentsIfNeeded().forPath(path).  
>  
> You shouldn’t ever need to catch the node exists exception in this case.  
> But, of course, it depends on your use case. Also, have a look at how  
> Curator implements various recipes for examples.  
>  
> -Jordan  
>  
>  
>  
> On August 28, 2015 at 4:47:41 PM, Daniel Kashtan (djkashtan@gmail.com)  
> wrote:  
>  
> I have this code using Curator:  
>  
> try  
> {  
> client.create().forPath(path);  
> }  
> catch (KeeperException.NodeExistsException ex)  
> {  
> LOG.debug("caught NodeExistsException");  
> }  
>  
> The trouble is that it is never caught and zookeeper pollutes my  
> production  
> logs with what are probably harmless exceptions. I assume that my code  
> executes just fine but later on the ZooKeeper server throws the exception  
> as it does work in the background. Is there a way to gracefully catch  
> those  
> exceptions so they don't pile up in my production logs?  
>  
> I have tried in the past to fix my code so these exceptions are never  
> thrown, but I have not found much in the documentation or on google on how  
> to deal with these exceptions. Is it a known problem? I would love to  
> solve  
> these issues too if possible.  
>  
> --  
> -Daniel  
>  
>  


--  
-Daniel  

Re: How to catch NodeExistsException

Posted by Daniel Kashtan <dj...@gmail.com>.
Is creatingParentsIfNeeded() a valid way to protect against
NodeExistExceptions? Also, which recipes would be relevant to my current
problem?

On Fri, Aug 28, 2015 at 10:23 PM, Jordan Zimmerman <
jordan@jordanzimmerman.com> wrote:

> FYI - Curator has its own mailing list at user@curator.apache.org
>
> For Curator, I suggest you use this form:
>
> client.create().creatingParentsIfNeeded().forPath(path).
>
> You shouldn’t ever need to catch the node exists exception in this case.
> But, of course, it depends on your use case. Also, have a look at how
> Curator implements various recipes for examples.
>
> -Jordan
>
>
>
> On August 28, 2015 at 4:47:41 PM, Daniel Kashtan (djkashtan@gmail.com)
> wrote:
>
> I have this code using Curator:
>
> try
> {
> client.create().forPath(path);
> }
> catch (KeeperException.NodeExistsException ex)
> {
> LOG.debug("caught NodeExistsException");
> }
>
> The trouble is that it is never caught and zookeeper pollutes my
> production
> logs with what are probably harmless exceptions. I assume that my code
> executes just fine but later on the ZooKeeper server throws the exception
> as it does work in the background. Is there a way to gracefully catch
> those
> exceptions so they don't pile up in my production logs?
>
> I have tried in the past to fix my code so these exceptions are never
> thrown, but I have not found much in the documentation or on google on how
> to deal with these exceptions. Is it a known problem? I would love to
> solve
> these issues too if possible.
>
> --
> -Daniel
>
>


-- 
-Daniel

Re: How to catch NodeExistsException

Posted by Jordan Zimmerman <jo...@jordanzimmerman.com>.
FYI - Curator has its own mailing list at user@curator.apache.org

For Curator, I suggest you use this form:

client.create().creatingParentsIfNeeded().forPath(path). 

You shouldn’t ever need to catch the node exists exception in this case. But, of course, it depends on your use case. Also, have a look at how Curator implements various recipes for examples.

-Jordan



On August 28, 2015 at 4:47:41 PM, Daniel Kashtan (djkashtan@gmail.com) wrote:

I have this code using Curator:  

try  
{  
client.create().forPath(path);  
}  
catch (KeeperException.NodeExistsException ex)  
{  
LOG.debug("caught NodeExistsException");  
}  

The trouble is that it is never caught and zookeeper pollutes my production  
logs with what are probably harmless exceptions. I assume that my code  
executes just fine but later on the ZooKeeper server throws the exception  
as it does work in the background. Is there a way to gracefully catch those  
exceptions so they don't pile up in my production logs?  

I have tried in the past to fix my code so these exceptions are never  
thrown, but I have not found much in the documentation or on google on how  
to deal with these exceptions. Is it a known problem? I would love to solve  
these issues too if possible.  

--  
-Daniel  

Re: How to catch NodeExistsException

Posted by Martin Serrano <ma...@attivio.com>.
I find this annoying too.  At one point my company was running a custom
zookeeper build that turned those messages to DEBUG on the server.  We
did not want to change the logging level because we found the other INFO
messages are useful.  The only thing I know to do is to use an existence
check first but this is unfortunate because it requires two calls. 
Maybe a multi-op could be used but that seems too complex for such a
common use case.

-Martin

On 08/28/2015 05:47 PM, Daniel Kashtan wrote:
> I have this code using Curator:
>
> try
> {
>    client.create().forPath(path);
> }
> catch (KeeperException.NodeExistsException ex)
> {
>    LOG.debug("caught NodeExistsException");
> }
>
> The trouble is that it is never caught and zookeeper pollutes my production
> logs with what are probably harmless exceptions. I assume that my code
> executes just fine but later on the ZooKeeper server throws the exception
> as it does work in the background. Is there a way to gracefully catch those
> exceptions so they don't pile up in my production logs?
>
> I have tried in the past to fix my code so these exceptions are never
> thrown, but I have not found much in the documentation or on google on how
> to deal with these exceptions. Is it a known problem? I would love to solve
> these issues too if possible.
>