[Zodb-checkins] CVS: ZODB3/ZODB - FileStorage.py:1.105.2.6

Jeremy Hylton jeremy@zope.com
Thu, 14 Nov 2002 12:01:46 -0500


Update of /cvs-repository/ZODB3/ZODB
In directory cvs.zope.org:/tmp/cvs-serv5883

Modified Files:
      Tag: ZODB3-3_1-branch
	FileStorage.py 
Log Message:
Various small cleanups to help make code understandable.

Move abortVersion() closer to commitVersion().
Replace seek() with read().
Add assertion about where file is point in abortVersion().
Replace variable p in abortVersion with data and bp, because
    p was holding two different things.


=== ZODB3/ZODB/FileStorage.py 1.105.2.5 => 1.105.2.6 ===
--- ZODB3/ZODB/FileStorage.py:1.105.2.5	Tue Nov  5 16:21:44 2002
+++ ZODB3/ZODB/FileStorage.py	Thu Nov 14 12:01:45 2002
@@ -309,9 +309,6 @@
         # hook to use something other than builtin dict
         return {}, {}, {}, {}
 
-    def abortVersion(self, src, transaction):
-        return self.commitVersion(src, '', transaction, abort=1)
-
     def _save_index(self):
         """Write the database index to a file to support quick startup
         """
@@ -441,6 +438,9 @@
             # XXX should log the error, though
             pass # We don't care if this fails.
 
+    def abortVersion(self, src, transaction):
+        return self.commitVersion(src, '', transaction, abort=1)
+
     def commitVersion(self, src, dest, transaction, abort=None):
         # We are going to commit by simply storing back pointers.
         if self._is_read_only:
@@ -521,6 +521,9 @@
                 here += heredelta
 
                 current_oids[oid] = 1
+                # Once we've found the data we are looking for,
+                # we can stop chasing backpointers.
+                break
 
             else:
                 # Hm.  This is a non-current record.  Is there a
@@ -2155,7 +2158,8 @@
         doid, serial, prev, tloc, vlen, plen = unpack(DATA_HDR, h)
 
         if vlen:
-            file.seek(vlen + 16, 1)
+            file.read(16)
+            version = file.read(vlen)
         if plen != z64:
             return file.read(U64(plen)), serial, old, tloc
         back = file.read(8) # We got a back pointer!
@@ -2407,6 +2411,11 @@
             else:
                 version = ''
 
+            datapos = pos + DATA_HDR_LEN
+            if vlen:
+                datapos += 16 + vlen
+            assert self._file.tell() == datapos, (self._file.tell(), datapos)
+
             if pos + dlen > self._tend or tloc != self._tpos:
                 warn("%s data record exceeds transaction record at %s",
                      file.name, pos)
@@ -2415,21 +2424,21 @@
             self._pos = pos + dlen
             tid = None
             if plen:
-                p = self._file.read(plen)
+                data = self._file.read(plen)
             else:
-                p = self._file.read(8)
-                if p == z64:
+                bp = self._file.read(8)
+                if bp == z64:
                     # If the backpointer is 0 (encoded as z64), then
                     # this transaction undoes the object creation.  It
                     # either aborts the version that created the
                     # object or undid the transaction that created it.
                     # Return None instead of a pickle to indicate
                     # this.
-                    p = None
+                    data = None
                 else:
-                    p, _s, tid = _loadBackTxn(self._file, oid, p)
+                    data, _s, tid = _loadBackTxn(self._file, oid, bp)
 
-            r = Record(oid, serial, version, p, tid)
+            r = Record(oid, serial, version, data, tid)
 
             return r