[Zodb-checkins] CVS: Zope3/src/zodb/storage - file.py:1.8.4.5

Jeremy Hylton jeremy@zope.com
Mon, 10 Mar 2003 15:59:11 -0500


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

Modified Files:
      Tag: opaque-pickles-branch
	file.py 
Log Message:
Bunch of small fixes and improvements.

Write refsdata then pickle data!

Change datalen() to recordlen().  It's the length of the whole record.
Add a few explanatory comments.
Probable corrections for refs handling in packing, ppos != pos branch.


=== Zope3/src/zodb/storage/file.py 1.8.4.4 => 1.8.4.5 ===
--- Zope3/src/zodb/storage/file.py:1.8.4.4	Mon Mar 10 15:22:45 2003
+++ Zope3/src/zodb/storage/file.py	Mon Mar 10 15:59:10 2003
@@ -348,7 +348,7 @@
             while pos < tend:
                 # Read the data records for this transaction
                 h = self._read_data_header(pos)
-                dlen = h.datalen()
+                dlen = h.recordlen()
                 tindex[h.oid] = pos
 
                 if h.version:
@@ -458,6 +458,7 @@
                 # If backpointer is 0, object does not currently exist.
                 raise POSKeyError(oid)
             h = self._read_data_header(back)
+            self._file.read(h.nrefs * 8)
             if h.plen:
                 return self._file.read(h.plen), h.serial, back, h.tloc
             back = h.back
@@ -1593,6 +1594,7 @@
         return self._file.read(1) != ' ' # XXX or == "p"?
 
     def _pack_index(self, index):
+        # Return an index for everything reachable at the pack time.
         rootl = [ZERO]
         pindex = fsIndex()
         while rootl:
@@ -1612,6 +1614,7 @@
         # Step 1, get index as of pack time that has only referenced objects.
         index = fsIndex()
         vindex = {}
+        # tindex is the index for the current transaction
         tindex = {}
         tvindex = {}
         packpos, maxoid, ltid = self._read_index(index, vindex, tindex,
@@ -1697,7 +1700,7 @@
             while pos < tend:
                 # Read the data records for this transaction
                 h = self._read_data_header(pos)
-                dlen = h.datalen()
+                dlen = h.recordlen()
                 if h.version:
                     dlen += 16 + h.vlen
                     if packing and pindex.get(oid, 0) != pos:
@@ -1710,6 +1713,8 @@
                     vindex[h.version] = opos
                 else:
                     if packing:
+                        # ppos and ph are the record pos and header as
+                        # of the pack time.
                         ppos = pindex.get(h.oid, 0)
                         if ppos != pos:
                             if not ppos:
@@ -1717,15 +1722,15 @@
                                 pos += dlen
                                 continue
 
-                            # This is not the most current record
-                            # But maybe it's the most current committed
-                            # record.
+                            # This is not the most current record, but
+                            # maybe it's the most current committed record.
                             ph = self._read_data_header(ppos)
                             if not ph.version:
                                 # The most current record is committed, so
                                 # we can toss this one
                                 pos += dlen
                                 continue
+                            self._file.read(ph.nrefs * 8)
                             pnv = self._loadBackPOS(h.oid, ph.pnv)
                             if pnv > pos:
                                 # The current non version data is later,
@@ -1738,8 +1743,7 @@
                             # pickle, but we're in the wrong place, after
                             # wandering around to figure out if we were
                             # current.  Seek back to pickle data.
-                            self._file.seek(pos + DATA_HDR_LEN +
-                                            ph.nrefs * 8)
+                            self._file.seek(pos + DATA_HDR_LEN)
 
                         nvindex[h.oid] = opos
 
@@ -1807,10 +1811,8 @@
                         ofile.write(p64(pnv))
                     ofile.write(pv)
                     ofile.write(version)
-                ofile.write(p)
-
-                # Write the references string
                 ofile.write(refsdata)
+                ofile.write(p)
 
             # skip the (intentionally redundant) transaction length
             pos += 8
@@ -2063,7 +2065,7 @@
         while pos < self._tend:
             # Read the data records for this transaction
             h = self._read_data_header(pos)
-            dlen = h.datalen()
+            dlen = h.recordlen()
             if h.version:
                 dlen += 16 + h.vlen
             if pos + dlen > self._tend or h.tloc != self._tpos:
@@ -2191,7 +2193,7 @@
         self.pnv, self.vprev = struct.unpack(">QQ", buf[:16])
         self.version = buf[16:]
 
-    def datalen(self):
+    def recordlen(self):
         return DATA_HDR_LEN + (self.nrefs * 8) + (self.plen or 8)