Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check if a path exists in Zookeeper using Curator?

Tags:

I'm currently in the early stages of development to integrate Zookeeper stuff into my app. I'm using Netflix's Curator as an API for dealing with Zookeeper. I get the gist of most of it (like adding ZNodes and whatnot).

But how the heck do you check if a ZNode exists? The code that seems like it would work is:

client.checkExists().forPath(path); 

...Where client is an instance of com.netflix.curator.framework.CuratorFramework

However, this call returns a org.apache.zookeeper.data.Stat object.

Using this object, how can I tell if a path exists or not?

Thanks

like image 917
Cody S Avatar asked Sep 21 '12 20:09

Cody S


People also ask

What is curator in ZooKeeper?

The Curator Framework is a high-level API that greatly simplifies using ZooKeeper. It adds many features that build on ZooKeeper and handles the complexity of managing connections to the ZooKeeper cluster and retrying operations.

What are ZooKeeper ZNodes?

What is Zookeeper ZNodes? The term ZNode is referred to every node in a ZooKeeper tree. The main purpose of the Znode is to maintain a stat structure. However, stat structure includes version numbers for data changes and ACL changes. Also, a stat structure includes timestamps in it.


1 Answers

The org.apache.zookeeper.data.Stat object is metadata about that ZNode. (It's conceptually similar to how stat() tells you information about a file on the filesystem, hence the name.) checkExists().forPath() returns a Stat if it exists, or null if it doesn't.

like image 158
willglynn Avatar answered Oct 07 '22 11:10

willglynn