Author: nunofsantos
Date: 2008-12-01 15:23:32 -0500 (Mon, 01 Dec 2008)
New Revision: 2901
Modified:
mgmt/trunk/mint/python/mint/dbexpire.py
mgmt/trunk/mint/python/mint/sql.py
Log:
add an optional keepCurrStats param to the database cleanup thread; now the default
behavior is to delete any old stats, regardless of whether they're the current stats
of any object
Modified: mgmt/trunk/mint/python/mint/dbexpire.py
===================================================================
--- mgmt/trunk/mint/python/mint/dbexpire.py 2008-12-01 19:56:35 UTC (rev 2900)
+++ mgmt/trunk/mint/python/mint/dbexpire.py 2008-12-01 20:23:32 UTC (rev 2901)
@@ -8,7 +8,7 @@
log = logging.getLogger("mint.dbexpire")
class DBExpireThread(Thread):
- def __init__(self, model, frequency=600, expiration=24*3600):
+ def __init__(self, model, frequency=600, expiration=24*3600, keepCurrStats=False):
super(DBExpireThread, self).__init__()
self.model = model
@@ -16,6 +16,7 @@
self.stopRequested = False
self.frequency = frequency
self.expiration = expiration
+ self.keepCurrStats = keepCurrStats
frequency_out, frequency_unit = self.convertTimeUnits(frequency)
expiration_out, expiration_unit = self.convertTimeUnits(expiration)
@@ -25,8 +26,8 @@
def run(self):
ops = []
for cls in mint.schema.statsClasses:
- ops.append(SqlExpire(eval(cls)))
- ops.append(SqlExpire(Job))
+ ops.append(SqlExpire(eval(cls), self.keepCurrStats))
+ ops.append(SqlExpire(Job, self.keepCurrStats))
attrs = dict()
attrs["expiration"] = self.expiration
Modified: mgmt/trunk/mint/python/mint/sql.py
===================================================================
--- mgmt/trunk/mint/python/mint/sql.py 2008-12-01 19:56:35 UTC (rev 2900)
+++ mgmt/trunk/mint/python/mint/sql.py 2008-12-01 20:23:32 UTC (rev 2901)
@@ -140,10 +140,11 @@
return sql
class SqlExpire(SqlOperation):
- def __init__(self, cls):
+ def __init__(self, cls, keepCurrStats):
super(SqlExpire, self).__init__("expire")
self.cls = cls
+ self.keepCurrStats = keepCurrStats
def generate(self):
table = self.cls.sqlmeta.table
@@ -152,8 +153,9 @@
sql = """
delete from %s
where qmf_update_time < now() - interval '%%(expiration)s seconds'
- and id not in (select stats_curr_id from %s)
- """ % (table, parent_table)
+ """ % (table)
+ if self.keepCurrStats:
+ sql += " and id not in (select stats_curr_id from %s)" %
(parent_table)
else:
sql = """
delete from %s