Database Reference
In-Depth Information
coordination and configuration using a system loosely based on a
hierarchical file system. These features, often called recipes in ZooKeeper
jargon, are left as an exercise for the application author. This has the
advantage of simplifying the ZooKeeper codebase, but it does force the
application developer to deal with some potentially difficult
implementations.
Fortunately, there are client libraries, such as the Curator library discussed
later in this chapter, that have carefully implemented the more complicated
recipes. This section covers the usage of the Curator library, but first it
covers the basics of ZooKeeper itself.
The znode
The core of ZooKeeper's data structures is the
znode
. These nodes can be
arranged hierarchically into tree structures as well as hold data. Because
ZooKeeper is not intended as a bulk storage facility, the amount of data a
single
znode
can hold is limited to about 1 MB of data. It also means that
ZooKeeperdoesnotsupportpartialreads,writes,orappends.Whenreading
and writing data, the entire byte array is transmitted in a single call.
The
znode
API supports six fundamental operations:
• The
create
operation, which takes a path and optional data element.
This, naturally, creates a new
znode
at the specified path with data if it
does not exist.
• The
delete
operation, which removes a
znode
from the hierarchy.
• The
exists
operation, which takes a path and allows applications to
check for the presence of a
znode
without reading its data.
• The
setData
operation, which takes the same parameters as the
create
operation. It overwrites data in an existing
znode
, but it doesn't create
a new one if it does not already exist.
• The
getData
operation retrieves the data block for a
znode
.
• The
getChildren
operation retrieves a list of children of the
znode
at
the specified path. This operation is a key part of many of the
coordination recipes developed for ZooKeeper.
All of these operations are subject to ZooKeeper's access control policies.
These operate much like file system permissions and dictate which clients