没有合适的资源?快使用搜索试试~ 我知道了~
Zookeeper 开发手册
5星 · 超过95%的资源 需积分: 10 61 下载量 195 浏览量
2011-10-25
10:44:14
上传
评论 1
收藏 131KB PDF 举报
温馨提示
试读
23页
Zookeeper 开发手册,英文的,需要中文的童鞋就不要下载了,免得骂人哈。
资源推荐
资源详情
资源评论
Copyright © 2008 The Apache Software Foundation. All rights reserved.
ZooKeeper Programmer's Guide
Developing Distributed Applications that use ZooKeeper
by
Table of contents
1 Introduction........................................................................................................................ 3
2 The ZooKeeper Data Model.............................................................................................. 3
2.1 ZNodes..........................................................................................................................4
2.2 Time in ZooKeeper.......................................................................................................5
2.3 ZooKeeper Stat Structure............................................................................................. 6
3 ZooKeeper Sessions........................................................................................................... 7
4 ZooKeeper Watches......................................................................................................... 10
4.1 What ZooKeeper Guarantees about Watches............................................................. 11
4.2 Things to Remember about Watches..........................................................................11
5 ZooKeeper access control using ACLs............................................................................11
5.1 ACL Permissions........................................................................................................ 12
6 Pluggable ZooKeeper authentication............................................................................... 15
7 Consistency Guarantees................................................................................................... 17
8 Bindings............................................................................................................................18
8.1 Java Binding............................................................................................................... 18
8.2 C Binding....................................................................................................................19
9 Building Blocks: A Guide to ZooKeeper Operations......................................................21
9.1 Handling Errors...........................................................................................................21
9.2 Connecting to ZooKeeper...........................................................................................21
9.3 Read Operations..........................................................................................................21
ZooKeeper Programmer's Guide
Page 2
Copyright © 2008 The Apache Software Foundation. All rights reserved.
9.4 Write Operations.........................................................................................................21
9.5 Handling Watches.......................................................................................................22
9.6 Miscelleaneous ZooKeeper Operations...................................................................... 22
10 Program Structure, with Simple Example......................................................................22
11 Gotchas: Common Problems and Troubleshooting....................................................... 22
ZooKeeper Programmer's Guide
Page 3
Copyright © 2008 The Apache Software Foundation. All rights reserved.
1 Introduction
This document is a guide for developers wishing to create distributed applications that
take advantage of ZooKeeper's coordination services. It contains conceptual and practical
information.
The first four sections of this guide present higher level discussions of various ZooKeeper
concepts. These are necessary both for an understanding of how ZooKeeper works as well
how to work with it. It does not contain source code, but it does assume a familiarity with the
problems associated with distributed computing. The sections in this first group are:
• The ZooKeeper Data Model
• ZooKeeper Sessions
• ZooKeeper Watches
• Consistency Guarantees
The next four sections provide practical programming information. These are:
• Building Blocks: A Guide to ZooKeeper Operations
• Bindings
• Program Structure, with Simple Example [tbd]
• Gotchas: Common Problems and Troubleshooting
The book concludes with an appendix containing links to other useful, ZooKeeper-related
information.
Most of information in this document is written to be accessible as stand-alone reference
material. However, before starting your first ZooKeeper application, you should probably at
least read the chaptes on the ZooKeeper Data Model and ZooKeeper Basic Operations. Also,
the Simple Programmming Example [tbd] is helpful for understanding the basic structure of
a ZooKeeper client application.
2 The ZooKeeper Data Model
ZooKeeper has a hierarchal name space, much like a distributed file system. The only
difference is that each node in the namespace can have data associated with it as well as
children. It is like having a file system that allows a file to also be a directory. Paths to nodes
are always expressed as canonical, absolute, slash-separated paths; there are no relative
reference. Any unicode character can be used in a path subject to the following constraints:
• The null character (\u0000) cannot be part of a path name. (This causes problems with the
C binding.)
• The following characters can't be used because they don't display well, or render in
confusing ways: \u0001 - \u0019 and \u007F - \u009F.
ZooKeeper Programmer's Guide
Page 4
Copyright © 2008 The Apache Software Foundation. All rights reserved.
• The following characters are not allowed: \ud800 -uF8FFF, \uFFF0-uFFFF, \uXFFFE -
\uXFFFF (where X is a digit 1 - E), \uF0000 - \uFFFFF.
• The "." character can be used as part of another name, but "." and ".." cannot alone be
used to indicate a node along a path, because ZooKeeper doesn't use relative paths. The
following would be invalid: "/a/b/./c" or "/a/b/../c".
• The token "zookeeper" is reserved.
2.1 ZNodes
Every node in a ZooKeeper tree is referred to as a znode. Znodes maintain a stat structure
that includes version numbers for data changes, acl changes. The stat structure also has
timestamps. The version number, together with the timestamp allow ZooKeeper to validate
the cache and to coordinate updates. Each time a znode's data changes, the version number
increases. For instance, whenever a client retrieves data, it also receives the version of the
data. And when a client performs an update or a delete, it must supply the version of the
data of the znode it is changing. If the version it supplies doesn't match the actual version
of the data, the update will fail. (This behavior can be overridden. For more information
see... )[tbd...]
Note:
In distributed application engineering, the word node can refer to a generic host machine, a server, a
member of an ensemble, a client process, etc. In the ZooKeeper documentation, znodes refer to the
data nodes. Servers refer to machines that make up the ZooKeeper service; quorum peers refer to
the servers that make up an ensemble; client refers to any host or process which uses a ZooKeeper
service.
Znodes are the main enitity that a programmer access. They have several characteristics that
are worth mentioning here.
2.1.1 Watches
Clients can set watches on znodes. Changes to that znode trigger the watch and then clear the
watch. When a watch triggers, ZooKeeper sends the client a notification. More information
about watches can be found in the section ZooKeeper Watches.
2.1.2 Data Access
The data stored at each znode in a namespace is read and written atomically. Reads get all the
data bytes associated with a znode and a write replaces all the data. Each node has an Access
Control List (ACL) that restricts who can do what.
ZooKeeper was not designed to be a general database or large object store. Instead,
it manages coordination data. This data can come in the form of configuration, status
ZooKeeper Programmer's Guide
Page 5
Copyright © 2008 The Apache Software Foundation. All rights reserved.
information, rendezvous, etc. A common property of the various forms of coordination data
is that they are relatively small: measured in kilobytes. The ZooKeeper client and the server
implementations have sanity checks to ensure that znodes have less than 1M of data, but the
data should be much less than that on average. Operating on relatively large data sizes will
cause some operations to take much more time than others and will affect the latencies of
some operations because of the extra time needed to move more data over the network and
onto storage media. If large data storage is needed, the usually pattern of dealing with such
data is to store it on a bulk storage system, such as NFS or HDFS, and store pointers to the
storage locations in ZooKeeper.
2.1.3 Ephemeral Nodes
ZooKeeper also has the notion of ephemeral nodes. These znodes exists as long as the
session that created the znode is active. When the session ends the znode is deleted. Because
of this behavior ephemeral znodes are not allowed to have children.
2.1.4 Sequence Nodes -- Unique Naming
When creating a znode you can also request that ZooKeeper append a monotonically
increasing counter to the end of path. This counter is unique to the parent znode. The counter
has a format of %010d -- that is 10 digits with 0 (zero) padding (the counter is formatted in
this way to simplify sorting), i.e. "<path>0000000001". See Queue Recipe for an example
use of this feature. Note: the counter used to store the next sequence number is a signed int
(4bytes) maintained by the parent node, the counter will overflow when incremented beyond
2147483647 (resulting in a name "<path>-2147483647").
2.2 Time in ZooKeeper
ZooKeeper tracks time multiple ways:
• Zxid
Every change to the ZooKeeper state receives a stamp in the form of a zxid (ZooKeeper
Transaction Id). This exposes the total ordering of all changes to ZooKeeper. Each
change will have a unique zxid and if zxid1 is smaller than zxid2 then zxid1 happened
before zxid2.
• Version numbers
Every change to a a node will cause an increase to one of the version numbers of that
node. The three version numbers are version (number of changes to the data of a znode),
cversion (number of changes to the children of a znode), and aversion (number of
changes to the ACL of a znode).
• Ticks
剩余22页未读,继续阅读
gavinh2008
- 粉丝: 0
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页