Database Reference
In-Depth Information
at the same time. For example, a setData operation with a version number will fail with
a KeeperException.BadVersionException if the znode is updated by another
process first because the version number does not match. The programmer is usually
aware that this kind of conflict is possible and will code to deal with it.
Some state exceptions indicate an error in the program, such as KeeperExcep-
tion.NoChildrenForEphemeralsException , which is thrown when trying to
create a child znode of an ephemeral znode.
Recoverable exceptions
Recoverable exceptions are those from which the application can recover within the same
ZooKeeper session. A recoverable exception is manifested by KeeperExcep-
tion.ConnectionLossException , which means that the connection to ZooKeeper
has been lost. ZooKeeper will try to reconnect, and in most cases the reconnection will
succeed and ensure that the session is intact.
However, ZooKeeper cannot tell if the operation that failed with a KeeperExcep-
tion.ConnectionLossException was applied. This is an example of partial fail-
ure (which we introduced at the beginning of the chapter). The onus is therefore on the
programmer to deal with the uncertainty, and the action that should be taken depends on
the application.
At this point, it is useful to make a distinction between idempotent and nonidempotent op-
erations. An idempotent operation is one that may be applied one or more times with the
same result, such as a read request or an unconditional setData . These can simply be
retried.
A nonidempotent operation cannot be retried indiscriminately, as the effect of applying it
multiple times is not the same as that of applying it once. The program needs a way of de-
tecting whether its update was applied by encoding information in the znode's pathname
or its data. We discuss how to deal with failed nonidempotent operations in Recoverable
exceptions , when we look at the implementation of a lock service.
Unrecoverable exceptions
In some cases, the ZooKeeper session becomes invalid — perhaps because of a timeout or
because the session was closed (both of these scenarios get a KeeperExcep-
tion.SessionExpiredException ), or perhaps because authentication failed
( KeeperException.AuthFailedException ). In any case, all ephemeral nodes
associated with the session will be lost, so the application needs to rebuild its state before
reconnecting to ZooKeeper.
Search WWH ::




Custom Search