Doing a simple create() method call in ZooKeeper seems to be incrementing by two instead of the normal one. While this is actually in keeping with the JavaDoc, which only specifies that the sequence be "monotonically increasing" without reference to the increment amount, I am not sure why this has started happening.
zk.create(path, value, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL);
I end up with "key-v-0000000056" then "key-v-0000000058"...where did 57 go?
Types of Znodes Persistence znode − Persistence znode is alive even after the client, which created that particular znode, is disconnected. By default, all znodes are persistent unless otherwise specified. Ephemeral znode − Ephemeral znodes are active until the client is alive.
Sequential znodes guaranty that the znode path will be unique. ZooKeeper ensemble will add sequence number along with 10 digit padding to the znode path. For example, the znode path /myapp will be converted to /myapp0000000001 and the next sequence number will be /myapp0000000002.
ZooKeeper Stat Structure pzxid The zxid of the change that last modified children of this znode. ctime The time in milliseconds from epoch when this znode was created. mtime The time in milliseconds from epoch when this znode was last modified. version The number of changes to the data of this znode.
An ephemeral zNode is a node that will disappear when the session of its owner ends. A typical use case for ephemeral nodes is when using ZooKeeper for discovery of hosts in your distributed system (service discovery).
Creation or deletion of any child znode increments the cversion of the parent znode. Since in ZooKeeper 3.3.3, which it seems you are using, the counter used for sequential znode creation is cversion itself, any "spurious" creation/deletion between two sequential creations is the most likely reason for the behavior you are experiencing.
Keep in mind that in ZooKeeper 3.4.x deletions do not affect the parent sequence counter anymore: a DataNode
internally holds a PersistedStat
in which the cversion represents the number of creations exactly; on the contrary, the cversion of the Stat
that you obtain by querying the node still represents the number of children changes: Stat.cversion = 2*PersistedStat.cversion - Stat.numChildren
.
Are you deleting key-v-0000000056 before you create the next key? The sequential id is just the cversion of the parent node, and deleting/creating children on the parent will increment the cversion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With