MattMcKnight
MattMcKnight

Reputation: 8290

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?

Upvotes: 5

Views: 2789

Answers (3)

Luca Geretti
Luca Geretti

Reputation: 10286

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.

Upvotes: 7

coder4
coder4

Reputation: 319

In the official documents, it says:

if the ZOO_SEQUENCE flag is set, a unique monotonically increasing sequence number is appended to the path name."

Which guaranteed the number is in increasing order, but not surely continuous.

Upvotes: 0

sbridges
sbridges

Reputation: 25150

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.

Upvotes: 4

Related Questions