DUE TO SPAM, SIGN-UP IS DISABLED. Goto Selfserve wiki signup and request an account.
Eurosys 2011 Tutorial
Tutorial slides
Code and library
To complete this tutorial you will need the ZooKeeper 3.3.3 "fat" jar. This has all you need to run zookeeper and develop against it.
Example skeleton code:
Running the ZooKeeper server
...
starts a ZooKeeper server running on port 2181. It is storing its data in /tmp, so this is obviously not a way you want to run in production.
Lets start up a ZooKeeper server cluster, so that we can experiment If you want to startup a cluster of server, you must do a bit more. To do this we need to create a configuration file for each server. Generally, we can share a configuration file across server, but since we are starting all three on the same machine, we need to have a configuration for each server:
...
| Code Block |
|---|
java -jar zookeeper-3.3.3-fatjar.jar client -server 127.0.0.1:2181
|
_if you started up a cluster of servers, you would use 127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183
...
instead of just 127.0.0.1:2181.
Now lets create the znodes. We have to supply initial data for them even though it isn't used:
| Code Block |
|---|
[zk: 127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183(CONNECTED) 0] create /assign "" Created /assign [zk: 127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183(CONNECTED) 1] create /tasks "" Created /tasks [zk: 127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183(CONNECTED) 2] ls / [assign, tasks, zookeeper] |
Tutorial slides
...
Extra credit (testing)
The code you have written works and is dynamic, but doesn't handle every error correctly. Check what happens when errors occur: change the TaskQueueWorker.java to use FailFirstZooKeeper.java and see what happens. (When submitting multiple tasks you will find that one gets assigned to a phantom worker.) How do you fix it?