[CalendarServer-changes] [6832] CalendarServer/branches/users/glyph/db-reconnect/twext/enterprise

source_changes at macosforge.org source_changes at macosforge.org
Fri Jan 28 17:40:36 PST 2011


Revision: 6832
          http://trac.macosforge.org/projects/calendarserver/changeset/6832
Author:   glyph at apple.com
Date:     2011-01-28 17:40:36 -0800 (Fri, 28 Jan 2011)
Log Message:
-----------
Small cleanups; test that lists are emptied out, empty them out as we go along rather than all at once, get rid of no-longer-used connectionFactory attribute on BaseSqlTxn.

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/db-reconnect/twext/enterprise/adbapi2.py
    CalendarServer/branches/users/glyph/db-reconnect/twext/enterprise/test/test_adbapi2.py

Modified: CalendarServer/branches/users/glyph/db-reconnect/twext/enterprise/adbapi2.py
===================================================================
--- CalendarServer/branches/users/glyph/db-reconnect/twext/enterprise/adbapi2.py	2011-01-29 01:40:26 UTC (rev 6831)
+++ CalendarServer/branches/users/glyph/db-reconnect/twext/enterprise/adbapi2.py	2011-01-29 01:40:36 UTC (rev 6832)
@@ -68,7 +68,7 @@
     # FIXME: this should *really* be 
     paramstyle = DEFAULT_PARAM_STYLE
 
-    def __init__(self, connectionFactory, threadHolder, connection, cursor):
+    def __init__(self, threadHolder, connection, cursor):
         self._completed = True
         self._cursor = cursor
         self._connection = connection
@@ -354,20 +354,26 @@
     @inlineCallbacks
     def stopService(self):
         """
-        Forcibly abort any outstanding transactions.
+        Forcibly abort any outstanding transactions, and release all resources
+        (notably, threads).
         """
+        # Phase 1: All of the busy transactions must be aborted first.  As each
+        # one is aborted, it will remove itself from the list.
         while self.busy:
             busy = self.busy[0]
             try:
                 yield busy.abort()
             except:
                 log.err()
-        # all transactions should now be in the free list, since 'abort()' will
-        # have put them there.
-        for free in self.free:
+        # Phase 2: All transactions should now be in the free list, since
+        # 'abort()' will have put them there.  Shut down all the associated
+        # ThreadHolders.
+        while self.free:
+            # (Stopping a BaseSqlTxn doesn't automatically recycle it / remove
+            # it the way aborting a PooledSqlTxn does, so we need to .pop()
+            # here.)
+            free = self.free.pop()
             yield free.stop()
-        self.busy = []
-        self.free = []
 
 
     def _createHolder(self):
@@ -415,7 +421,6 @@
             return (connection, cursor)
         def finishInit((connection, cursor)):
             baseTxn = BaseSqlTxn(
-                connectionFactory=self.connectionFactory,
                 threadHolder=holder,
                 connection=connection,
                 cursor=cursor

Modified: CalendarServer/branches/users/glyph/db-reconnect/twext/enterprise/test/test_adbapi2.py
===================================================================
--- CalendarServer/branches/users/glyph/db-reconnect/twext/enterprise/test/test_adbapi2.py	2011-01-29 01:40:26 UTC (rev 6831)
+++ CalendarServer/branches/users/glyph/db-reconnect/twext/enterprise/test/test_adbapi2.py	2011-01-29 01:40:36 UTC (rev 6832)
@@ -337,6 +337,8 @@
         self.assertEquals(holder.started, True)
         self.assertEquals(holder.stopped, False)
         yield self.pool.stopService()
+        self.assertEquals(self.pool.busy, [])
+        self.assertEquals(self.pool.free, [])
         self.assertEquals(len(self.holders), 1)
         self.assertEquals(holder.started, True)
         self.assertEquals(holder.stopped, True)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110128/4c9aee66/attachment-0001.html>


More information about the calendarserver-changes mailing list