Github user dragonsinth commented on a diff in the pull request: https://github.com/apache/curator/pull/250#discussion_r167677124 --- 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; } - } - - if ( added ) - { - publishEvent(TreeCacheEvent.Type.NODE_ADDED, toPublish); - } - else - { - if ( oldChildData == null || oldChildData.getStat().getMzxid() != newStat.getMzxid() ) + if ( childDataUpdater.compareAndSet(this, oldChildData, toUpdate) ) { - publishEvent(TreeCacheEvent.Type.NODE_UPDATED, toPublish); + if ( !isLive(oldChildData) ) + { + publishEvent(TreeCacheEvent.Type.NODE_ADDED, toPublish); + } + else if ( oldChildData.getStat().getMzxid() != newStat.getMzxid() ) + { + publishEvent(TreeCacheEvent.Type.NODE_UPDATED, toPublish); + } + break; --- End diff -- I think the second check is now superfluous since we checked above. ``` if ( childDataUpdater.compareAndSet(this, oldChildData, toUpdate) ) { publishEvent(isLive(oldChildData) ? TreeCacheEvent.Type.NODE_UPDATED : TreeCacheEvent.Type.NODE_ADDED, toPublish); break; } ```
---