[
https://issues.apache.org/jira/browse/CURATOR-151?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14162847#comment-14162847
]
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_r18558577
--- Diff:
curator-recipes/src/main/java/org/apache/curator/framework/recipes/shared/SharedValue.java
---
@@ -165,14 +153,20 @@ public boolean trySetValue(byte[] newValue) throws
Exception
* was not successful, {@link #getValue()} will return the updated
value
* @throws Exception ZK errors, interruptions, etc.
*/
- public boolean trySetValue(VersionedValue<byte[]> newValue) throws
Exception
+ public boolean trySetValue(VersionedValue<byte[]> previous, byte[]
newValue) throws Exception
{
Preconditions.checkState(state.get() == State.STARTED, "not
started");
+ VersionedValue<byte[]> current = currentValue.get();
+ if ( previous.getVersion() != current.getVersion() ||
!Arrays.equals(previous.getValue(), current.getValue()) )
+ {
+ return false;
+ }
+
try
{
-
client.setData().withVersion(newValue.getVersion()).forPath(path,
newValue.getValue());
- currentValue.set(new
VersionedValue<byte[]>(newValue.getVersion() + 1,
Arrays.copyOf(newValue.getValue(), newValue.getValue().length)));
+ Stat result =
client.setData().withVersion(previous.getVersion()).forPath(path, newValue);
+ updateValue(result.getVersion(), Arrays.copyOf(newValue,
newValue.length));
--- End diff --
I don't think I understand. Which method would you rename, and what kind
of name would you think? Do you mean that the 2-arg version should be named
something like "compareAndSetValue"?
> 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)