curator-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CURATOR-151) SharedValue has limited utility but can be improved
Date Thu, 09 Oct 2014 08:51:34 GMT

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

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

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

    https://github.com/apache/curator/pull/47#discussion_r18633269
  
    --- Diff: curator-recipes/src/main/java/org/apache/curator/framework/recipes/shared/SharedValue.java
---
    @@ -184,6 +178,25 @@ public boolean trySetValue(VersionedValue<byte[]> newValue)
throws Exception
             return false;
         }
     
    +    private void updateValue(int version, byte[] bytes)
    +    {
    +        while (true)
    +        {
    +            VersionedValue<byte[]> current = currentValue.get();
    +            if (current.getVersion() >= version)
    +            {
    +                // A newer version was concurrently set.
    +                return;
    +            }
    +            if ( currentValue.compareAndSet(current, new VersionedValue<byte[]>(version,
bytes)) )
    +            {
    +                // Successfully set.
    +                return;
    +            }
    +            // Lost a race, retry.
    +        }
    +    }
    +
         /**
    --- End diff --
    
    Ah, gotcha.  So this isn't new behavior -- this is just a standard compare-and-set loop
that replaces the synchronized keyword.  It's not round tripping to the server multiple times.
 There's still only one attempt to set the server value, and if it fails the calling methods
return false.  This is just atomically setting currentValue.  We could replace the loop with
a synchronized block, but performance would be worse.


> SharedValue has limited utility but can be improved
> ---------------------------------------------------
>
>                 Key: CURATOR-151
>                 URL: https://issues.apache.org/jira/browse/CURATOR-151
>             Project: Apache Curator
>          Issue Type: Improvement
>          Components: Recipes
>    Affects Versions: 2.6.0
>            Reporter: Jordan Zimmerman
>            Assignee: Jordan Zimmerman
>             Fix For: 2.7.0
>
>
> Currently, SharedValue has limited utility as the internally managed version is always
used for trySetValue. A good improvement would be a) add an API to get the current value AND
current version and b) add an alternate trySetValue that takes a new value AND an expected
version. 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message