# ZooKeeper基本数据模型

## 介绍

ZooKeeper是一个树形结构，类似于前端开发中的tree.js组件。

ZooKeeper的数据模型也可以理解为linux/unix的文件目录：/usr/local/...

每个节点都称为znode，它可以有子节点，也可以有数据。

每个节点分为临时节点和永久节点，临时节点在客户端断开后消失。

每个ZooKeeper节点都有各自的版本号，可以通过命令行来显示节点信息。

每当节点数据发生变化，那么该节点的版本号会累加（乐观锁）

删除/修改过时节点， 版本号不同匹配则会报错。

每个ZooKeeper节点存储的数据不宜过大，几k即可。

节点可以设置权限acl，可以通过权限来限制用户的访问。

![](/files/-LfnTMIoqw-LdxQIWNUl)

参考资料：

[ZooKeeper系列之二：ZooKeeper数据模型、命名空间以及节点的概念](https://blog.csdn.net/shenlan211314/article/details/6170731)

[Zookeeper数据模型及其应用](https://www.cnblogs.com/wxisme/p/6085501.html)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xiaoxiami.gitbook.io/zookeeper/zookeeperji-ben-shu-ju-mo-xing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
