Changeset 573446
- Timestamp:
- 12/06/07 14:07:40 (4 years ago)
- Branches:
- master, ketama-compat
- Children:
- 0acb6c
- Parents:
- 7b1ed1
- git-author:
- Tomash Brechko <tomash.brechko@…> (12/04/07 12:23:24)
- git-committer:
- Tomash Brechko <tomash.brechko@…> (12/06/07 14:07:40)
- Files:
-
- 6 edited
-
Fast.xs (modified) (1 diff)
-
TODO (modified) (1 diff)
-
src/client.c (modified) (4 diffs)
-
src/client.h (modified) (3 diffs)
-
src/reply.kw (modified) (1 diff)
-
t/Cache-Memcached-Fast.t (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
Fast.xs
r77ace6 r573446 340 340 341 341 342 void 343 incr(memd, skey, ...) 344 Cache_Memcached_Fast * memd 345 SV * skey 346 ALIAS: 347 decr = CMD_DECR 348 PROTOTYPE: $$;$ 349 PREINIT: 350 const char *key; 351 STRLEN key_len; 352 arith_type arg = 1, result; 353 int noreply, res; 354 PPCODE: 355 if (items > 2 && SvOK(ST(2))) 356 arg = SvUV(ST(2)); 357 key = SvPV(skey, key_len); 358 noreply = (GIMME_V == G_VOID); 359 res = client_arith(memd, ix, key, key_len, arg, &result, noreply); 360 if (! noreply && res == MEMCACHED_SUCCESS) 361 { 362 dXSTARG; 363 364 /* 365 NOTE: arith_type is at least 64 bit, but Perl UV is 32 366 bit. 367 */ 368 PUSHu(result); 369 XSRETURN(1); 370 } 371 372 342 373 bool 343 374 delete(memd, skey, ...) -
TODO
refe05f r573446 25 25 26 26 - Use better rounding in flush_all(). 27 28 - Disable noreply in benchmark.pl before shipping. -
src/client.c
re083b4 r573446 50 50 51 51 52 struct arith_state 53 { 54 arith_type *result; 55 }; 56 57 58 static inline 59 void 60 arith_state_reset(struct arith_state *state, arith_type *result) 61 { 62 state->result = result; 63 } 64 65 52 66 struct command_state; 53 67 typedef int (*parse_reply_func)(struct command_state *state); … … 99 113 parse_reply_func parse_reply; 100 114 101 struct value_state value; 115 union 116 { 117 struct value_state value; 118 struct arith_state arith; 119 }; 102 120 }; 103 121 … … 681 699 return MEMCACHED_UNKNOWN; 682 700 } 701 } 702 703 704 static 705 int 706 parse_arith_reply(struct command_state *state) 707 { 708 int res, match_count; 709 arith_type arith; 710 711 switch (state->match) 712 { 713 case MATCH_NOT_FOUND: 714 res = swallow_eol(state, 0, 1); 715 716 return (res == MEMCACHED_SUCCESS ? MEMCACHED_FAILURE : res); 717 718 default: 719 return MEMCACHED_UNKNOWN; 720 721 case MATCH_0: case MATCH_1: case MATCH_2: case MATCH_3: case MATCH_4: 722 case MATCH_5: case MATCH_6: case MATCH_7: case MATCH_8: case MATCH_9: 723 break; 724 } 725 726 --state->pos; 727 728 res = sscanf(state->pos, FMT_ARITH "%n", &arith, &match_count); 729 if (res != 1) 730 return MEMCACHED_UNKNOWN; 731 732 state->pos += match_count; 733 734 res = swallow_eol(state, 1, 1); 735 if (res != MEMCACHED_SUCCESS) 736 return res; 737 738 *state->arith.result = arith; 739 740 return MEMCACHED_SUCCESS; 683 741 } 684 742 … … 1303 1361 1304 1362 int 1363 client_arith(struct client *c, enum arith_cmd_e cmd, 1364 const char *key, size_t key_len, 1365 arith_type arg, arith_type *result, int noreply) 1366 { 1367 int use_noreply = (noreply && c->noreply); 1368 size_t request_size = 1369 (sizeof(struct iovec) * (c->prefix_len ? 4 : 3) 1370 + sizeof(" 18446744073709551616 noreply\r\n")); 1371 struct command_state *state; 1372 struct iovec *buf_iov; 1373 char *buf; 1374 int server_index, res; 1375 1376 client_reset_for_command(c); 1377 1378 server_index = client_get_server_index(c, key, key_len); 1379 if (server_index == -1) 1380 return MEMCACHED_CLOSED; 1381 1382 state = &c->servers[server_index].cmd_state; 1383 command_state_reset(state, (c->prefix_len ? 2 : 1), 1, 1384 (use_noreply ? NULL : parse_arith_reply)); 1385 arith_state_reset(&state->arith, result); 1386 1387 res = iov_buf_extend(state, request_size); 1388 if (res != MEMCACHED_SUCCESS) 1389 return res; 1390 1391 switch (cmd) 1392 { 1393 case CMD_INCR: 1394 iov_push(state, STR_WITH_LEN("incr ")); 1395 break; 1396 1397 case CMD_DECR: 1398 iov_push(state, STR_WITH_LEN("decr ")); 1399 break; 1400 } 1401 if (c->prefix_len) 1402 iov_push(state, c->prefix, c->prefix_len); 1403 iov_push(state, (void *) key, key_len); 1404 1405 res = push_key(state, 0); 1406 if (res != MEMCACHED_SUCCESS) 1407 return res; 1408 1409 buf_iov = &state->iov_buf[state->iov_count]; 1410 iov_push(state, NULL, 0); 1411 buf = (char *) &state->iov_buf[state->iov_count]; 1412 buf_iov->iov_base = buf; 1413 buf_iov->iov_len = sprintf(buf, " " FMT_ARITH "%s\r\n", arg, 1414 (use_noreply ? " noreply" : "")); 1415 1416 return process_commands(c); 1417 1418 } 1419 1420 1421 int 1305 1422 client_delete(struct client *c, const char *key, size_t key_len, 1306 1423 delay_type delay, int noreply) -
src/client.h
r77ace6 r573446 19 19 enum set_cmd_e { CMD_SET, CMD_ADD, CMD_REPLACE, CMD_APPEND, CMD_PREPEND }; 20 20 21 enum arith_cmd_e { CMD_INCR, CMD_DECR }; 22 21 23 22 24 typedef unsigned int flags_type; … … 31 33 typedef size_t value_size_type; 32 34 #define FMT_VALUE_SIZE "%zu" 35 36 typedef unsigned long long arith_type; 37 #define FMT_ARITH "%llu" 33 38 34 39 … … 101 106 extern 102 107 int 108 client_arith(struct client *c, enum arith_cmd_e cmd, 109 const char *key, size_t key_len, 110 arith_type arg, arith_type *result, int noreply); 111 112 extern 113 int 103 114 client_delete(struct client *c, const char *key, size_t key_len, 104 115 delay_type delay, int noreply); -
src/reply.kw
r99b316 r573446 29 29 VALUE 30 30 VERSION 31 # incr and decr return non-negative number. 32 0 33 1 34 2 35 3 36 4 37 5 38 6 39 7 40 8 41 9 -
t/Cache-Memcached-Fast.t
r28082a r573446 6 6 # change 'tests => 1' to 'tests => last_test_to_print'; 7 7 8 use Test::More tests => 3 5;8 use Test::More tests => 39; 9 9 BEGIN { use_ok('Cache::Memcached::Fast') }; 10 10 … … 59 59 60 60 61 $memd->set("arith", 10); 62 is($memd->incr("arith", 5), 15); 63 is($memd->decr("arith"), 14); 64 is($memd->get("arith"), 14); 65 66 61 67 $res1 = $memd->get_multi("key_no_such_key", "key1", "key_no_such_key", 62 68 "key2", "key_no_such_key", "key_no_such_key", … … 87 93 ok(1); 88 94 ok(1); 95 ok(1); 89 96 } else { 90 97 my $memd_noreply = Cache::Memcached::Fast->new({ … … 96 103 97 104 $memd_noreply->flush_all; 105 98 106 $memd_noreply->add("k", "v"); 99 107 $memd_noreply->set("k", "v"); … … 104 112 $memd_noreply->delete("k"); 105 113 is($memd_noreply->get("k"), undef); 114 115 $memd_noreply->set("arith", 10); 116 $memd_noreply->incr("arith", 5); 117 $memd_noreply->decr("arith"); 118 is($memd_noreply->get("arith"), 14); 119 106 120 $memd_noreply->flush_all; 107 121 }
Note: See TracChangeset
for help on using the changeset viewer.
