SK-Yang / memcached

Automatically exported from code.google.com/p/memcached
0 stars 0 forks source link

assoc_delete issue. #287

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Reported by soach888@gmail.com, Sep 08, 2012

i find there may be a bug when delete a item from hash_table during i read the 
source code.

below is the source code, and during deleting a item, it will firstly find the 
before's value. but "**before" will pointer to a item to be deleted, and at 
last it make *before = nxt; and i think this will delete all items linked after 
this item, not this item, and cause all these items in *head and *tail (static 
item *heads[LARGEST_ID];static item *tails[LARGEST_ID];) can not be accessed 
forever, 

maybe this can explain why some items can alive too long.

void assoc_delete(const char *key, const size_t nkey, const uint32_t hv) {
    item **before = _hashitem_before(key, nkey, hv);

    if (*before) {
        item *nxt;
        hash_items--;
        nxt = (*before)->h_next;
        (*before)->h_next = 0;   /* probably pointless, but whatever. */
        *before = nxt;
        return;
    }
    assert(*before != 0);
}

Original issue reported on code.google.com by soach...@gmail.com on 8 Sep 2012 at 9:23

Attachments:

GoogleCodeExporter commented 9 years ago
Please write a test proving this.

Original comment by dorma...@rydia.net on 8 Sep 2012 at 5:21

GoogleCodeExporter commented 9 years ago
sorry ,you are right. but i do not understan why it would works, can you 
explain it? thank you.

Original comment by soach...@gmail.com on 10 Sep 2012 at 3:09

GoogleCodeExporter commented 9 years ago
Closing this ticket.

I think you might be conflating the LRU heads/tailt structures with the hash 
table bucket lists. There's a global LRU list all active items are linked into, 
and then the hash table buckets can each have lists of items if multiple items 
hash to the same value.

so that before bit is collapsing the singly-linked-list from that particular 
bucket. (h_next, not next or prev)

Original comment by dorma...@rydia.net on 10 Sep 2012 at 6:35