[SPY-77] incr/decr can overflow the long return type Created: 07/Feb/12  Updated: 04/Oct/12  Resolved: 04/Oct/12

Status: Resolved
Project: Spymemcached Java Client
Component/s: library
Affects Version/s: 2.7.3
Fix Version/s: 2.8.2
Security Level: Public

Type: Bug Priority: Major
Reporter: Mike Wiederhold Assignee: Mike Wiederhold
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment: All

I'm currently using the Couchbase Server 2.0 Developer Preview, but I think what I am seeing is the same as Membase Server.
I'm using spymemcached in Java and I'd like to be able to increase a numeric key and return the new value. This works when the numbers are small as the result of the asyncIncr method fits into a Long, but when it doesn't Java overflows the Long and I end up with negative numbers. I can retrieve the correct (positive) value by doing a normal get as it returns the value as a String.
Is it possible to retrieve the result of asyncIncr as a String as to prevent this problem?
I'd also like to ask why negative numbers aren't supported and if there is a standard way to achieve this functionality by using an offset in my application code?


Comment by Mike Wiederhold [ 04/Oct/12 ]
This is not an issue. Java doesn't have a good way to represent an unsigned long so a large cas value means that it will be represented as a negative signed long.
Generated at Wed Dec 17 14:25:20 CST 2014 using JIRA 5.2.4#845-sha1:c9f4cc41abe72fb236945343a1f485c2c844dac9.