Changeset 619
- Timestamp:
- 10/03/07 20:45:31 (1 year ago)
- Files:
-
- trunk/server/ChangeLog (modified) (1 diff)
- trunk/server/doc/protocol.txt (modified) (3 diffs)
- trunk/server/memcached.c (modified) (6 diffs)
- trunk/server/memcached.h (modified) (2 diffs)
- trunk/server/t/incrdecr.t (modified) (2 diffs)
- trunk/server/thread.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/server/ChangeLog
r618 r619 12 12 * Fix for do_item_cachedump() which was returning 13 13 an incorrect timestamp. 14 15 * Switch to unsigned 64-bit increment/decrement counters 16 from Evan Miller and Dusgtin Sallings. 14 17 15 18 2007-08-21 Paul Lindner <lindner@inuus.com> trunk/server/doc/protocol.txt
r615 r619 263 263 Commands "incr" and "decr" are used to change data for some item 264 264 in-place, incrementing or decrementing it. The data for the item is 265 treated as decimal representation of a 32-bit unsigned integer. If the265 treated as decimal representation of a 64-bit unsigned integer. If the 266 266 current data value does not conform to such a representation, the 267 267 commands behave as if the value were 0. Also, the item must already … … 280 280 281 281 - <value> is the amount by which the client wants to increase/decrease 282 the item. It is a decimal representation of a 32-bit unsigned integer.282 the item. It is a decimal representation of a 64-bit unsigned integer. 283 283 284 284 The response will be one of: … … 290 290 291 291 Note that underflow in the "decr" command is caught: if a client tries 292 to decrease the value below 0, the new value will be 0. Overflow in the293 "incr" command will wrap around the 32bit mark.292 to decrease the value below 0, the new value will be 0. Overflow in 293 the "incr" command will wrap around the 64 bit mark. 294 294 295 295 Note also that decrementing a number such that it loses length isn't trunk/server/memcached.c
r615 r619 1259 1259 } 1260 1260 1261 static void process_arithmetic_command(conn *c, token_t *tokens, const size_t ntokens, const intincr) {1262 char temp[ 32];1261 static void process_arithmetic_command(conn *c, token_t *tokens, const size_t ntokens, const bool incr) { 1262 char temp[sizeof("18446744073709551615")]; 1263 1263 item *it; 1264 unsigned int delta;1264 int64_t delta; 1265 1265 char *key; 1266 1266 size_t nkey; … … 1289 1289 } 1290 1290 1291 delta = strto ul(tokens[2].value, NULL, 10);1291 delta = strtoll(tokens[2].value, NULL, 10); 1292 1292 1293 1293 if(errno == ERANGE) { … … 1316 1316 * returns a response string to send back to the client. 1317 1317 */ 1318 char *do_add_delta(item *it, const int incr, const unsigned int delta, char *buf) {1318 char *do_add_delta(item *it, const bool incr, const int64_t delta, char *buf) { 1319 1319 char *ptr; 1320 uint32_t value;1320 int64_t value; 1321 1321 int res; 1322 1322 … … 1324 1324 while ((*ptr != '\0') && (*ptr < '0' && *ptr > '9')) ptr++; // BUG: can't be true 1325 1325 1326 value = strtoul (ptr, NULL, 10);1326 value = strtoull(ptr, NULL, 10); 1327 1327 1328 1328 if(errno == ERANGE) { … … 1330 1330 } 1331 1331 1332 if (incr != 0)1332 if (incr) 1333 1333 value += delta; 1334 1334 else { … … 1336 1336 else value -= delta; 1337 1337 } 1338 s nprintf(buf, 32, "%u", value);1338 sprintf(buf, "%llu", value); 1339 1339 res = strlen(buf); 1340 1340 if (res + 2 > it->nbytes) { /* need to realloc */ trunk/server/memcached.h
r603 r619 223 223 char *do_defer_delete(item *item, time_t exptime); 224 224 void do_run_deferred_deletes(void); 225 char *do_add_delta(item *item, int incr, const unsigned int delta, char *buf);225 char *do_add_delta(item *item, const bool incr, const int64_t delta, char *buf); 226 226 int do_store_item(item *item, int comm); 227 227 conn *conn_new(const int sfd, const int init_state, const int event_flags, const int read_buffer_size, const bool is_udp, struct event_base *base); … … 254 254 255 255 /* Lock wrappers for cache functions that are called from main loop. */ 256 char *mt_add_delta(item *item, const int incr, const unsigned int delta, char *buf);256 char *mt_add_delta(item *item, const int incr, const int64_t delta, char *buf); 257 257 void mt_assoc_move_next_bucket(void); 258 258 conn *mt_conn_from_freelist(void); trunk/server/t/incrdecr.t
r608 r619 2 2 3 3 use strict; 4 use Test::More tests => 1 6;4 use Test::More tests => 17; 5 5 use FindBin qw($Bin); 6 6 use lib "$Bin/lib"; … … 31 31 is(scalar <$sock>, "0\r\n", "- 5 = 0"); 32 32 33 print $sock "incr num ".(2**32-2)."\r\n";34 is(scalar <$sock>, (2**32-2)."\r\n", "+ ".(2**32-2)." = ".(2**32-2));33 printf $sock "set num 0 0 10\r\n4294967296\r\n"; 34 is(scalar <$sock>, "STORED\r\n", "stored 2**32"); 35 35 36 36 print $sock "incr num 1\r\n"; 37 is(scalar <$sock>, (2**32-1)."\r\n", "+ 1 = ".(2**32-1)); 37 is(scalar <$sock>, "4294967297\r\n", "4294967296 + 1 = 4294967297"); 38 39 printf $sock "set num 0 0 %d\r\n18446744073709551615\r\n", length("18446744073709551615"); 40 is(scalar <$sock>, "STORED\r\n", "stored 2**64-1"); 38 41 39 42 print $sock "incr num 1\r\n"; 40 is(scalar <$sock>, "0\r\n", " + 1 = 0");43 is(scalar <$sock>, "0\r\n", "(2**64 - 1) + 1 = 0"); 41 44 42 45 print $sock "decr bogus 5\r\n"; trunk/server/thread.c
r608 r619 463 463 * Does arithmetic on a numeric item value. 464 464 */ 465 char *mt_add_delta(item *item, int incr, const unsigned int delta, char *buf) {465 char *mt_add_delta(item *item, int incr, const int64_t delta, char *buf) { 466 466 char *ret; 467 467
