小光 游
小光 游

Reputation: 1

Have zookeeper sequential number continuous since 3.4.x?

In my project, I need the latest sequential number without get children nodes, because there are too many children nodes.

Upvotes: 0

Views: 269

Answers (2)

ReneSac
ReneSac

Reputation: 531

Acording to this answer and confirmed by my experiments, since Zookeeper 3.4 the sequential znodes are numbered from the parent's PersistedStat.cversion number, that stores the number of znodes created under it. You can calculate this number querying the parent znode stat and then applying the following formula:

PersistedStat.cversion = (ZnodeStat.cversion + ZnodeStat.numChildren) /2

That way, you don't need to use get_children() to discover the number of the last created znode.

Upvotes: 1

JasonG
JasonG

Reputation: 5962

I don't think you can do that. What you could to is watch the node that is n+1 (which doesn't exist) and then take action when it triggers a watch upon creation.

Also consider leader election where that node publishes itself. This can cause big blasts of data to go out though if you have a lot of nodes. http://techblog.outbrain.com/2011/07/leader-election-with-zookeeper/

Upvotes: 0

Related Questions