Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zookeeper CLI - wildcard support

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?

like image 518
Vivek Madani Avatar asked Jul 31 '14 06:07

Vivek Madani


People also ask

How do I use ZooKeeper command line?

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.

Which of the following command is used to initialize the ZooKeeper?

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.

How do I start ZooKeeper service in Linux?

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.


1 Answers

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()
like image 115
Marcel Krcah Avatar answered Oct 19 '22 03:10

Marcel Krcah