Skip to content

Commit

Permalink
fix glitch with flush_all <future>
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dormando committed Feb 2, 2012
1 parent 5f37a9c commit c1c99c9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion items.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 14 additions & 2 deletions t/flush-all.t
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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');

0 comments on commit c1c99c9

Please sign in to comment.