Baskar
Baskar

Reputation: 1645

Zookeeper CLI - Read Znode with space

Is it possible to read a znode with a space in it through Zookeeper CLI?

I've 2 values under regions ('us-west 1' and 'us-east')

 [zk: localhost:2181(CONNECTED) 11] get /regions/
 us-west 1   us-east 

I can read 'us-east'.

[zk: localhost:2181(CONNECTED) 11] get /regions/us-east
null
cZxid = 0xa
ctime = Tue Jul 10 12:41:49 IST 2012
mZxid = 0xa
mtime = Tue Jul 10 12:41:49 IST 2012
pZxid = 0x1b
cversion = 9
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 0
numChildren = 9

But not 'us-west 1'

[zk: localhost:2181(CONNECTED) 11] get /regions/us-west 1
Node does not exist: /regions/us-west 

I tried options like '%20', '\ ' , '+' etc.. for the space, but nothing worked.

Upvotes: 3

Views: 9190

Answers (3)

malthe
malthe

Reputation: 1449

There's an open issue in JIRA for this feature, but a workaround is to pass a command on the command-line instead of using the interactive console:

$ zkCli.sh -c get "/regions/us-west 1"

Upvotes: 0

Shlomi Noach
Shlomi Noach

Reputation: 9414

Please try zookeepercli, as follows:

$ zookeepercli --servers srv1,srv2,srv3 -c create "/demo_only 1" "the value"
$ zookeepercli --servers srv1,srv2,srv3 -c get "/demo_only 1" 
the value

zookeepercli is free and open source. Disclaimer: I'm author of this tool.

Upvotes: 8

Viccari
Viccari

Reputation: 9318

It looks like you will not be able to do that from the ZK command-line client. The Zookeeper Java client (which is the one you are using, probably) separates commands (e.g. get) from their parameters (e.g. /regions/us-west 1 in your case) by parsing whitespace characters, as you can see in the code provided with the client (e.g. zookeeper-3.3.5\src\java\main\org\apache\zookeeper\ZooKeeperMain.java):

public boolean parseCommand( String cmdstring ) {
    String[] args = cmdstring.split(" ");
    if (args.length == 0){
        return false;
    }
    command = args[0];
    cmdArgs = Arrays.asList(args);
    return true;
}

Since they are splitting by a " ", unless you discover a way to overcome that split call by some sort of escaping when calling the get command, you won't be able to retrieve those nodes using this client. The code above interprets your 1 in a get call as if it were the watch parameter, as you can see in the get command syntax:

get path [watch]

I recommend you to use a different character, like '_' for example, instead of the whitespace on the znodes naming. If that is not an option, you will either need to modify the ZK Java client yourself, or use another client.

Upvotes: 3

Related Questions