Zookeeper CLI -读取带空格的Znode

mjqavswn  于 2022-12-09  发布在  Apache
关注(0)|答案(3)|浏览(207)

是否可以通过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"、""、"+"等选项,但没有任何效果。

rekjcdws

rekjcdws1#

请尝试zookeepercli,如下所示:

$ 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**是免费和开源的。免责声明:我是这个工具的作者。
cetgtptt

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):

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.

hkmswyz6

hkmswyz63#

JIRA中有一个关于此功能的未决问题,但解决方法是在命令行上传递命令,而不是使用交互式控制台:

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

相关问题