是否可以通过Zookeeper CLI读取带有空格的znode?
我在区域下有2个值("us-west 1"和"us-east")
[zk: localhost:2181(CONNECTED) 11] get /regions/
us-west 1 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
但不是"美西1号"
[zk: localhost:2181(CONNECTED) 11] get /regions/us-west 1
Node does not exist: /regions/us-west
我尝试了"%20"、""、"+"等选项,但没有任何效果。
3条答案
按热度按时间rekjcdws1#
请尝试zookeepercli,如下所示:
cetgtptt2#
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):Since they are splitting by a " ", unless you discover a way to overcome that
split
call by some sort of escaping when calling theget
command, you won't be able to retrieve those nodes using this client. The code above interprets your1
in aget
call as if it were thewatch
parameter, as you can see in theget
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.
hkmswyz63#
JIRA中有一个关于此功能的未决问题,但解决方法是在命令行上传递命令,而不是使用交互式控制台: