summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordormando <dormando@rydia.net>2012-02-01 18:05:20 -0800
committerdormando <dormando@rydia.net>2012-02-01 18:05:20 -0800
commitc1c99c9f2b37071ee46310735b7a1903aa53193c (patch)
tree91a05bb0624ac294a0aa37d08ecec79e0bf4768f
parent5f37a9cd84b24fda97735a59afb347cc11e30579 (diff)
downloadmemcached-c1c99c9f2b37071ee46310735b7a1903aa53193c.tar.gz
fix glitch with flush_all <future>1.4.12
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.
-rw-r--r--items.c2
-rwxr-xr-xt/flush-all.t16
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');