[Zope3-checkins] CVS: Zope3/src/zodb - db.py:1.9.2.1

Jeremy Hylton jeremy@zope.com
Sat, 1 Mar 2003 21:35:26 -0500


Update of /cvs-repository/Zope3/src/zodb
In directory cvs.zope.org:/tmp/cvs-serv19102/src/zodb

Modified Files:
      Tag: jeremy-atomic-invalidation-branch
	db.py 
Log Message:
New invalidation API.

The begin_ and finish_invalidation() methods are no longer needed.
Change invalidate() to take a set of oids instead of just one.


=== Zope3/src/zodb/db.py 1.9 => 1.9.2.1 ===
--- Zope3/src/zodb/db.py:1.9	Thu Feb 27 15:16:45 2003
+++ Zope3/src/zodb/db.py	Sat Mar  1 21:35:25 2003
@@ -55,10 +55,12 @@
 
         self.log = logging.getLogger("zodb")
 
-        # Allocate locks:
-        l=Lock()
-        self._a=l.acquire
-        self._r=l.release
+        # The lock protects access to the pool data structures.
+        # Store the lock acquire and release methods as methods
+        # of the instance.
+        l = Lock()
+        self._a = l.acquire
+        self._r = l.release
 
         # Setup connection pools and cache info
         # _pool is currently available (closed) connections
@@ -148,17 +150,7 @@
     def getPoolSize(self):
         return self._pool_size
 
-    def begin_invalidation(self):
-        # Must be called before first call to invalidate and before
-        # the storage lock is held.
-        self._a()
-
-    def finish_invalidation(self):
-        # Must be called after begin_invalidation() and after final
-        # invalidate() call.
-        self._r()
-
-    def invalidate(self, oid, connection=None, version=''):
+    def invalidate(self, oids, connection=None, version=''):
         """Invalidate references to a given oid.
 
         This is used to indicate that one of the connections has committed a
@@ -166,7 +158,6 @@
         passed in to prevent useless (but harmless) messages to the
         connection.
         """
-        assert oid is not None
         if connection is not None:
             assert version == connection._version
             version = connection._version
@@ -174,18 +165,18 @@
         # Notify connections
         for cc in self._allocated:
             if cc is not connection:
-                self.invalidateConnection(cc, oid, version)
+                self.invalidateConnection(cc, oids, version)
 
         if self._temps:
             # t accumulates all the connections that aren't closed.
             t = []
             for cc in self._temps:
                 if cc is not connection:
-                    self.invalidateConnection(cc, oid, version,
+                    self.invalidateConnection(cc, oids, version,
                                               t.append)
             self._temps = t
 
-    def invalidateConnection(self, conn, oid, version, alive=None):
+    def invalidateConnection(self, conn, oids, version, alive=None):
         """Send invalidation message to conn for oid on version.
 
         If the modification occurred on a version, an invalidation is
@@ -205,7 +196,7 @@
             if alive is not None:
                 alive(conn)
         if not version or conn.getVersion() == version:
-            conn.invalidate(oid)
+            conn.invalidate(oids)
 
     def open(self, version='', transaction=None, temporary=0, force=None,
              waitflag=1):
@@ -374,13 +365,11 @@
 
     def commit(self, txn):
         super(CommitVersion, self).commit(txn)
-        for oid in self._oids:
-            self._db.invalidate(oid, version=self._dest)
+        self._db.invalidate(self._oids, version=self._dest)
         if self._dest:
             # the code above just invalidated the dest version.
             # now we need to invalidate the source!
-            for oid in self._oids:
-                self._db.invalidate(oid, version=self._version)
+            self._db.invalidate(self._oids, version=self._version)
 
 class AbortVersion(SimpleDataManager):
     """An object that will see to version abortion."""
@@ -394,8 +383,7 @@
 
     def commit(self, txn):
         super(AbortVersion, self).commit(txn)
-        for oid in self._oids:
-            self._db.invalidate(oid, version=self._version)
+        self._db.invalidate(self._oids, version=self._version)
 
 class TransactionalUndo(SimpleDataManager):
     """An object that will see to transactional undo."""
@@ -409,5 +397,4 @@
 
     def commit(self, txn):
         super(TransactionalUndo, self).commit(txn)
-        for oid in self._oids:
-            self._db.invalidate(oid)
+        self._db.invalidate(self._oids)