ZooKeeper Data Model – Znodes, Time & Stat Structure
1. Objective – Data Model in ZooKeeper
In our last ZooKeeper Tutorial, we discussed ZooKeeper ZNodes. Today, we will see the ZooKeeper Data Model. First, we will discuss the meaning of the data Model in Apache ZooKeeper. Moreover, we will learn ZNodes, Time in ZooKeeper, and ZooKeeper Stat Structure.
So, let’s start ZooKeeper Data Model.
2. ZooKeeper Data Model
As same as a distributed file system, ZooKeeper also has a hierarchal namespace. Though there is one thing with differ them is that each node in the namespace here may contain the data associated with it or associated with children. So, it is more like having a file system which permits a file to also behave as a directory. However, to nodes, paths are always expressed in several ways such as canonical, absolute, slash-separated paths; and there is no relative reference. Moreover, to the following constraints, we can use any unicode character in a path subject:
- There should be no null character (\u0000) as a part of a pathname. Because it causes problems with the C binding.
- We can not use these following characters \u0001 – \u0019 and \u007F – \u009F because these characters don’t display well, or may render in confusing ways.
- Similarly, the following characters \ud800 -uF8FFF, \uFFF0-uFFFF, \uXFFFE – \uXFFFF (where X is a digit 1 – E), \uF0000 – \uFFFFF, are not allowed.
- We can use “.” character as part of another name. Yet it is not possible to use “.” and “..” alone to indicate a node along a path. This is only because ZooKeeper doesn’t use relative paths. So, The following “/a/b/./c” or “/a/b/../c” , would be invalid.
In addition, the “zookeeper” token is reserved.
Do you know about ZooKeeper Queues
3. Different Data Model in ZooKeeper
Below given are the ZooKeeper Data Model, let’s discuss them in detail:
Basically, in a ZooKeeper tree, every node a ZNode. As their main purpose, Znodes maintain a stat structure. However, a Stat Structure consists of version numbers for data changes, all changes as well as timestamps. In other words, the main entity that a programmer access are ZNodes.
b. Time in ZooKeeper
In multiple ways, ZooKeeper tracks time:
i. Zxid(ZooKeeper Transaction Id)
In the form of a zxid (ZooKeeper Transaction Id), every change to the ZooKeeper state receives a stamp. So, the total ordering of all changes to ZooKeeper exposes by it. Make sure each change will have a unique zxid.
Let’s discuss the benefits and limitations of ZooKeeper
ii. Version numbers
With every change to a node, an increase causes to one of the version numbers of that node. There are three version numbers:
a. version- It is the number of changes to the data of a znode.
b. cversion- Whereas, it is the number of changes to the children of a znode.
c. aversion- It is a number of changes to the ACL of a znode.
Servers use ticks to define the timing of events when using multi-server ZooKeeper. For example, session timeouts, status uploads, connection timeouts between peers, and many more. However, indirectly tick time is exposed through the minimum session timeout. Here, minimum session timeout is 2 times the tick time. So, the server will tell the client that the session timeout is actually the minimum session timeout if a client requests a session timeout less than the minimum session timeout.
Learn more about ZooKeeper Workflow
Except to put timestamps into the stat structure on the znode creation and znode modification, ZooKeeper doesn’t use real-time, or clock time, at all.
c. ZooKeeper Stat Structure
In ZooKeeper, the Stat structure is made up of the various fields, for each ZNode:
It is the zxid of the change, basically which caused this znode to be created.
Whereas, it is the zxid of the change since last modified of this znode.
ctime is the time in milliseconds from an epoch since this znode was created.
On defining mtime, it is the time in milliseconds from an epoch since this znode was last modified.
version shows the number of changes happens to the data of this znode.
Read ZooKeeper Leader Election
Similarly, the number of changes occurs to the children of this znode is shown by cversion.
Simply, the aversion is the number of changes to the ACL of this znode.
If the znode is an ephemeral node, so this is the session id of the owner of this znode. However, it will be zero, if it is not an ephemeral node.
It displays the length of the data field of this znode.
As per its name, “numChildren” signifies the number of children of this znode.
So, this was all in the ZooKeeper Data Model. Hope you like our explanation.
Hence, we have learned the whole about ZooKeeper Data Model. Moreover, in this data model in ZooKeeper, we discussed Znodes, Time, and Stat Structure in detail. Still, if any doubt regarding ZooKeeper Data Model, ask in the comment tab.
See also –