java在向ZooKeeper添加带空格的字符串时的奇怪行为
使用ZK 3.4.5和zkCli。我得到以下信息:
./zkCli.sh -server localhost:2181
Connecting to localhost:2181
Welcome to ZooKeeper!
JLine support is enabled
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0] create /test 100
Created /test
[zk: localhost:2181(CONNECTED) 1] create /test/spacesString "this string has spaces in it"
Created /test/spacesString
[zk: localhost:2181(CONNECTED) 2] get /test/spacesString
"this
cZxid = 0x9c220
ctime = Wed Mar 11 06:46:10 EDT 2015
mZxid = 0x9c220
mtime = Wed Mar 11 06:46:10 EDT 2015
[deleted rest of output here]
[zk: localhost:2181(CONNECTED) 3] set /test/spacesString "new value"
Command failed: java.lang.NumberFormatException: For input string: "value""
我尝试这种方法是因为here。 从这一点上,我认为我所尝试的应该是有效的。两个问题:
为什么第一个带空格的字符串不能正确创建
为什么后续的“set”抛出NumberFormatException
# 1 楼答案
它不起作用的原因是命令解析器使用空格来标记输入,并且没有正确处理字符串。这一问题在以下方面得到了解决:
ZOOKEEPER-1853-“zkCli.sh无法发出在数据中包含空格的CREATE命令”
根据JIRA,修复应该在3.4.7、3.5.2和3.6.0中