From e84026a29b795ab5fc73c81d7790ec83aad83987 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 20 May 2008 18:35:23 +0200 Subject: Fix memcache_flush() I have no idea what I've been smoking when I checked this in :-( Karolin, this fixes the join bug 3.0.28->3.2.0rc1 Thanks, Volker (This used to be commit f845dbbceeff032cd248117ddf63af3d3736b21c) --- source3/lib/memcache.c | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) (limited to 'source3') diff --git a/source3/lib/memcache.c b/source3/lib/memcache.c index 6dee61af50..e1426bc811 100644 --- a/source3/lib/memcache.c +++ b/source3/lib/memcache.c @@ -120,11 +120,11 @@ static int memcache_compare(struct memcache_element *e, enum memcache_number n, { DATA_BLOB this_key, this_value; - if ((int)e->n < (int)n) return -1; - if ((int)e->n > (int)n) return 1; + if ((int)e->n < (int)n) return 1; + if ((int)e->n > (int)n) return -1; - if (e->keylength < key.length) return -1; - if (e->keylength > key.length) return 1; + if (e->keylength < key.length) return 1; + if (e->keylength > key.length) return -1; memcache_element_parse(e, &this_key, &this_value); return memcmp(this_key.data, key.data, key.length); @@ -357,10 +357,18 @@ void memcache_flush(struct memcache *cache, enum memcache_number n) return; } + /* + * First, find *any* element of number n + */ + while (true) { struct memcache_element *elem = memcache_node2elem(node); struct rb_node *next; + if ((int)elem->n == (int)n) { + break; + } + if ((int)elem->n < (int)n) { next = node->rb_right; } @@ -373,15 +381,36 @@ void memcache_flush(struct memcache *cache, enum memcache_number n) node = next; } - node = rb_next(node); if (node == NULL) { return; } + /* + * Then, find the leftmost element with number n + */ + + while (true) { + struct rb_node *prev = rb_prev(node); + struct memcache_element *elem; + + if (prev == NULL) { + break; + } + elem = memcache_node2elem(prev); + if ((int)elem->n != (int)n) { + break; + } + node = prev; + } + while (node != NULL) { struct memcache_element *e = memcache_node2elem(node); struct rb_node *next = rb_next(node); + if (e->n != n) { + break; + } + memcache_delete_element(cache, e); node = next; } -- cgit