zookeeper-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maoling <...@git.apache.org>
Subject [GitHub] zookeeper pull request #618: ZOOKEEPER-1011:fix Java Barrier Documentation e...
Date Tue, 11 Dec 2018 11:18:31 GMT
Github user maoling commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/618#discussion_r240568921
  
    --- Diff: zookeeper-docs/src/documentation/content/xdocs/zookeeperTutorial.xml ---
    @@ -177,58 +165,106 @@ a boolean flag that enables the process to set a watch. In the
code the flag is
              * @throws KeeperException
              * @throws InterruptedException
              */
    +        boolean enter() throws Exception {
    +            boolean readyPathExists = zk.exists(readyPath, watcher) != null;
     
    -        boolean enter() throws KeeperException, InterruptedException{
    -            zk.create(root + "/" + name, new byte[0], Ids.OPEN_ACL_UNSAFE,
    -                    CreateMode.EPHEMERAL_SEQUENTIAL);
    -            while (true) {
    -                synchronized (mutex) {
    -                    List&lt;String&gt; list = zk.getChildren(root, true);
    +            zk.create(ourPath, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
    +            return readyPathExists || internalEnter();
    +        }
     
    -                    if (list.size() &lt; size) {
    -                        mutex.wait();
    -                    } else {
    -                        return true;
    +        private synchronized boolean internalEnter() throws Exception {
    +            boolean result = true;
    +            List&lt;String&gt; list = zk.getChildren(barrierPath, false);
    +            do {
    +                if (list.size() >= size) {
    +                    try {
    +                        zk.create(readyPath, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    +                    } catch (KeeperException.NodeExistsException ignore) {
    +                        // ignore
    +                    }
    +                    break;
    +                } else {
    +                    if (!hasBeenNotified.get()) {
    +                        wait();
                         }
                     }
    -            }
    +            } while (false);
    --- End diff --
    
    @nameof
    you can test this code by printing some logs to verify the correctness(wrong) of what
you think(hahaha)


---

Mime
View raw message