ZooKeeper主要有三类功能
ZooKeeper Data Model -------->
ZNodes,Time in ZooKeeper , ZooKeeper Stat Structure
Znodes
ZooKeeper 中每一个node都对应一个znode
znode维护着数据的version numbers for data changes acl changes
version numbers 在每次data发生变化时都会自动增长。
znode是程序操作的实体。操作有如下几种
Watches client可以为znode设置Watches
Data Access 可以原子性的读取znode的数据
znode 存放的数据不易过大
Time in ZooKeeper
ZooKeeper tracks time multiple ways
Zxid , Version numbers , Ticks , Real time
ZooKeeper Stat Structure
czxid , mzxid , pzxid , ctime , mtime , version , cversion , aversion , ephemeralOwner , dataLength , numChildren
ZooKeeper Sessions
自动保持,检测,重连,更换,负载均衡 连接及session信息
ZooKeeper Watches
1. one-time trigger 每个watches只会触发一次,除非再次创建watches
2.sent to the client ZooKeeper会保证client感知到data changge的顺序
3.the data for which the watch was set. getData () exists() set data watches。getchildren() sets child watches.
触发watches的事件
-
Created event:
Enabled with a call to exists.
-
Deleted event:
Enabled with a call to exists, getData, and getChildren.
-
Changed event:
Enabled with a call to exists and getData.
-
Child event:
Enabled with a call to getChildren.
-
Child Remove event:
Watcher which was added with a call to getChildren.
-
Data Remove event:
Watcher which was added with a call to exists or getData.
client在看到新数据之前,会先看到对应Watches
watches的顺序和数据更新顺序一致
ZooKeeper access control using ACLs
ZooKeeper supports the following permissions:
-
CREATE: you can create a child node
-
READ: you can get data from a node and list its children.
-
WRITE: you can set data for a node
-
DELETE: you can delete a child node
-
ADMIN: you can set permissions
ZooKeeper Gurantees
ZooKeeper java Example