Github user dragonsinth commented on a diff in the pull request:

    https://github.com/apache/curator/pull/250#discussion_r167675994
  
    --- Diff: 
curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
 ---
    @@ -436,41 +432,28 @@ else if ( event.getResultCode() == 
KeeperException.Code.NONODE.intValue() )
                 case GET_DATA:
                     if ( event.getResultCode() == 
KeeperException.Code.OK.intValue() )
                     {
    -                    ChildData toPublish = new ChildData(event.getPath(), 
newStat, event.getData());
    -                    ChildData oldChildData;
    -                    if ( cacheData )
    -                    {
    -                        oldChildData = childDataUpdater.getAndSet(this, 
toPublish);
    -                    }
    -                    else
    -                    {
    -                        oldChildData = childDataUpdater.getAndSet(this, 
new ChildData(event.getPath(), newStat, null));
    -                    }
    -
    -                    boolean added;
    -                    if (parent == null) {
    -                        // We're the singleton root.
    -                        added = nodeStateUpdater.getAndSet(this, 
NodeState.LIVE) != NodeState.LIVE;
    -                    } else {
    -                        added = nodeStateUpdater.compareAndSet(this, 
NodeState.PENDING, NodeState.LIVE);
    -                        if (!added) {
    -                            // Ordinary nodes are not allowed to 
transition from dead -> live;
    -                            // make sure this isn't a delayed response 
that came in after death.
    -                            if (nodeState != NodeState.LIVE) {
    -                                return;
    -                            }
    +                    String eventPath = event.getPath();
    +                    ChildData toPublish = new ChildData(eventPath, 
newStat, event.getData());
    +                    ChildData toUpdate = cacheData ? toPublish : new 
ChildData(eventPath, newStat, null);
    +                    while (true) {
    +                        final ChildData oldChildData = childData;
    +                        if ( (isLive(oldChildData) && newStat.getMzxid() 
<= oldChildData.getStat().getMzxid())
    +                                // Ordinary nodes are not allowed to 
transition from dead -> live;
    +                                // make sure this isn't a delayed response 
that came in after death.
    +                                || (parent != null && oldChildData == 
DEAD) ) {
    +                            break;
    --- End diff --
    
    Can we break up these cases for clarity?
    
    ```
                            final ChildData oldChildData = childData;
                            // Ignore this event if we've already processed a 
newer update for this node.
                            if ( (isLive(oldChildData) && newStat.getMzxid() <= 
oldChildData.getStat().getMzxid()) )
                            {
                                break;
                            }
                            // Non-root nodes are not allowed to transition 
from dead -> live;
                            // make sure this isn't a delayed response that 
came in after death.
                            if ( parent != null && oldChildData == DEAD )
                            {
                                break;
                            }
    ```



---

Reply via email to