[ 
https://issues.apache.org/jira/browse/CURATOR-447?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16361410#comment-16361410
 ] 

ASF GitHub Bot commented on CURATOR-447:
----------------------------------------

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


> TreeCache: Improve memory usage and concurrent update logic
> -----------------------------------------------------------
>
>                 Key: CURATOR-447
>                 URL: https://issues.apache.org/jira/browse/CURATOR-447
>             Project: Apache Curator
>          Issue Type: Improvement
>          Components: Recipes
>    Affects Versions: 3.3.0, 2.12.0
>            Reporter: Nick Hill
>            Priority: Minor
>              Labels: performance
>
> Jira https://issues.apache.org/jira/browse/CURATOR-374 reduced per-node 
> memory usage in {{TreeCache}}. It can be improved further via removal of the 
> {{nodeState}} field - its {{LIVE}} state corresponds exactly to the adjacent 
> {{childData}} field being non-null, and a sentinel {{ChildData}} value can be 
> used for the {{DEAD}} state. This simplification also reduces the room for 
> bugs and state inconsistencies.
> Other improvements included:
> * A further simplification to have {{TreeNode}} extend {{AtomicReference}}, 
> which obviates the need for an explicit {{childData}} field
> * More robust cache update logic (in get-children and get-data event 
> callbacks)
> * Avoid overhead of incrementing/decrementing the {{outstandingOps}} atomic 
> integer post-initialization



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to