Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zookeeper PERSISTENT_SEQUENTIAL incrementing by two

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?

like image 688
MattMcKnight Avatar asked Apr 26 '12 17:04

MattMcKnight


People also ask

What is the difference between an ephemeral znode and a persistent znode in ZooKeeper?

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.

Which of the following is the correct ZooKeeper syntax for creating a sequential?

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.

What is Pzxid in ZooKeeper?

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.

What is ephemeral node in ZooKeeper?

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).


2 Answers

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.

like image 125
Luca Geretti Avatar answered Oct 29 '22 16:10

Luca Geretti


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.

like image 44
sbridges Avatar answered Oct 29 '22 16:10

sbridges