[Zodb-checkins] SVN: ZODB/branches/3.9/src/ Bug Fixed:

Jim Fulton jim at zope.com
Mon Apr 18 10:51:16 EDT 2011


Log message for revision 121440:
  Bug Fixed:
  
  "activity monitor not updated for subconnections when connection
  returned to pool"
  
  https://bugs.launchpad.net/zodb/+bug/737198
  

Changed:
  U   ZODB/branches/3.9/src/CHANGES.txt
  U   ZODB/branches/3.9/src/ZODB/ActivityMonitor.py
  U   ZODB/branches/3.9/src/ZODB/Connection.py
  U   ZODB/branches/3.9/src/ZODB/DB.py
  U   ZODB/branches/3.9/src/ZODB/tests/testConnection.py

-=-
Modified: ZODB/branches/3.9/src/CHANGES.txt
===================================================================
--- ZODB/branches/3.9/src/CHANGES.txt	2011-04-17 16:44:57 UTC (rev 121439)
+++ ZODB/branches/3.9/src/CHANGES.txt	2011-04-18 14:51:15 UTC (rev 121440)
@@ -2,6 +2,18 @@
  Change History
 ================
 
+3.9.8 (2011-04-18)
+==================
+
+Bugs Fixed
+----------
+
+- "activity monitor not updated for subconnections when connection
+  returned to pool"
+
+  https://bugs.launchpad.net/zodb/+bug/737198
+
+
 3.9.7 (2010-09-28)
 ==================
 

Modified: ZODB/branches/3.9/src/ZODB/ActivityMonitor.py
===================================================================
--- ZODB/branches/3.9/src/ZODB/ActivityMonitor.py	2011-04-17 16:44:57 UTC (rev 121439)
+++ ZODB/branches/3.9/src/ZODB/ActivityMonitor.py	2011-04-18 14:51:15 UTC (rev 121440)
@@ -15,6 +15,7 @@
 
 $Id$"""
 
+import threading
 import time
 
 
@@ -24,14 +25,13 @@
     This simple implementation just keeps a small log in memory
     and iterates over the log when getActivityAnalysis() is called.
 
-    It assumes that log entries are added in chronological sequence,
-    which is only guaranteed because DB.py holds a lock when calling
-    the closedConnection() method.
+    It assumes that log entries are added in chronological sequence.
     """
 
     def __init__(self, history_length=3600):
         self.history_length = history_length  # Number of seconds
         self.log = []                     # [(time, loads, stores)]
+        self.trim_lock = threading.Lock()
 
     def closedConnection(self, conn):
         log = self.log
@@ -41,6 +41,8 @@
         self.trim(now)
 
     def trim(self, now):
+        self.trim_lock.acquire()
+        
         log = self.log
         cutoff = now - self.history_length
         n = 0
@@ -49,6 +51,8 @@
             n = n + 1
         if n:
             del log[:n]
+        
+        self.trim_lock.release()
 
     def setHistoryLength(self, history_length):
         self.history_length = history_length

Modified: ZODB/branches/3.9/src/ZODB/Connection.py
===================================================================
--- ZODB/branches/3.9/src/ZODB/Connection.py	2011-04-17 16:44:57 UTC (rev 121439)
+++ ZODB/branches/3.9/src/ZODB/Connection.py	2011-04-18 14:51:15 UTC (rev 121440)
@@ -325,6 +325,10 @@
                 # get back here.
         else:
             self.opened = None
+            
+        am = self._db._activity_monitor
+        if am is not None:
+            am.closedConnection(self)        
 
     def db(self):
         """Returns a handle to the database this connection belongs to."""

Modified: ZODB/branches/3.9/src/ZODB/DB.py
===================================================================
--- ZODB/branches/3.9/src/ZODB/DB.py	2011-04-17 16:44:57 UTC (rev 121439)
+++ ZODB/branches/3.9/src/ZODB/DB.py	2011-04-18 14:51:15 UTC (rev 121440)
@@ -513,10 +513,6 @@
             assert connection._db is self
             connection.opened = None
 
-            am = self._activity_monitor
-            if am is not None:
-                am.closedConnection(connection)
-
             if connection.before:
                 self.historical_pool.repush(connection, connection.before)
             else:

Modified: ZODB/branches/3.9/src/ZODB/tests/testConnection.py
===================================================================
--- ZODB/branches/3.9/src/ZODB/tests/testConnection.py	2011-04-17 16:44:57 UTC (rev 121439)
+++ ZODB/branches/3.9/src/ZODB/tests/testConnection.py	2011-04-18 14:51:15 UTC (rev 121440)
@@ -325,6 +325,42 @@
         >>> cn._Connection__onCloseCallbacks
         """
 
+    def test_close_dispatches_to_activity_monitors(self):
+        r"""doctest that connection close updates activity monitors
+
+        Set up a multi-database:
+
+            >>> import ZODB.MappingStorage
+
+            >>> db1 = ZODB.DB(ZODB.MappingStorage.MappingStorage())
+            >>> db2 = ZODB.DB(ZODB.MappingStorage.MappingStorage(),
+            ...               databases=db1.databases, database_name='2',
+            ...               cache_size=10)
+            >>> conn1 = db1.open()
+            >>> conn2 = conn1.get_connection('2')
+
+        Add activity monitors to both dbs:
+
+            >>> from ZODB.ActivityMonitor import ActivityMonitor
+            >>> db1.setActivityMonitor(ActivityMonitor())
+            >>> db2.setActivityMonitor(ActivityMonitor())
+
+        Commit a transaction that affects both connections:
+
+            >>> conn1.root()[0] = conn1.root().__class__()
+            >>> conn2.root()[0] = conn2.root().__class__()
+            >>> transaction.commit()
+
+        After closing the primary connection, both monitors should be up to
+        date:
+
+            >>> conn1.close()
+            >>> len(db1.getActivityMonitor().log)
+            1
+            >>> len(db2.getActivityMonitor().log)
+            1
+        """
+
     def test_db(self):
         r"""doctest of db() method
 



More information about the Zodb-checkins mailing list