diff options
author | Volker Lendecke <vl@samba.org> | 2008-05-20 18:35:23 +0200 |
---|---|---|
committer | Volker Lendecke <vl@samba.org> | 2008-05-20 18:38:31 +0200 |
commit | e84026a29b795ab5fc73c81d7790ec83aad83987 (patch) | |
tree | edc43e77bbc18b96351f51b574d9cb58a4ef2e46 | |
parent | 7aa839bba0b4ae408f87a29e4e3a48607bfee275 (diff) | |
download | samba-e84026a29b795ab5fc73c81d7790ec83aad83987.tar.gz samba-e84026a29b795ab5fc73c81d7790ec83aad83987.tar.bz2 samba-e84026a29b795ab5fc73c81d7790ec83aad83987.zip |
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)
-rw-r--r-- | source3/lib/memcache.c | 39 |
1 files changed, 34 insertions, 5 deletions
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; } |