Zookeeper zkCli.sh create switches documentation
Asked Answered
T

1

7

Sorry this is a pretty lame question. I googled and searched on the ZK websites for a long time before I finally opted to ask here though!

When I start ZooKeeper's zkCli.sh and type help, for the create command it says:

create [-s] [-e] path data acl

What are the -s and -e for?

While that is really I need to know, I would also like to know where this information is defined, documented and/or described because as I said, I searched for a long time and was not able to find it!

thanks for any help!

Turgot answered 18/2, 2015 at 17:16 Comment(0)
T
7

The -s and -e options are for specifying sequential or ephemeral nodes.

Unfortunately, I am not sure if this is documented anywhere. Luckily, Zookeeper is open source. We can just go ahead and check the best source of truth - the code.

https://github.com/apache/zookeeper/blob/trunk/bin/zkCli.sh

The shell script is starting a new java process - org.apache.zookeeper.ZooKeeperMain. Next step might be a bit harder without some basic Java knowledge, but we can try a simple code search and see if we can spot something:

https://github.com/apache/zookeeper/blob/trunk/src/java/main/org/apache/zookeeper/ZooKeeperMain.java

It appears the actual command has its own class:

https://github.com/apache/zookeeper/blob/trunk/src/java/main/org/apache/zookeeper/cli/CreateCommand.java

Bingo. We can see the options right at the top:

 options.addOption(new Option("e", false, "ephemeral"));
 options.addOption(new Option("s", false, "sequential"));

Let's try to confirm this. Later on in the code, we can see all the possible cases:

CreateMode flags = CreateMode.PERSISTENT;
if(cl.hasOption("e") && cl.hasOption("s")) {
    flags = CreateMode.EPHEMERAL_SEQUENTIAL;
} else if (cl.hasOption("e")) {
    flags = CreateMode.EPHEMERAL;
} else if (cl.hasOption("s")) {
    flags = CreateMode.PERSISTENT_SEQUENTIAL;
}
Tristan answered 18/2, 2015 at 21:15 Comment(2)
Thank you for such a great answer - maybe submit such as documentation bug against ZK? You deserve the credit!Turgot
update: the new -c switch is for "container" znodes: zookeeper.apache.org/doc/r3.5.1-alpha/api/org/apache/zookeeper/…Voice

© 2022 - 2024 — McMap. All rights reserved.