mirrorlist-server/mirrorlist_server.py | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
New commits:
commit ed972730963a1c618faa5fb6b3110c860e1c4859
Author: Matt Domsch <Matt_Domsch(a)dell.com>
Date: Sat Apr 23 22:26:43 2011 -0500
mirrorlist_server: fix host netblocks lookup
1) host_netblocks_tree (with an s!)
2) don't walk the list, use the tree as it is intended, deleting found
nodes and searching again. This should eliminate any slowdown due to
the host netblocks list getting too long.
diff --git a/mirrorlist-server/mirrorlist_server.py
b/mirrorlist-server/mirrorlist_server.py
index 440fb5b..e2d19e6 100755
--- a/mirrorlist-server/mirrorlist_server.py
+++ b/mirrorlist-server/mirrorlist_server.py
@@ -190,13 +190,15 @@ def client_netblocks(ip):
except:
return result
- # fast lookup in the tree; if present, find all the netblocks in the list
- # rather than just the "best" one
- node = host_netblock_tree.search_best(ip.strNormal()))
- if node is not None:
- for k,v in host_netblock_cache.iteritems():
- if clientIP in k:
- result.extend(v)
+ # fast lookup in the tree; if present, find all the netblocks by deleting the found
one and searching again
+ # this is safe w/o copying the tree again only because this is the only place the
tree is used, and
+ # we'll get a new copy of the tree from our parent the next time it fork()s.
+ node = host_netblocks_tree.search_best(ip.strNormal())
+ while node is not None:
+ result.extend(node.data['hosts'])
+ prefix = node.prefix
+ host_netblocks_tree.delete(prefix)
+ node = host_netblocks_tree.search_best(ip.strNormal()))
return result
def trim_by_client_country(s, clientCountry):
@@ -612,7 +614,8 @@ def do_mirrorlist(kwargs):
def setup_host_netblocks_tree():
tree = radix.Radix()
for k, v in host_netblock_cache.iteritems():
- tree.add(k.strNormal())
+ node = tree.add(k.strNormal())
+ node.data['hosts'] = v
return tree
def setup_netblocks(netblocks_file):