Changeset 438 for branches/performance

Show
Ignore:
Timestamp:
11/20/06 22:05:31 (3 years ago)
Author:
sgrimm
Message:

Fix for flush_all 1-second window bug. You can now do a "set" immediately
after a "flush_all" without the newly set data getting expired. (Ported
from trunk.)

Location:
branches/performance/server
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • branches/performance/server/items.c

    r419 r438  
    330330    return buf; 
    331331} 
     332 
     333/* expires items that are more recent than the oldest_live setting. */ 
     334void item_flush_expired() { 
     335    int i; 
     336    item *iter, *next; 
     337    if (! settings.oldest_live) 
     338        return; 
     339    for (i = 0; i < LARGEST_ID; i++) { 
     340        /* The LRU is sorted in decreasing time order, and an item's timestamp 
     341         * is never newer than its last access time, so we only need to walk 
     342         * back until we hit an item older than the oldest_live time. 
     343         * The oldest_live checking will auto-expire the remaining items. 
     344         */ 
     345        for (iter = heads[i]; iter != NULL; iter = next) { 
     346            if (iter->time >= settings.oldest_live) { 
     347                next = iter->next; 
     348                if ((iter->it_flags & ITEM_SLABBED) == 0) { 
     349                    item_unlink(iter); 
     350                } 
     351            } else { 
     352                /* We've hit the first old item. Continue to the next queue. */ 
     353                break; 
     354            } 
     355        } 
     356    } 
     357} 
  • branches/performance/server/memcached.c

    r421 r438  
    9797    stats.curr_bytes = stats.bytes_read = stats.bytes_written = 0; 
    9898 
    99     /* make the time we started always be 1 second before we really 
     99    /* make the time we started always be 2 seconds before we really 
    100100       did, so time(0) - time.started is never zero.  if so, things 
    101101       like 'settings.oldest_live' which act as booleans as well as 
    102102       values are now false in boolean context... */ 
    103     stats.started = time(0) - 1; 
     103    stats.started = time(0) - 2; 
    104104} 
    105105 
     
    13381338 
    13391339        if(ntokens == 2) { 
    1340             settings.oldest_live = current_time; 
     1340            settings.oldest_live = current_time - 1; 
     1341            item_flush_expired(); 
    13411342            out_string(c, "OK"); 
    13421343            return; 
     
    13491350        } 
    13501351 
    1351         settings.oldest_live = realtime(exptime); 
     1352        settings.oldest_live = realtime(exptime) - 1; 
     1353        item_flush_expired(); 
    13521354        out_string(c, "OK"); 
    13531355        return; 
  • branches/performance/server/memcached.h

    r419 r438  
    277277char *item_stats_sizes(int *bytes); 
    278278void item_stats(char *buffer, int buflen); 
     279void item_flush_expired(void); 
    279280 
    280281/* time handling */ 
  • branches/performance/server/t/flush-all.t

    r347 r438  
    22 
    33use strict; 
    4 use Test::More tests => 11; 
     4use Test::More tests => 10; 
    55use FindBin qw($Bin); 
    66use lib "$Bin/lib"; 
     
    1717print $sock "flush_all\r\n"; 
    1818is(scalar <$sock>, "OK\r\n", "did flush_all"); 
     19mem_get_is($sock, "foo", undef); 
    1920 
    20 mem_get_is($sock, "foo", undef); 
    21 SKIP: { 
    22     skip "flush_all is still only second-granularity.  need atomic counter on flush_all.", 2 unless 0; 
    23  
    24     print $sock "set foo 0 0 3\r\nnew\r\n"; 
    25     is(scalar <$sock>, "STORED\r\n", "stored foo = 'new'"); 
    26     mem_get_is($sock, "foo", 'new'); 
    27 } 
    28  
    29 sleep 1; 
    30 mem_get_is($sock, "foo", undef); 
     21# check that flush_all doesn't blow away items that immediately get set 
     22print $sock "set foo 0 0 3\r\nnew\r\n"; 
     23is(scalar <$sock>, "STORED\r\n", "stored foo = 'new'"); 
     24mem_get_is($sock, "foo", 'new'); 
    3125 
    3226# and the other form, specifying a flush_all time...