Database Reference
In-Depth Information
time the database moves. Also, there would be no straightforward way to update the connec-
tion information if the database needs to be moved while you have an analytic running.
Better still, storing the connection information in ZooKeeper allows your analytics to quickly
access the information while also providing a simple mechanism for updates.
key-value store. In fact, there are protections built into ZooKeeper to ensure that folks do not
attempt to use it as a large data store. ZooKeeper is, however, just right when all you want to
do is share a little bit of information across your environment.
Tutorial Links
The official
getting started guide
is a great place to get your feet wet with ZooKeeper.
Example Code
In this example, we're going to start by opening the ZooKeeper command-line interface:
$ zookeeper-client
Now we'll create a key-value pair. In this case, the key is
/movie_reviews/database
and
the value is the IP address of a database we'll use for our movie reviews:
[zk: localhost:3000(CONNECTED) 0] create /movie_reviews ''
Created /movie_reviews
[zk: localhost:3000(CONNECTED) 1] create /movie_reviews/database
'10.2.1.1'
Created /movie_reviews/database
Now we'll retrieve the value for our key. Notice that we get back two important pieces of
data—the actual value of
10.2.1.1
and the version of the value:
[zk: localhost:3000(CONNECTED) 2] get /movie_reviews/database
'10.2.1.1'
<metadata>
dataVersion = 0
<metadata>