[Zodb-checkins] CVS: Zope/lib/python/ZODB - fspack.py:1.5.4.7

Jeremy Hylton jeremy at zope.com
Fri Jan 16 12:24:14 EST 2004


Update of /cvs-repository/Zope/lib/python/ZODB
In directory cvs.zope.org:/tmp/cvs-serv5411/lib/python/ZODB

Modified Files:
      Tag: Zope-2_6-branch
	fspack.py 
Log Message:
Fix for FileStorage redundant pack bug.

Backported from the trunk.


=== Zope/lib/python/ZODB/fspack.py 1.5.4.6 => 1.5.4.7 ===
--- Zope/lib/python/ZODB/fspack.py:1.5.4.6	Mon Aug  4 05:26:42 2003
+++ Zope/lib/python/ZODB/fspack.py	Fri Jan 16 12:23:43 2004
@@ -24,10 +24,6 @@
 a backpointer after that time.
 """
 
-# This module contains code backported from ZODB4 from the
-# zodb.storage.file package.  It's been edited heavily to work with
-# ZODB3 code and storage layout.
-
 import os
 import struct
 from types import StringType
@@ -471,11 +467,19 @@
 
     def buildPackIndex(self):
         pos = 4L
+        # We make the initial assumption that the database has been
+        # packed before and set unpacked to True only after seeing the
+        # first record with a status == " ".  If we get to the packtime
+        # and unpacked is still False, we need to watch for a redundant
+        # pack.
+        unpacked = 0
         while pos < self.eof:
             th = self._read_txn_header(pos)
             if th.tid > self.packtime:
                 break
             self.checkTxn(th, pos)
+            if th.status != "p":
+                unpacked = 1
 
             tpos = pos
             end = pos + th.tlen
@@ -498,6 +502,23 @@
             pos += 8
 
         self.packpos = pos
+
+        if unpacked:
+            return
+        # check for a redundant pack.  If the first record following
+        # the newly computed packpos has status 'p', then it was
+        # packed earlier and the current pack is redudant.
+        try:
+            th = self._read_txn_header(pos)
+        except CorruptedDataError, err:
+            if err.buf != "": 
+                raise
+        if th.status == 'p':
+            # Delay import to code with circular imports.
+            from ZODB.FileStorage import FileStorageError
+            raise FileStorageError(
+                "The database has already been packed to a later time"
+                " or no changes have been made since the last pack")
 
     def findReachableAtPacktime(self, roots):
         """Mark all objects reachable from the oids in roots as reachable."""




More information about the Zodb-checkins mailing list