ZooKeeper是有序的。ZooKeeper用一个数字来记录每个反映所有ZooKeeper事务的顺序。后续的操作可以使用顺序来实现高水平的抽象,例如同步原语。
ZooKeeper is fast. It is especially fast in "read-dominant" workloads. ZooKeeper applications run on thousands of machines, and it performs best where reads are more common than writes, at ratios of around 10:1.
ZooKeeper是快速的。尤其是在读取性能特性明显。ZooKeeper应用运行在成千台机器上,并且它在读取上比写入表现得更好,比率大概为10:1
Data model and the hierarchical namespaceThe name space provided by ZooKeeper is much like that of a standard file system. A name is a sequence of path elements separated by a slash (/). Every node in ZooKeeper's name space is identified by a path.
ZooKeeper所提供的命名空间跟标准文件系统很相似。路径中一系列元素是用斜杠(/)分隔的。每个节点在ZooKeper命名空间中是用路径来识别的。
ZooKeeper's Hierarchical Namespace
Nodes and ephemeral nodes(节点和临时节点)Unlike is standard file systems, each node in a ZooKeeper 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. (ZooKeeper was designed to store coordination data: status information, configuration, location information, etc., so the data stored at each node is usually small, in the byte to kilobyte range.) We use the term znode to make it clear that we are talking about ZooKeeper data nodes.
Znodes maintain a stat structure that includes version numbers for data changes, ACL changes, and timestamps, to allow cache validations and coordinated 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.
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 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. Ephemeral nodes are useful when you want to implement [tbd].
不像标准的文件系统,ZooKeeper命名空间中每个节点拥有与它以及它的孩子有关的数据。就像拥有一个文件系统一样允许一个文件也做为一个目录。(ZooKeeper被设计为储存调度数据:状态信息,配置信息、位置信息等等,所以储存每个节点中的数据通常很小,在字节到千字节之间)。当我们讨论ZooKeeper数据节点时使用“znode”这个称呼使得表述清晰。
Znodes维持一个状态结构包括数据改变的状态码,ACL改变和时间戳,允许缓存验证和调度更新信息。znodes的每个时间点的数据改变,版本号会增加。例如,当客户端获得数据时也接收到数据的版本。
储存在每个znode命名空间中的数据的读写都是原子性的。读取时获得与znode相关联的所有数据,写入时替换所有数据。每个节点都有严格的准入控制来限制谁可以做什么。
ZooKeeper也拥有临时节点的概念。这些节点一直存在只要创建这些节点的会话还是活跃的。当会话结束时节点被删除。当你想要实现临时节点是有用(待定)。
Conditional updates and watches(条件更新和监控)ZooKeeper supports the concept of watches. Clients can set a watch on a znodes. A watch will be triggered and removed when the znode changes. When a watch is triggered the client receives a packet saying that the znode has changed. And if the connection between the client and one of the Zoo Keeper servers is broken, the client will receive a local notification. These can be used to [tbd].
ZooKeeper支持监控的概念。客户端对znode设置一个监控。当znode改变时监控会触发并移除。当一个监控触发时客户端会收到一个数据包包含znode已经改变的信息。如果当客户端和ZooKeeper���务器的连接断开,客户端将会收到一个本地通知。这些都可以用来(待定)
Guarantees(保证)ZooKeeper is very fast and very simple. Since its goal, though, is to be a basis for the construction of more complicated services, such as synchronization, it provides a set of guarantees. These are:
Sequential Consistency - Updates from a client will be applied in the order that they were sent.
Atomicity - Updates either succeed or fail. No partial results.
Single System Image - A client will see the same view of the service regardless of the server that it connects to.
Reliability - Once an update has been applied, it will persist from that time forward until a client overwrites the update.
Timeliness - The clients view of the system is guaranteed to be up-to-date within a certain time bound.
For more information on these, and how they can be used, see [tbd]
ZooKeeper非常快和非常简单。然而它一直以来的目标,是作为更多复杂服务结构的基础,例如同步,提供一系列的保证。它们是:
顺序一致性:来自客户端的更新会按照它们的发送顺序进行应用。
原子性:更新只有成功或者失败,没有中间状态
单一系统图像:客户端无论连接哪个服务器,它所得到ZooKeeper服务的图像都是一致的
可靠性:一旦更新被应用,那么它将会一直持续保存直到更新被覆盖。
时效性:系统的客户端视图在一个特定的时间里都保证是最新的。
更多关于这些保证的信息和如何使用,可以看[待定]
Simple APIOne of the design goals of ZooKeeper is provide a very simple programming interface. As a result, it supports only these operations:
ZooKeeper的一个设计目标就是提供简单的编程接口。因此,他只提供这些操作:
create(创建)
creates a node at a location in the tree(在树结构位置中创建一个节点)
delete(删除)
deletes a node(删除一个节点)
exists(判断是否存在)
tests if a node exists at a location(判断一个节点是否存在么讴歌位置上)
get data(获取数据)
reads the data from a node(从一个节点读取数据)
set data(设置数据)
writes data to a node(往一个节点里写入数据)
get children(获得子集)
retrieves a list of children of a node(获得一个节点的子集)
sync(同步)
waits for data to be propagated(等待数据同步到每个节点上)
For a more in-depth discussion on these, and how they can be used to implement higher level operations, please refer to [tbd]
这些方法的深入讨论和如何是用来实现更高程度的操作,请参考[tbd]
Implementation(实现)