From c1c99c9f2b37071ee46310735b7a1903aa53193c Mon Sep 17 00:00:00 2001 From: dormando Date: Wed, 1 Feb 2012 18:05:20 -0800 Subject: fix glitch with flush_all reported by jhpark. items at the bottom of the LRU would be popped for sets if flush_all was set for the "future" but said future hadn't arrived yet. item_get handled this correctly so the flush would not happen, but items at the bottom of the LRU would be reclaimed early. Added tests for this as well. --- items.c | 2 +- t/flush-all.t | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/items.c b/items.c index 19e2e71..ab588db 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 e113fc9..b803bb7 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'); -- cgit v1.2.1