[Zodb-checkins] SVN: ZODB/branches/3.10/src/ZODB/ Bugs Fixed

Jim Fulton jim at zope.com
Tue Apr 12 09:50:07 EDT 2011


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

Changed:
  U   ZODB/branches/3.10/src/ZODB/ActivityMonitor.py
  U   ZODB/branches/3.10/src/ZODB/Connection.py
  U   ZODB/branches/3.10/src/ZODB/DB.py
  U   ZODB/branches/3.10/src/ZODB/tests/testConnection.py

-=-
Modified: ZODB/branches/3.10/src/ZODB/ActivityMonitor.py
===================================================================
--- ZODB/branches/3.10/src/ZODB/ActivityMonitor.py	2011-04-12 13:41:44 UTC (rev 121408)
+++ ZODB/branches/3.10/src/ZODB/ActivityMonitor.py	2011-04-12 13:50:07 UTC (rev 121409)
@@ -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.10/src/ZODB/Connection.py
===================================================================
--- ZODB/branches/3.10/src/ZODB/Connection.py	2011-04-12 13:41:44 UTC (rev 121408)
+++ ZODB/branches/3.10/src/ZODB/Connection.py	2011-04-12 13:50:07 UTC (rev 121409)
@@ -321,6 +321,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.10/src/ZODB/DB.py
===================================================================
--- ZODB/branches/3.10/src/ZODB/DB.py	2011-04-12 13:41:44 UTC (rev 121408)
+++ ZODB/branches/3.10/src/ZODB/DB.py	2011-04-12 13:50:07 UTC (rev 121409)
@@ -491,10 +491,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.10/src/ZODB/tests/testConnection.py
===================================================================
--- ZODB/branches/3.10/src/ZODB/tests/testConnection.py	2011-04-12 13:41:44 UTC (rev 121408)
+++ ZODB/branches/3.10/src/ZODB/tests/testConnection.py	2011-04-12 13:50:07 UTC (rev 121409)
@@ -325,6 +325,39 @@
         >>> cn._Connection__onCloseCallbacks
         """
 
+    def test_close_dispatches_to_activity_monitors(self):
+        r"""doctest that connection close updates activity monitors
+        
+        Set up a multi-database:
+        
+            >>> db1 = ZODB.DB(None)
+            >>> db2 = ZODB.DB(None, 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