Skip to content

Commit c1c99c9

Browse files
committed
fix glitch with flush_all <future>
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.
1 parent 5f37a9c commit c1c99c9

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

Diff for: items.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ item *do_item_alloc(char *key, const size_t nkey, const int flags, const rel_tim
106106
search = tails[id];
107107
if (search != NULL && (refcount_incr(&search->refcount) == 2)) {
108108
if ((search->exptime != 0 && search->exptime < current_time)
109-
|| (search->time < oldest_live)) { // dead by flush
109+
|| (search->time <= oldest_live && oldest_live <= current_time)) { // dead by flush
110110
STATS_LOCK();
111111
stats.reclaimed++;
112112
STATS_UNLOCK();

Diff for: t/flush-all.t

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/perl
22

33
use strict;
4-
use Test::More tests => 14;
4+
use Test::More tests => 21;
55
use FindBin qw($Bin);
66
use lib "$Bin/lib";
77
use MemcachedTest;
@@ -40,5 +40,17 @@ is(scalar <$sock>, "OK\r\n", "did flush_all in future");
4040
print $sock "set foo 0 0 4\r\n1234\r\n";
4141
is(scalar <$sock>, "STORED\r\n", "stored foo = '1234'");
4242
mem_get_is($sock, "foo", '1234');
43-
sleep(2.2);
43+
sleep(3);
4444
mem_get_is($sock, "foo", undef);
45+
46+
print $sock "set foo 0 0 5\r\n12345\r\n";
47+
is(scalar <$sock>, "STORED\r\n", "stored foo = '12345'");
48+
mem_get_is($sock, "foo", '12345');
49+
print $sock "flush_all 86400\r\n";
50+
is(scalar <$sock>, "OK\r\n", "did flush_all for far future");
51+
# Check foo still exists.
52+
mem_get_is($sock, "foo", '12345');
53+
print $sock "set foo2 0 0 5\r\n54321\r\n";
54+
is(scalar <$sock>, "STORED\r\n", "stored foo2 = '54321'");
55+
mem_get_is($sock, "foo", '12345');
56+
mem_get_is($sock, "foo2", '54321');

0 commit comments

Comments
 (0)