From 3e4332bd717ec78a6e2461ca4ff0cf3caff866e9 Mon Sep 17 00:00:00 2001 From: Trond Norbye Date: Wed, 10 Nov 2010 17:48:47 -0800 Subject: Issue 140 - Fix age for items stats --- items.c | 20 +++++++++++++++++++- t/issue_140.t | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 t/issue_140.t diff --git a/items.c b/items.c index e7f01ea..f92fc2e 100644 --- a/items.c +++ b/items.c @@ -401,7 +401,25 @@ void do_item_stats(ADD_STAT add_stats, void *c) { char key_str[STAT_KEY_LEN]; char val_str[STAT_VAL_LEN]; int klen = 0, vlen = 0; - + int search = 50; + while (search > 0 && + tails[i] != NULL && + ((settings.oldest_live != 0 && /* Item flushd */ + settings.oldest_live <= current_time && + tails[i]->time <= settings.oldest_live) || + (tails[i]->exptime != 0 && /* and not expired */ + tails[i]->exptime < current_time))) { + --search; + if (tails[i]->refcount == 0) { + do_item_unlink(tails[i]); + } else { + break; + } + } + if (tails[i] == NULL) { + /* We removed all of the items in this slab class */ + continue; + } APPEND_NUM_FMT_STAT(fmt, i, "number", "%u", sizes[i]); APPEND_NUM_FMT_STAT(fmt, i, "age", "%u", tails[i]->time); APPEND_NUM_FMT_STAT(fmt, i, "evicted", diff --git a/t/issue_140.t b/t/issue_140.t new file mode 100644 index 0000000..2c6151e --- /dev/null +++ b/t/issue_140.t @@ -0,0 +1,37 @@ +#!/usr/bin/perl + +use strict; +use Test::More tests => 7; +use FindBin qw($Bin); +use lib "$Bin/lib"; +use MemcachedTest; + +my $server = new_memcached(); +my $sock = $server->sock; + +print $sock "set a 0 0 1\r\na\r\n"; +is (scalar <$sock>, "STORED\r\n", "stored key"); + +my $stats = mem_stats($sock, "items"); +my $age = $stats->{"items:1:age"}; +isnt ($age, "0", "Age should not be zero"); + +print $sock "flush_all\r\n"; +is (scalar <$sock>, "OK\r\n", "items flushed"); + +my $stats = mem_stats($sock, "items"); +my $age = $stats->{"items:1:age"}; +is ($age, undef, "all should be gone"); + +print $sock "set a 0 1 1\r\na\r\n"; +is (scalar <$sock>, "STORED\r\n", "stored key"); + +my $stats = mem_stats($sock, "items"); +my $age = $stats->{"items:1:age"}; +isnt ($age, "0", "Age should not be zero"); + +sleep(2); + +my $stats = mem_stats($sock, "items"); +my $age = $stats->{"items:1:age"}; +is ($age, undef, "all should be gone"); -- cgit v1.2.1