Permalink
Browse files

"stats reset" should reset eviction counters as well

  • Loading branch information...
1 parent f5ea171 commit 53180103df1bbca1292a14ef96aab2e6a19e13cf Trond Norbye committed Mar 24, 2009
Showing with 49 additions and 1 deletion.
  1. +0 −1 assoc.c
  2. +7 −0 items.c
  3. +2 −0 items.h
  4. +1 −0 memcached.c
  5. +39 −0 t/issue_22.t
View
@@ -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;
View
@@ -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;
View
@@ -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;
View
@@ -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) {
View
@@ -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");

0 comments on commit 5318010

Please sign in to comment.