[Zodb-checkins] SVN: ZODB/branches/3.8/src/ZEO/cache.py Added assertion data.

Jim Fulton jim at zope.com
Wed May 28 16:31:38 EDT 2008


Log message for revision 87003:
  Added assertion data.
  

Changed:
  U   ZODB/branches/3.8/src/ZEO/cache.py

-=-
Modified: ZODB/branches/3.8/src/ZEO/cache.py
===================================================================
--- ZODB/branches/3.8/src/ZEO/cache.py	2008-05-28 18:52:47 UTC (rev 87002)
+++ ZODB/branches/3.8/src/ZEO/cache.py	2008-05-28 20:31:33 UTC (rev 87003)
@@ -233,6 +233,9 @@
         # file, and tell our parent about it too (via the `install` callback).
         # Remember the location of the largest free block.  That seems a
         # decent place to start currentofs.
+
+        self.current = ZODB.fsIndex.fsIndex()
+        self.noncurrent = BTrees.LOBTree.LOBTree()
         max_free_size = l = 0
         ofs = max_free_offset = ZEC3_HEADER_SIZE
         current = self.current
@@ -243,9 +246,10 @@
                 size, oid, start_tid, end_tid = unpack(">I8s8s8s", read(28))
 
                 if end_tid == z64:
+                    assert oid not in current, (ofs, self.f.tell())
                     current[oid] = ofs
                 else:
-                    assert start_tid < end_tid
+                    assert start_tid < end_tid, (ofs, self.f.tell())
                     self._set_noncurrent(oid, start_tid, ofs)
                 l += 1
             elif status == 'f':
@@ -296,12 +300,12 @@
     # Close the underlying file.  No methods accessing the cache should be
     # used after this.
     def close(self):
-        if hasattr(self,'_lock_file'):
-            self._lock_file.close()
         if self.f:
             sync(self.f)
             self.f.close()
             self.f = None
+        if hasattr(self,'_lock_file'):
+            self._lock_file.close()
 
     ##
     # Evict objects as necessary to free up at least nbytes bytes,
@@ -315,7 +319,8 @@
     # freed (starting at currentofs when _makeroom returns, and
     # spanning the number of bytes retured by _makeroom).
     def _makeroom(self, nbytes):
-        assert 0 < nbytes <= self.maxsize - ZEC3_HEADER_SIZE
+        assert 0 < nbytes <= self.maxsize - ZEC3_HEADER_SIZE, (
+            nbytes, self.maxsize)
         if self.currentofs + nbytes > self.maxsize:
             self.currentofs = ZEC3_HEADER_SIZE
         ofs = self.currentofs
@@ -353,7 +358,7 @@
             raise ValueError("new last tid (%s) must be greater than "
                              "previous one (%s)" % (u64(tid),
                                                     u64(self.tid)))
-        assert isinstance(tid, str) and len(tid) == 8
+        assert isinstance(tid, str) and len(tid) == 8, tid
         self.tid = tid
         self.f.seek(len(magic))
         self.f.write(tid)
@@ -384,10 +389,10 @@
             return None
         self.f.seek(ofs)
         read = self.f.read
-        assert read(1) == 'a'
+        assert read(1) == 'a', (ofs, self.f.tell(), oid)
         size, saved_oid, tid, end_tid, lver, ldata = unpack(
             ">I8s8s8shI", read(34))
-        assert saved_oid == oid
+        assert saved_oid == oid, (ofs, self.f.tell(), oid, saved_oid)
         if lver or version:
             if lver != len(version) or read(lver) != version:
                 self._trace(0x20, oid, version)
@@ -395,8 +400,8 @@
         
         
         data = read(ldata)
-        assert len(data) == ldata
-        assert read(8) == oid
+        assert len(data) == ldata, (ofs, self.f.tell(), oid, len(data), ldata)
+        assert read(8) == oid, (ofs, self.f.tell(), oid) 
 
         self._n_accesses += 1
         self._trace(0x22, oid, version, tid, end_tid, ldata)
@@ -423,16 +428,16 @@
 
         self.f.seek(ofs)
         read = self.f.read
-        assert read(1) == 'a'
+        assert read(1) == 'a', (ofs, self.f.tell(), oid, before_tid)
         size, saved_oid, saved_tid, end_tid, lver, ldata = unpack(
             ">I8s8s8shI", read(34))
-        assert saved_oid == oid
-        assert saved_tid == p64(tid)
-        assert lver == 0
-        assert end_tid != z64
+        assert saved_oid == oid, (ofs, self.f.tell(), oid, saved_oid)
+        assert saved_tid == p64(tid), (ofs, self.f.tell(), oid, saved_tid, tid)
+        assert lver == 0, (ofs, self.f.tell())
+        assert end_tid != z64, (ofs, self.f.tell(), oid)
         data = read(ldata)
-        assert len(data) == ldata
-        assert read(8) == oid
+        assert len(data) == ldata, (ofs, self.f.tell())
+        assert read(8) == oid, (ofs, self.f.tell(), oid)
         
         if end_tid < before_tid:
             self._trace(0x24, oid, "", before_tid)
@@ -456,10 +461,10 @@
             return None
         self.f.seek(ofs)
         read = self.f.read
-        assert self.f.read(1) == 'a'
+        assert self.f.read(1) == 'a', (ofs, self.f.tell(), oid)
         size, saved_oid, saved_tid, end_tid, lver, ldata = unpack(
             ">I8s8s8shI", read(34))
-        assert saved_oid == oid
+        assert saved_oid == oid, (ofs, self.f.tell(), oid, saved_oid)
         if lver:
             return read(lver)
         return None
@@ -490,11 +495,11 @@
             if ofs:
                 seek(ofs)
                 read = self.f.read
-                assert read(1) == 'a'
+                assert read(1) == 'a', (ofs, self.f.tell(), oid)
                 size, saved_oid, saved_tid, end_tid = unpack(
                     ">I8s8s8s", read(28))
-                assert saved_oid == oid
-                assert end_tid == z64
+                assert saved_oid == oid, (ofs, self.f.tell(), oid, saved_oid)
+                assert end_tid == z64, (ofs, self.f.tell(), oid)
                 if saved_tid == start_tid:
                     return
                 raise ValueError("already have current data for oid")
@@ -520,7 +525,7 @@
         self._len += 1
 
         nfreebytes = self._makeroom(size)
-        assert size <= nfreebytes
+        assert size <= nfreebytes, (size, nfreebytes)
         excess = nfreebytes - size
         # If there's any excess (which is likely), we need to record a
         # free block following the end of the data record.  That isn't
@@ -593,11 +598,11 @@
 
         self.f.seek(ofs)
         read = self.f.read
-        assert read(1) == 'a'
+        assert read(1) == 'a', (ofs, self.f.tell(), oid)
         size, saved_oid, saved_tid, end_tid, lver = unpack(
             ">I8s8s8sh", read(30))
-        assert saved_oid == oid
-        assert end_tid == z64
+        assert saved_oid == oid, (ofs, self.f.tell(), oid, saved_oid)
+        assert end_tid == z64, (ofs, self.f.tell(), oid)
         del self.current[oid]
         if tid is None or lver:
             self.f.seek(ofs)
@@ -626,10 +631,10 @@
         read = self.f.read
         for oid, ofs in self.current.iteritems():
             seek(ofs)
-            assert read(1) == 'a'
+            assert read(1) == 'a', (ofs, self.f.tell(), oid)
             size, saved_oid, tid, end_tid, lver = unpack(">I8s8s8sh", read(30))
-            assert saved_oid == oid
-            assert end_tid == z64
+            assert saved_oid == oid, (ofs, self.f.tell(), oid, saved_oid)
+            assert end_tid == z64, (ofs, self.f.tell(), oid)
             if lver:
                 version = read(lver)
             else:
@@ -697,7 +702,6 @@
         self._trace = _trace
         _trace(0x00)
 
-
 def sync(f):
     f.flush()
 



More information about the Zodb-checkins mailing list