diff options
author | Trond Norbye <trond.norbye@gmail.com> | 2011-07-18 19:11:48 +0200 |
---|---|---|
committer | Trond Norbye <trond.norbye@gmail.com> | 2011-07-18 19:11:48 +0200 |
commit | 44c0e100b826298a9d77ccc76ca0d49130fecf5c (patch) | |
tree | 9b6d8a78854dc7a325400eacac74ba9ca886d594 | |
parent | 6298b3978687530bc9d219b6ac707a1b681b2a46 (diff) | |
download | memcached-44c0e100b826298a9d77ccc76ca0d49130fecf5c.tar.gz |
Issue 183 - Reclaim items dead by flush_all
-rw-r--r-- | items.c | 4 | ||||
-rw-r--r-- | t/issue_183.t | 23 |
2 files changed, 26 insertions, 1 deletions
@@ -99,12 +99,14 @@ item *do_item_alloc(char *key, const size_t nkey, const int flags, const rel_tim /* do a quick check if we have any expired items in the tail.. */ int tries = 50; item *search; + rel_time_t oldest_live = settings.oldest_live; for (search = tails[id]; tries > 0 && search != NULL; tries--, search=search->prev) { if (search->refcount == 0 && - (search->exptime != 0 && search->exptime < current_time)) { + ((search->time < oldest_live) || // dead by flush + (search->exptime != 0 && search->exptime < current_time))) { it = search; /* I don't want to actually free the object, just steal * the item to avoid to grab the slab mutex twice ;-) diff --git a/t/issue_183.t b/t/issue_183.t new file mode 100644 index 0000000..94b956c --- /dev/null +++ b/t/issue_183.t @@ -0,0 +1,23 @@ +#!/usr/bin/perl + +use strict; +use Test::More tests => 5; +use FindBin qw($Bin); +use lib "$Bin/lib"; +use MemcachedTest; + +my $server = new_memcached(); +my $sock = $server->sock; +print $sock "set key 0 0 1\r\n1\r\n"; +is (scalar <$sock>, "STORED\r\n", "stored key"); +my $s1 = mem_stats($sock); +my $r1 = $s1->{"reclaimed"}; +is ($r1, "0", "Objects should not be reclaimed"); +sleep(2); +print $sock "flush_all\r\n"; +is (scalar <$sock>, "OK\r\n", "Cache flushed"); +print $sock "set key 0 0 1\r\n1\r\n"; +is (scalar <$sock>, "STORED\r\n", "stored key"); +my $s2 = mem_stats($sock); +my $r2 = $s2->{"reclaimed"}; +is ($r2, "1", "Objects should be reclaimed"); |