Commit 0471cbd6 authored by Hanno Schlichting's avatar Hanno Schlichting

Actually nest the queryplan on the catalog id as well

parent a370d541
......@@ -883,16 +883,19 @@ class ZCatalog(Folder, Persistent, Implicit):
security.declareProtected(manage_zcatalog_entries, 'getCatalogPlan')
def getCatalogPlan(self):
"""Get a string representation of a query plan"""
plan = PriorityMap.get_plan()
pmap = PriorityMap.get_value()
output = []
output.append('# query plan dumped at %r\n' % time.asctime())
output.append('queryplan = {')
for cid, plan in sorted(pmap.items()):
output.append(' %s: {' % repr(cid))
for querykey, details in sorted(plan.items()):
output.append(' %s: {' % repr(querykey))
for indexname, benchmark in sorted(details.items()):
tuplebench = repr(tuple(benchmark))
output.append(' %r:\n %s,' % (indexname, tuplebench))
output.append(' },')
output.append(' },')
output.append('}')
return '\n'.join(output)
......
......@@ -35,19 +35,16 @@ Report = namedtuple('Report', ['hits', 'duration', 'last'])
logger = getLogger('Products.ZCatalog')
class PriorityMap(object):
"""This holds a query key to Benchmark mapping."""
lock = allocate_lock()
value = {}
@classmethod
def get_plan(cls):
return cls.value.copy()
class NestedDict(object):
"""Holds a structure of two nested dicts."""
@classmethod
def get(cls, key):
return cls.value.get(key, None)
outer = cls.value.get(key, None)
if outer is None:
cls.set(key, {})
outer = cls.value[key]
return outer
@classmethod
def set(cls, key, value):
......@@ -59,6 +56,40 @@ class PriorityMap(object):
with cls.lock:
cls.value = {}
@classmethod
def get_entry(cls, key, key2):
outer = cls.get(key)
inner = outer.get(key2, None)
if inner is None:
cls.set_entry(key, key2, {})
inner = outer.get(key2)
return inner
@classmethod
def set_entry(cls, key, key2, value):
outer = cls.get(key)
with cls.lock:
outer[key2] = value
@classmethod
def clear_entry(cls, key):
cls.set(key, {})
class PriorityMap(NestedDict):
"""This holds a structure of nested dicts.
The outer dict is a mapping of catalog id to plans. The inner dict holds
a query key to Benchmark mapping.
"""
lock = allocate_lock()
value = {}
@classmethod
def get_value(cls):
return cls.value.copy()
@classmethod
def load_default(cls):
location = environ.get('ZCATALOGQUERYPLAN')
......@@ -67,19 +98,22 @@ class PriorityMap(object):
pmap = resolve(location)
logger.info('loaded priority %d map(s) from %s',
len(pmap), location)
# Convert simple benchmark tuples to namedtuples
# Convert the simple benchmark tuples to namedtuples
new_plan = {}
for querykey, details in pmap.items():
new_plan[querykey] = {}
for cid, plan in pmap.items():
new_plan[cid] = {}
for querykey, details in plan.items():
new_plan[cid][querykey] = {}
for indexname, benchmark in details.items():
new_plan[querykey][indexname] = Benchmark(*benchmark)
new_plan[cid][querykey][indexname] = \
Benchmark(*benchmark)
with cls.lock:
cls.value = new_plan
except ImportError:
logger.warning('could not load priority map from %s', location)
class Reports(object):
class Reports(NestedDict):
"""This holds a structure of nested dicts.
The outer dict is a mapping of catalog id to reports. The inner dict holds
......@@ -89,43 +123,6 @@ class Reports(object):
lock = allocate_lock()
value = {}
@classmethod
def get(cls, key):
outer = cls.value.get(key, None)
if outer is None:
cls.set(key, {})
outer = cls.value[key]
return outer
@classmethod
def set(cls, key, value):
with cls.lock:
cls.value[key] = value
@classmethod
def clear(cls):
with cls.lock:
cls.value = {}
@classmethod
def get_entry(cls, key, key2):
outer = cls.get(key)
inner = outer.get(key2, None)
if inner is None:
cls.set_entry(key, key2, {})
inner = outer.get(key2)
return inner
@classmethod
def set_entry(cls, key, key2, value):
outer = cls.get(key)
with cls.lock:
outer[key2] = value
@classmethod
def clear_entry(cls, key):
cls.set(key, {})
class ValueIndexes(object):
"""Holds a set of index names considered to have an uneven value
......@@ -239,7 +236,7 @@ class CatalogPlan(object):
self.duration = None
def plan(self):
benchmark = PriorityMap.get(self.key)
benchmark = PriorityMap.get_entry(self.cid, self.key)
if not benchmark:
return None
......@@ -290,7 +287,7 @@ class CatalogPlan(object):
def stop(self):
self.end_time = time.time()
self.duration = self.end_time - self.start_time
PriorityMap.set(self.key, self.benchmark)
PriorityMap.set_entry(self.cid, self.key, self.benchmark)
self.log()
def log(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment