Looks like zookeeper CLI (zkCli.sh) does not support wildcard - I have not looked at the zookeeper code to figure out whether it is not possible design wise or whether I am missing something silly here.
What is the best way then to recursively delete nodes starting with a string. I would want to do something like:
./zkCli.sh rmr abc*
to delete all nodes that begin with abc. Is there any simpler way out other than using Java/Python or similar clients? Or in other words, is this achievable through only ZK CLI?
In order to perform ZooKeeper CLI operations, at very first we have to turn on our ZooKeeper server (“bin/zkServer.sh start”). Afterward, we will also turn on ZooKeeper client (“bin/zkCli.sh”). Hence, we can perform the following operation, once the client starts: Create znodes.
Start ZooKeeper with the zkServer.sh command. Connect to the local ZooKeeper server with the following command: bin/zkCli.sh -server 127.0. 0.1:2181.
To start the ZooKeeper server on a Linux system, use the Zookeeper/zookeeper/bin/zkServer.sh restart command from your Watson Explorer installation directory. On Microsoft Windows systems, use the Zookeeper\zookeeper\bin\zkServer. cmd command.
No, the current zkCli.sh
does not support wildcard removal (according to the implementation of
DeleteCommand and DeleteAllCommand, which are classes used by zkCli.sh
)
However, it is pretty straigh-forward to create a workaround, e.g. in Python with Kazoo. Checkout this gist, usage is: python zkDelAll.py /abc
Interestingly, *
is a valid path character, so you can create a znode with with a path /abc*
.
EDIT: The core implementation from the gist is the following:
from kazoo.client import KazooClient
zk = KazooClient(hosts='localhost:2181')
zk.start()
for child in zk.get_children('/'):
if child.startswith('abc'):
zk.delete('/' + child)
zk.stop()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With