[Zodb-checkins] CVS: StandaloneZODB/ZEO - ClientCache.py:1.16.2.2 ClientStorage.py:1.33.2.4 Invalidator.py:1.5.2.1

Jeremy Hylton jeremy@zope.com
Fri, 26 Oct 2001 13:20:37 -0400


Update of /cvs-repository/StandaloneZODB/ZEO
In directory cvs.zope.org:/tmp/cvs-serv17975

Modified Files:
      Tag: zeo-1_0-branch
	ClientCache.py ClientStorage.py Invalidator.py 
Log Message:
Eliminate leaks of Invalidator objects.

Explicitly break cycles in the closeIntensionally() call on
ClientStorage.  Add a close() method to Invalidator that gives up its
references to other objects.

XXX We still leak ClientCache objects for reasons I can't fathom.
We leak a ClientCache each time a ClientStorage object is created.
I'm not overly concerned because applications will almost certainly
create a single instance and not many.




=== StandaloneZODB/ZEO/ClientCache.py 1.16.2.1 => 1.16.2.2 ===
         try:
             self._f[self._current].close()
-        except OSError:
+        except ValueError:
             pass
 
     def open(self):
@@ -373,6 +373,8 @@
                     self._f[current]=open(self._p[current],'w+b')
                 else:
                     # Temporary cache file:
+                    if self._f[current] is not None:
+                        self._f[current].close()
                     self._f[current] = tempfile.TemporaryFile(suffix='.zec')
                 self._f[current].write(magic)
                 self._pos=pos=4


=== StandaloneZODB/ZEO/ClientStorage.py 1.33.2.3 => 1.33.2.4 ===
         # called until after this call.
 
-        invalidator=Invalidator.Invalidator(
-            db.invalidate,
-            self._cache.invalidate)
+        self.invalidator = Invalidator.Invalidator(db.invalidate,
+                                                   self._cache.invalidate)
 
         def out_of_band_hook(
             code, args,
             get_hook={
-                'b': (invalidator.begin, 0),
-                'i': (invalidator.invalidate, 1),
-                'e': (invalidator.end, 0),
-                'I': (invalidator.Invalidate, 1),
+                'b': (self.invalidator.begin, 0),
+                'i': (self.invalidator.invalidate, 1),
+                'e': (self.invalidator.end, 0),
+                'I': (self.invalidator.Invalidate, 1),
                 'U': (self._commit_lock_release, 0),
                 's': (self._serials.append, 1),
                 'S': (self._info.update, 1),
@@ -307,9 +306,12 @@
         try:
             LOG("ClientStorage", INFO, "close")
             self._call.closeIntensionally()
-            self._cache.close()
             self._tfile.close()
-            self.closed = 1 
+            self._cache.close()
+            if self.invalidator is not None:
+                self.invalidator.close()
+                self.invalidator = None
+            self.closed = 1
         finally: self._lock_release()
         
     def commitVersion(self, src, dest, transaction):
@@ -318,7 +320,6 @@
         self._lock_acquire()
         try:
             oids=self._call('commitVersion', src, dest, self._serial)
-            invalidate=self._cache.invalidate
             if dest:
                 vlen = pack(">H", len(src))
                 # just invalidate our version data
@@ -523,7 +524,6 @@
             seek=tfile.seek
             read=tfile.read
             cache=self._cache
-            update=cache.update
             size=tfile.tell()
             cache.checkSize(size)
             seek(0)
@@ -544,9 +544,9 @@
                             "temporary file."
                             )
                     if s==ResolvedSerial:
-                        cache.invalidate(oid, v)
+                        self._cache.invalidate(oid, v)
                     else:
-                        update(oid, s, v, p)
+                        self._cache.update(oid, s, v, p)
                     i=i+15+vlen+dlen
                 elif opcode == "i":
                     oid=read(8)
@@ -579,7 +579,8 @@
         try:
             oids=self._call('undo', transaction_id)
             cinvalidate=self._cache.invalidate
-            for oid in oids: cinvalidate(oid,'')                
+            for oid in oids:
+                cinvalidate(oid,'')                
             return oids
         finally: self._lock_release()
 


=== StandaloneZODB/ZEO/Invalidator.py 1.5 => 1.5.2.1 ===
         self.cinvalidate=cinvalidate
 
+    def close(self):
+        self.dinvalidate = None
+        self.cinvalidate = None
+
     def begin(self):
         self._tfile=tempfile.TemporaryFile()
         pickler=cPickle.Pickler(self._tfile, 1)