Author: nunofsantos
Date: 2008-12-11 13:18:44 -0500 (Thu, 11 Dec 2008)
New Revision: 2975
Modified:
mgmt/trunk/cumin/python/cumin/model.py
mgmt/trunk/mint/python/mint/__init__.py
mgmt/trunk/mint/python/mint/dbexpire.py
mgmt/trunk/mint/python/mint/update.py
Log:
enqueue db expiration 'updates' into the update queue instead of having them in a
separate thread, to avoid deadlocks
Modified: mgmt/trunk/cumin/python/cumin/model.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/model.py 2008-12-11 17:00:32 UTC (rev 2974)
+++ mgmt/trunk/cumin/python/cumin/model.py 2008-12-11 18:18:44 UTC (rev 2975)
@@ -27,6 +27,7 @@
debug=False)
self.data.updateObjects = False
+ self.data.dbExpiration = False
self.classes = list()
self.invocations = set()
Modified: mgmt/trunk/mint/python/mint/__init__.py
===================================================================
--- mgmt/trunk/mint/python/mint/__init__.py 2008-12-11 17:00:32 UTC (rev 2974)
+++ mgmt/trunk/mint/python/mint/__init__.py 2008-12-11 18:18:44 UTC (rev 2975)
@@ -325,6 +325,7 @@
self.debug = debug
self.updateObjects = True
self.pollRegistrations = True
+ self.dbExpiration = True
assert MintModel.staticInstance is None
MintModel.staticInstance = self
@@ -375,15 +376,19 @@
def start(self):
self.updateThread.start()
- self.dbExpireThread.start()
+ if self.dbExpiration:
+ self.dbExpireThread.start()
+
if self.pollRegistrations:
self.registrationThread.start()
def stop(self):
self.updateThread.stop()
- self.dbExpireThread.stop()
+ if self.dbExpiration:
+ self.dbExpireThread.stop()
+
if self.pollRegistrations:
self.registrationThread.stop()
Modified: mgmt/trunk/mint/python/mint/dbexpire.py
===================================================================
--- mgmt/trunk/mint/python/mint/dbexpire.py 2008-12-11 17:00:32 UTC (rev 2974)
+++ mgmt/trunk/mint/python/mint/dbexpire.py 2008-12-11 18:18:44 UTC (rev 2975)
@@ -16,43 +16,28 @@
self.threshold = threshold
self.keepCurrStats = keepCurrStats
- frequency_out, frequency_unit = self.convertTimeUnits(frequency)
- threshold_out, threshold_unit = self.convertTimeUnits(threshold)
+ self.ops = []
+ for cls in mint.schema.statsClasses:
+ self.ops.append(SqlExpire(eval(cls), self.keepCurrStats))
+ self.ops.append(SqlExpire(Job, self.keepCurrStats))
+
+ self.attrs = dict()
+ self.attrs["threshold"] = self.threshold
+
+ frequency_out, frequency_unit = self.__convertTimeUnits(frequency)
+ threshold_out, threshold_unit = self.__convertTimeUnits(threshold)
log.debug("Expiring database records older than %d %s, every %d %s" \
% (threshold_out, threshold_unit, frequency_out, frequency_unit))
def run(self):
- ops = []
- for cls in mint.schema.statsClasses:
- ops.append(SqlExpire(eval(cls), self.keepCurrStats))
- ops.append(SqlExpire(Job, self.keepCurrStats))
-
- attrs = dict()
- attrs["threshold"] = self.threshold
-
- conn = self.model.dbConn.getConnection()
-
while True:
- try:
- if self.stopRequested:
- break
+ if self.stopRequested:
+ break
+ up = mint.update.DBExpireUpdate(self.model)
+ self.model.updateThread.enqueue(up)
+ time.sleep(self.frequency)
- cursor = conn.cursor()
- rowcount = 0
- for op in ops:
- rowcount += op.execute(cursor, attrs)
- log.debug("%d records expired" % (rowcount))
- conn.commit()
-
- time.sleep(self.frequency)
- except:
- conn.rollback()
- log.exception("DB cleanup failed")
-
- def stop(self):
- self.stopRequested = True
-
- def convertTimeUnits(self, t):
+ def __convertTimeUnits(self, t):
if t / (24*3600) >= 1:
t_out = t / (24*3600)
t_unit = "days"
Modified: mgmt/trunk/mint/python/mint/update.py
===================================================================
--- mgmt/trunk/mint/python/mint/update.py 2008-12-11 17:00:32 UTC (rev 2974)
+++ mgmt/trunk/mint/python/mint/update.py 2008-12-11 18:18:44 UTC (rev 2975)
@@ -375,3 +375,20 @@
if len(self.slots[slot]) > 0:
return self.slots[slot].popleft()
return None
+
+class DBExpireUpdate(ModelUpdate):
+ def __init__(self, model):
+ super(DBExpireUpdate, self).__init__(model, None, None)
+
+ def process(self, conn):
+ try:
+ cursor = conn.cursor()
+ rowcount = 0
+ attrs = self.model.dbExpireThread.attrs
+ for op in self.model.dbExpireThread.ops:
+ rowcount += op.execute(cursor, attrs)
+ log.debug("%d records expired" % (rowcount))
+ conn.commit()
+ except:
+ conn.rollback()
+ log.exception("DB cleanup failed")
Show replies by date