[emiller@imvu.com: [PATCH] "incr" supports wraparound]

Paul Lindner lindner at inuus.com
Wed Aug 22 04:21:23 UTC 2007


Evan and I sat down and discussed his patch at the Hackathon.  The
behavior when > 2^31 was pretty stupid in the implementation.
(basically it croaks parsing the negative sign)

So... Given that protocol.txt says that overflow is not defined I went
ahead and committed the patch.

I thought about providing a command line switch of configure option to
turn off the new behavior, but it doesn't seem worth it.

If you really, really, really need the error on 2^31 behavior feel
free to tweak the code or provide a patch with test cases for each
case.

Thanks
On Tue, Aug 21, 2007 at 09:05:06PM -0700, Evan Miller wrote:

> From: Evan Miller <emiller at imvu.com>
> Date: Thu, 16 Aug 2007 17:06:02 -0700
> Organization: IMVU, Inc.
> X-Complaints-To: usenet at sea.gmane.org
> X-Gmane-NNTP-Posting-Host: dsl253-070-162.sfo1.dsl.speakeasy.net
> X-Virus-Checked: Checked by ClamAV on mail.danga.com
> Subject: [PATCH] "incr" supports wraparound
> 
> Currently Memcached gives an error when incrementing large counters:
> 
> set foobar 0 0 10
> 2147483647
> STORED
> incr foobar 1
> 2147483648
> incr foobar 1
> CLIENT_ERROR cannot increment or decrement non-numeric value
> 
> I believe this is a bug. Attached is a patch to make counters wrap
> around the 2**32 mark, similar to counters in routers. New behavior:
> 
> set foobar 0 0 10
> 4294967294
> STORED
> incr foobar 1
> 4294967295
> incr foobar 1
> 0
> 
> A CLIENT_ERROR will continue to be returned if a value above 2**32 is
> incremented, but the "incr" command will never push the value over that
> mark.
> 
> A future version of Memcached should probably use a 64-bit counter
> instead, but the 32-bit limit is in line with the existing docs. ("The
> data for the item is treated as decimal representation of a 32-bit
> unsigned integer.")
> 
> The patch also adds "const" keywords to arguments of do_add_delta and
> mt_add_delta, to be consistent with the header file.
> 
> Documentation and tests have been updated.
> 
> Evan Miller
> IMVU, Inc.
> 
> 
> 

-- 
Paul Lindner        ||||| | | | |  |  |  |   |   |
lindner at inuus.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.danga.com/pipermail/memcached/attachments/20070821/23bbd8b2/attachment.pgp


More information about the memcached mailing list