Uploaded image for project: 'ZooKeeper'
  1. ZooKeeper
  2. ZOOKEEPER-3221

WriteLock in recipes may get wrong child name as lock id

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Critical
    • Resolution: Unresolved
    • None
    • None
    • recipes
    • None
    • zookeeper-recipes-1.0

    Description

      recently i used WriteLock in my application, and get following Exception

      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)
      

      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 java.lang.IllegalArgumentException in final delete operation. 

      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);
                      }
                  }
      
              }
      

       

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              abacus Huo Zhu
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - 24h
                  24h
                  Remaining:
                  Remaining Estimate - 24h
                  24h
                  Logged:
                  Time Spent - Not Specified
                  Not Specified