diff options
author | Trond Norbye <Trond.Norbye@sun.com> | 2009-03-24 20:59:47 +0100 |
---|---|---|
committer | Trond Norbye <Trond.Norbye@sun.com> | 2009-03-24 20:59:47 +0100 |
commit | 53180103df1bbca1292a14ef96aab2e6a19e13cf (patch) | |
tree | 63dfe5d5f745e44c716b2d41ee2186916f384852 | |
parent | f5ea1711289c360c3be1e630f6ccfc12a9afa417 (diff) | |
download | memcached-53180103df1bbca1292a14ef96aab2e6a19e13cf.tar.gz |
"stats reset" should reset eviction counters as well
See: http://code.google.com/p/memcached/issues/detail?id=22
-rw-r--r-- | assoc.c | 1 | ||||
-rw-r--r-- | items.c | 7 | ||||
-rw-r--r-- | items.h | 2 | ||||
-rw-r--r-- | memcached.c | 1 | ||||
-rw-r--r-- | t/issue_22.t | 39 |
5 files changed, 49 insertions, 1 deletions
@@ -183,7 +183,6 @@ void assoc_delete(const char *key, const size_t nkey) { static volatile int do_run_maintenance_thread = 1; -extern pthread_mutex_t cache_lock; #define DEFAULT_HASH_BULK_MOVE 1 int hash_bulk_move = DEFAULT_HASH_BULK_MOVE; @@ -46,6 +46,13 @@ void item_init(void) { } } +void item_stats_reset(void) { + pthread_mutex_lock(&cache_lock); + memset(itemstats, 0, sizeof(itemstats_t) * LARGEST_ID); + pthread_mutex_unlock(&cache_lock); +} + + /* Get the next CAS id for a new item. */ uint64_t get_cas_id(void) { static uint64_t cas_id = 0; @@ -27,3 +27,5 @@ void do_item_flush_expired(void); item *do_item_get(const char *key, const size_t nkey); item *do_item_get_nocheck(const char *key, const size_t nkey); +void item_stats_reset(void); +extern pthread_mutex_t cache_lock; diff --git a/memcached.c b/memcached.c index 654a93e..a3f46aa 100644 --- a/memcached.c +++ b/memcached.c @@ -164,6 +164,7 @@ static void stats_reset(void) { stats_prefix_clear(); STATS_UNLOCK(); threadlocal_stats_reset(); + item_stats_reset(); } static void settings_init(void) { diff --git a/t/issue_22.t b/t/issue_22.t new file mode 100644 index 0000000..f498c45 --- /dev/null +++ b/t/issue_22.t @@ -0,0 +1,39 @@ +#!/usr/bin/perl + +use strict; +use Test::More tests => 84; +use FindBin qw($Bin); +use lib "$Bin/lib"; +use MemcachedTest; + +my $server = new_memcached("-m 3"); +my $sock = $server->sock; +my $value = "B"x66560; +my $key = 0; + +for ($key = 0; $key < 40; $key++) { + print $sock "set key$key 0 0 66560\r\n$value\r\n"; + is (scalar <$sock>, "STORED\r\n", "stored key$key"); +} + +my $first_stats = mem_stats($sock, "items"); +my $first_evicted = $first_stats->{"items:31:evicted"}; +# I get 1 eviction on a 32 bit binary, but 4 on a 64 binary.. +# Just check that I have evictions... +isnt ($first_evicted, "0", "check evicted"); + +print $sock "stats reset\r\n"; +is (scalar <$sock>, "RESET\r\n", "Stats reset"); + +my $second_stats = mem_stats($sock, "items"); +my $second_evicted = $second_stats->{"items:31:evicted"}; +is ("0", $second_evicted, "check evicted"); + +for ($key = 40; $key < 80; $key++) { + print $sock "set key$key 0 0 66560\r\n$value\r\n"; + is (scalar <$sock>, "STORED\r\n", "stored key$key"); +} + +my $last_stats = mem_stats($sock, "items"); +my $last_evicted = $last_stats->{"items:31:evicted"}; +is ($last_evicted, "40", "check evicted"); |