NOTE

ZooKeeper Znode Properties

The four ZooKeeper node types: persistent, ephemeral, persistent sequential, and ephemeral sequential.

ZooKeeperCreated Updated 1 min readhistorical

This is a historical learning note and may contain outdated or incomplete understanding.

1. Node Types

1.1. PERSISTENT (Persistent Node)

Unless manually deleted, the node always exists in ZooKeeper.

[zk: localhost:2181(CONNECTED) 9] create /zsk
Created /zsk
[zk: localhost:2181(CONNECTED) 10] ls /zsk
[]

1.2. EPHEMERAL (Ephemeral Node)

The lifecycle of an ephemeral node is bound to the client session. Once the client session becomes invalid (a disconnected connection between the client and ZooKeeper does not necessarily mean the session is invalid), all ephemeral nodes created by that client are removed.

After the session ends or times out, ZooKeeper automatically deletes the node.

[zk: localhost:2181(CONNECTED) 11] create -e /zsk2
Created /zsk2
[zk: localhost:2181(CONNECTED) 12] ls /zsk2
[]

After pressing Ctrl+C to exit and logging in again, the /vvv node disappears.

1.3. PERSISTENT_SEQUENTIAL (Persistent Sequential Node)

Its basic characteristics are the same as a persistent node. It additionally has a sequential property: an auto-incrementing integer maintained by the parent node is appended to the node name.

After the sequential property is specified, the sequence number of the created node increases.

[zk: localhost:2181(CONNECTED) 13] create -s /zsk3
Created /zsk30000000178
[zk: localhost:2181(CONNECTED) 14] ls /zsk3
Node does not exist: /zsk3
[zk: localhost:2181(CONNECTED) 15] ls /zsk30000000178
[]
[zk: localhost:2181(CONNECTED) 16]

1.4. EPHEMERAL_SEQUENTIAL (Ephemeral Sequential Node)

Its basic characteristics are the same as an ephemeral node. It additionally has a sequential property: an auto-incrementing integer maintained by the parent node is appended to the node name.

[zk: localhost:2181(CONNECTED) 16] create -se /zsk4
Created /zsk40000000179
[zk: localhost:2181(CONNECTED) 17] ls /zsk40000000179
[]
[zk: localhost:2181(CONNECTED) 18]

Discussion

Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub