[jira] [Commented] (ZOOKEEPER-2384) Support atomic increment / decrement of znode value
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2384?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15638611#comment-15638611 ] Ted Yu commented on ZOOKEEPER-2384: --- Thanks for the suggestion, Nick. > Support atomic increment / decrement of znode value > --- > > Key: ZOOKEEPER-2384 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2384 > Project: ZooKeeper > Issue Type: Improvement >Reporter: Ted Yu > Labels: atomic > > Use case is to store reference count (integer type) in znode. > It is desirable to provide support for atomic increment / decrement of the > znode value. > Suggestion from Flavio: > {quote} > you can read the znode, keep the version of the znode, update the value, > write back conditionally. The condition for the setData operation to succeed > is that the version is the same that it read > {quote} > While the above is feasible, developer has to implement retry logic > him/herself. It is not easy to combine increment / decrement with other > operations using multi. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (ZOOKEEPER-2384) Support atomic increment / decrement of znode value
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2384?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15639919#comment-15639919 ] Jordan Zimmerman commented on ZOOKEEPER-2384: - FYI - Curator has a recipe to do this (http://curator.apache.org/curator-recipes/distributed-atomic-long.html) which is pretty complicated. Having native support would be nice. But, to do it would require that ZK have non-opaque data for the first time. It might be a can of worms if not done correctly. > Support atomic increment / decrement of znode value > --- > > Key: ZOOKEEPER-2384 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2384 > Project: ZooKeeper > Issue Type: Improvement >Reporter: Ted Yu > Labels: atomic > > Use case is to store reference count (integer type) in znode. > It is desirable to provide support for atomic increment / decrement of the > znode value. > Suggestion from Flavio: > {quote} > you can read the znode, keep the version of the znode, update the value, > write back conditionally. The condition for the setData operation to succeed > is that the version is the same that it read > {quote} > While the above is feasible, developer has to implement retry logic > him/herself. It is not easy to combine increment / decrement with other > operations using multi. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (ZOOKEEPER-2384) Support atomic increment / decrement of znode value
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2384?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15188132#comment-15188132 ] Flavio Junqueira commented on ZOOKEEPER-2384: - What I suggested isn't particularly hard to do, but it can be inefficient in the presence of contention. If there are many clients trying to do that, then they can keep stepping on each other and causing the conditional write to fail. > Support atomic increment / decrement of znode value > --- > > Key: ZOOKEEPER-2384 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2384 > Project: ZooKeeper > Issue Type: Improvement >Reporter: Ted Yu > > Use case is to store reference count (integer type) in znode. > It is desirable to provide support for atomic increment / decrement of the > znode value. > Suggestion from Flavio: > you can read the znode, keep the version of the znode, update the value, > write back conditionally. The condition for the setData operation to succeed > is that the version is the same that it read > While the above is feasible, developer has to implement retry logic > him/herself. It is not easy to combine increment / decrement with other > operations using multi. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (ZOOKEEPER-2384) Support atomic increment / decrement of znode value
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2384?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15188757#comment-15188757 ] Nick Hill commented on ZOOKEEPER-2384: -- How about: setData (e.g. empty) to increment, setAcl to decrement. You can get the current count by subtracting aversion from version in the returned stat, or similarly query the count just by using exists() So then Increment would also work in multi (but I don't think decrement since no acl) Could be an effective hack for some use cases (avoids contention retry issue) > Support atomic increment / decrement of znode value > --- > > Key: ZOOKEEPER-2384 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2384 > Project: ZooKeeper > Issue Type: Improvement >Reporter: Ted Yu > > Use case is to store reference count (integer type) in znode. > It is desirable to provide support for atomic increment / decrement of the > znode value. > Suggestion from Flavio: > you can read the znode, keep the version of the znode, update the value, > write back conditionally. The condition for the setData operation to succeed > is that the version is the same that it read > While the above is feasible, developer has to implement retry logic > him/herself. It is not easy to combine increment / decrement with other > operations using multi. -- This message was sent by Atlassian JIRA (v6.3.4#6332)