[Zodb-checkins] CVS: StandaloneZODB/ZODB - FileStorage.py:1.76.8.4

Guido van Rossum guido@python.org
Fri, 4 Jan 2002 09:11:36 -0500


Update of /cvs-repository/StandaloneZODB/ZODB
In directory cvs.zope.org:/tmp/cvs-serv26341

Modified Files:
      Tag: Standby-branch
	FileStorage.py 
Log Message:
_skip_to_start(): Thanks to Tim's analysis, fix the bug in the
consistency checking at the end.  The bug might have been caused by
adding the consistency checking code: without the read(8) there, it
would have worked!  Also rewrote the essential part of the code to
avoid doing a tell() call, doing straight arithmetic on self._pos
instead, while still allowing this to work for positions > sys.maxint.

(Contrary to popular belief, relative seek isn't any faster than an
absolute seek; a tell call is definitely more expensive than an add. :-)


=== StandaloneZODB/ZODB/FileStorage.py 1.76.8.3 => 1.76.8.4 ===
         # Scan through the transaction records doing almost no sanity
         # checks. 
-        self._file.seek(self._pos)
         while 1:
-            self._pos = self._file.tell()
+            self._file.seek(self._pos)
             h = self._file.read(16)
             if len(h) < 16:
                 return
@@ -2033,13 +2032,19 @@
             if tid >= start:
                 return
             tl = U64(stl)
-            self._file.seek(tl - 8, 1)
-            rtl = self._file.read(8)
-            if rtl != stl:
-                pos = self._file.tell() - 8
-                panic("%s has inconsistent transaction length at %s "
-                      "(%s != %s)",
-                      self._file.name, pos, rtl, stl)
+            try:
+                self._pos += tl + 8
+            except OverflowError:
+                self._pos = long(self._pos) + tl + 8
+            if __debug__:
+                # Sanity check
+                self._file.seek(self._pos - 8, 0)
+                rtl = self._file.read(8)
+                if rtl != stl:
+                    pos = self._file.tell() - 8
+                    panic("%s has inconsistent transaction length at %s "
+                          "(%s != %s)",
+                          self._file.name, pos, U64(rtl), U64(stl))
 
     def next(self, index=0):
         file=self._file