[ https://issues.apache.org/jira/browse/ZOOKEEPER-3221?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
maoling reassigned ZOOKEEPER-3221: ---------------------------------- Assignee: maoling > WriteLock in recipes may get wrong child name as lock id > -------------------------------------------------------- > > Key: ZOOKEEPER-3221 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-3221 > Project: ZooKeeper > Issue Type: Bug > Components: recipes > Environment: zookeeper-recipes-1.0 > Reporter: Huo Zhu > Assignee: maoling > Priority: Critical > Original Estimate: 24h > Remaining Estimate: 24h > > recently i used WriteLock in my application, and get following Exception > {code:java} > Exception in thread "produce 1" java.lang.IllegalArgumentException: Path must > start with / character > at org.apache.zookeeper.common.PathUtils.validatePath(PathUtils.java:51) > at org.apache.zookeeper.ZooKeeper.delete(ZooKeeper.java:851) > at org.apache.zookeeper.recipes.lock.WriteLock$1.execute(WriteLock.java:118) > at org.apache.zookeeper.recipes.lock.WriteLock$1.execute(WriteLock.java:1) > at org.apache.zookeeper.recipes.lock.WriteLock.unlock(WriteLock.java:122) > {code} > the following function is called when tried to lock, used an existed child > node name as inner lock id, which may be conflict with another lock user, and > at the same time the lock id is just the node name , no with prefix path, > causing{color:#FF0000} java.lang.IllegalArgumentException{color} in final > delete operation. > {code:java} > private void findPrefixInChildren(String prefix, ZooKeeper zookeeper, String > dir) throws KeeperException, InterruptedException { > List<String> names = zookeeper.getChildren(dir, false); > for (String name : names) { > if (name.startsWith(prefix)) { > id = name; > if (LOG.isDebugEnabled()) { > LOG.debug("Found id created last time: " + id); > } > break; > } > } > if (id == null) { > id = zookeeper.create(dir + "/" + prefix, data, getAcl(), > EPHEMERAL_SEQUENTIAL); > if (LOG.isDebugEnabled()) { > LOG.debug("Created id: " + id); > } > } > } > {code} > -- This message was sent by Atlassian JIRA (v7.6.3#76005)