diff --git a/items.c b/items.c index 19e2e7167e..ab588db4d5 100644 --- a/items.c +++ b/items.c @@ -106,7 +106,7 @@ item *do_item_alloc(char *key, const size_t nkey, const int flags, const rel_tim search = tails[id]; if (search != NULL && (refcount_incr(&search->refcount) == 2)) { if ((search->exptime != 0 && search->exptime < current_time) - || (search->time < oldest_live)) { // dead by flush + || (search->time <= oldest_live && oldest_live <= current_time)) { // dead by flush STATS_LOCK(); stats.reclaimed++; STATS_UNLOCK(); diff --git a/t/flush-all.t b/t/flush-all.t index e113fc9601..b803bb7d48 100755 --- a/t/flush-all.t +++ b/t/flush-all.t @@ -1,7 +1,7 @@ #!/usr/bin/perl use strict; -use Test::More tests => 14; +use Test::More tests => 21; use FindBin qw($Bin); use lib "$Bin/lib"; use MemcachedTest; @@ -40,5 +40,17 @@ is(scalar <$sock>, "OK\r\n", "did flush_all in future"); print $sock "set foo 0 0 4\r\n1234\r\n"; is(scalar <$sock>, "STORED\r\n", "stored foo = '1234'"); mem_get_is($sock, "foo", '1234'); -sleep(2.2); +sleep(3); mem_get_is($sock, "foo", undef); + +print $sock "set foo 0 0 5\r\n12345\r\n"; +is(scalar <$sock>, "STORED\r\n", "stored foo = '12345'"); +mem_get_is($sock, "foo", '12345'); +print $sock "flush_all 86400\r\n"; +is(scalar <$sock>, "OK\r\n", "did flush_all for far future"); +# Check foo still exists. +mem_get_is($sock, "foo", '12345'); +print $sock "set foo2 0 0 5\r\n54321\r\n"; +is(scalar <$sock>, "STORED\r\n", "stored foo2 = '54321'"); +mem_get_is($sock, "foo", '12345'); +mem_get_is($sock, "foo2", '54321');