Skip to content

Commit 5318010

Browse files
Trond NorbyeTrond Norbye
Trond Norbye
authored and
Trond Norbye
committed
"stats reset" should reset eviction counters as well
See: http://code.google.com/p/memcached/issues/detail?id=22
1 parent f5ea171 commit 5318010

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed

assoc.c

-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ void assoc_delete(const char *key, const size_t nkey) {
183183

184184
static volatile int do_run_maintenance_thread = 1;
185185

186-
extern pthread_mutex_t cache_lock;
187186
#define DEFAULT_HASH_BULK_MOVE 1
188187
int hash_bulk_move = DEFAULT_HASH_BULK_MOVE;
189188

items.c

+7
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ void item_init(void) {
4646
}
4747
}
4848

49+
void item_stats_reset(void) {
50+
pthread_mutex_lock(&cache_lock);
51+
memset(itemstats, 0, sizeof(itemstats_t) * LARGEST_ID);
52+
pthread_mutex_unlock(&cache_lock);
53+
}
54+
55+
4956
/* Get the next CAS id for a new item. */
5057
uint64_t get_cas_id(void) {
5158
static uint64_t cas_id = 0;

items.h

+2
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ void do_item_flush_expired(void);
2727

2828
item *do_item_get(const char *key, const size_t nkey);
2929
item *do_item_get_nocheck(const char *key, const size_t nkey);
30+
void item_stats_reset(void);
31+
extern pthread_mutex_t cache_lock;

memcached.c

+1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ static void stats_reset(void) {
164164
stats_prefix_clear();
165165
STATS_UNLOCK();
166166
threadlocal_stats_reset();
167+
item_stats_reset();
167168
}
168169

169170
static void settings_init(void) {

t/issue_22.t

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/perl
2+
3+
use strict;
4+
use Test::More tests => 84;
5+
use FindBin qw($Bin);
6+
use lib "$Bin/lib";
7+
use MemcachedTest;
8+
9+
my $server = new_memcached("-m 3");
10+
my $sock = $server->sock;
11+
my $value = "B"x66560;
12+
my $key = 0;
13+
14+
for ($key = 0; $key < 40; $key++) {
15+
print $sock "set key$key 0 0 66560\r\n$value\r\n";
16+
is (scalar <$sock>, "STORED\r\n", "stored key$key");
17+
}
18+
19+
my $first_stats = mem_stats($sock, "items");
20+
my $first_evicted = $first_stats->{"items:31:evicted"};
21+
# I get 1 eviction on a 32 bit binary, but 4 on a 64 binary..
22+
# Just check that I have evictions...
23+
isnt ($first_evicted, "0", "check evicted");
24+
25+
print $sock "stats reset\r\n";
26+
is (scalar <$sock>, "RESET\r\n", "Stats reset");
27+
28+
my $second_stats = mem_stats($sock, "items");
29+
my $second_evicted = $second_stats->{"items:31:evicted"};
30+
is ("0", $second_evicted, "check evicted");
31+
32+
for ($key = 40; $key < 80; $key++) {
33+
print $sock "set key$key 0 0 66560\r\n$value\r\n";
34+
is (scalar <$sock>, "STORED\r\n", "stored key$key");
35+
}
36+
37+
my $last_stats = mem_stats($sock, "items");
38+
my $last_evicted = $last_stats->{"items:31:evicted"};
39+
is ($last_evicted, "40", "check evicted");

0 commit comments

Comments
 (0)