Package org.apache.drill.exec.coord.zk
Class ZookeeperClient
java.lang.Object
org.apache.drill.exec.coord.zk.ZookeeperClient
- All Implemented Interfaces:
AutoCloseable
A namespace aware Zookeeper client.
The implementation only operates under the given namespace and is safe to use.
Note that instance of this class holds onto resources that must be released via
#close()
.-
Constructor Summary
ConstructorDescriptionZookeeperClient
(org.apache.curator.framework.CuratorFramework curator, String root, org.apache.zookeeper.CreateMode mode) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
Creates the given path without placing any data in.void
Deletes the given node residing at the given pathentries()
Returns an iterator of (key, value) pairs residing underroot
path.byte[]
Returns a value corresponding to the given path if path exists in the cache, null otherwise.byte[]
Returns the value corresponding to the given key, null otherwise.byte[]
get
(String path, boolean consistent, DataChangeVersion version) Returns the value corresponding to the given key, null otherwise.byte[]
get
(String path, DataChangeVersion version) Returns the value corresponding to the given key, null otherwise.org.apache.curator.framework.recipes.cache.PathChildrenCache
getCache()
org.apache.zookeeper.CreateMode
getMode()
getRoot()
boolean
Returns true if path exists in the cache, false otherwise.boolean
Returns true if path exists, false otherwise.boolean
hasPath
(String path, boolean consistent, DataChangeVersion version) Checks if the given path exists.void
Puts the given byte sequence into the given path.void
put
(String path, byte[] data, DataChangeVersion version) Puts the given byte sequence into the given path.byte[]
putIfAbsent
(String path, byte[] data) Puts the given byte sequence into the given path if path is does not exist.void
start()
Starts the client.
-
Constructor Details
-
ZookeeperClient
public ZookeeperClient(org.apache.curator.framework.CuratorFramework curator, String root, org.apache.zookeeper.CreateMode mode)
-
-
Method Details
-
start
Starts the client. This call ensures the creation of the root path. -
getCache
public org.apache.curator.framework.recipes.cache.PathChildrenCache getCache() -
getRoot
-
getMode
public org.apache.zookeeper.CreateMode getMode() -
hasPath
Returns true if path exists in the cache, false otherwise. Note that calls to this method are eventually consistent.- Parameters:
path
- path to check- Returns:
- true if path exists, false otherwise
-
hasPath
Returns true if path exists, false otherwise. If consistent flag is set to true, check is done directly is made against Zookeeper directly, else check is done against local cache.- Parameters:
path
- path to checkconsistent
- whether the check should be consistent- Returns:
- true if path exists, false otherwise
-
hasPath
Checks if the given path exists. If the flag consistent is set, the check is consistent as it is made against Zookeeper directly. Otherwise, the check is eventually consistent. If consistency flag is set to true and version holder is not null, passes version holder to get data change version. Data change version is retrieved fromStat
object, it increases each time znode data change is performed. Link to Zookeeper documentation - https://zookeeper.apache.org/doc/r3.2.2/zookeeperProgrammers.html#sc_zkDataModel_znodes- Parameters:
path
- path to checkconsistent
- whether the check should be consistentversion
- version holder- Returns:
- true if path exists, false otherwise
-
get
Returns a value corresponding to the given path if path exists in the cache, null otherwise. Note that calls to this method are eventually consistent.- Parameters:
path
- target path
-
get
Returns the value corresponding to the given key, null otherwise. If the flag consistent is set, the check is consistent as it is made against Zookeeper directly. Otherwise, the check is eventually consistent.- Parameters:
path
- target pathconsistent
- consistency flag
-
get
Returns the value corresponding to the given key, null otherwise. The check is consistent as it is made against Zookeeper directly. Passes version holder to get data change version.- Parameters:
path
- target pathversion
- version holder
-
get
Returns the value corresponding to the given key, null otherwise. If the flag consistent is set, the check is consistent as it is made against Zookeeper directly. Otherwise, the check is eventually consistent. If consistency flag is set to true and version holder is not null, passes version holder to get data change version. Data change version is retrieved fromStat
object, it increases each time znode data change is performed. Link to Zookeeper documentation - https://zookeeper.apache.org/doc/r3.2.2/zookeeperProgrammers.html#sc_zkDataModel_znodes- Parameters:
path
- target pathconsistent
- consistency checkversion
- version holder
-
create
Creates the given path without placing any data in.- Parameters:
path
- target path
-
put
Puts the given byte sequence into the given path. If path does not exists, this call creates it.- Parameters:
path
- target pathdata
- data to store- Throws:
IllegalArgumentException
- if data size is bigger that jute.maxbuffer value
-
put
Puts the given byte sequence into the given path.If path does not exists, this call creates it.
If version holder is not null and path already exists, passes given version for comparison. Zookeeper maintains stat structure that holds version number which increases each time znode data change is performed. If we pass version that doesn't match the actual version of the data, the update will fail
KeeperException.BadVersionException
. We catch such exception and re-throw it asVersionMismatchException
. Link to documentation - https://zookeeper.apache.org/doc/r3.2.2/zookeeperProgrammers.html#sc_zkDataModel_znodes- Parameters:
path
- target pathdata
- data to storeversion
- version holder- Throws:
IllegalArgumentException
- if data size is bigger that jute.maxbuffer value
-
putIfAbsent
Puts the given byte sequence into the given path if path is does not exist.- Parameters:
path
- target pathdata
- data to store- Returns:
- null if path was created, else data stored for the given path
-
delete
Deletes the given node residing at the given path- Parameters:
path
- target path to delete
-
entries
Returns an iterator of (key, value) pairs residing underroot
path. -
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-