We don't watch the file of the -ROOT- region. We just asynchronously read it once to find -ROOT-, then we close our ZooKeeper session. There are a few reasons for this. First of all, the -ROOT- region doesn't move often. When it does, and when we need to use it, we'll realize that -ROOT- is no longer where we though it was and we'll find it again. Secondly, maintaining a session open just to watch the -ROOT- region is a waste of resources both on our side and on ZK's side. ZK is chatty, it will frequently send us heart beats that will keep waking its event thread, etc. Third, if the application we're part of already needs to maintain a session with ZooKeeper anyway, we can't easily share it with them anyway, because of ZooKeeper's API. Indeed, unfortunately the ZooKeeper API requires that the {@link ZooKeeper}object be re-created when the session is invalidated (due to a disconnection or a timeout), which means that it's impossible to share the {@link ZooKeeper} object. Ideally in an application thereshould be only one instance, but their poor API makes it impractical, since the instance must be re-created when the session is invalidated, which entails that one entity should own the reconnection process and have a way of giving everyone else the new instance. This is extremely cumbersome so I don't expect anyone to do this, which is why we manage our own instance.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|