Skip to content

Commit

Permalink
Issue 183 - Reclaim items dead by flush_all
Browse files Browse the repository at this point in the history
  • Loading branch information
trondn committed Jul 18, 2011
1 parent 6298b39 commit 44c0e10
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion items.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;-)
Expand Down
23 changes: 23 additions & 0 deletions t/issue_183.t
Original file line number Diff line number Diff line change
@@ -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");

0 comments on commit 44c0e10

Please sign in to comment.