[Zodb-checkins] CVS: ZODB3/ZODB/FileStorage - fspack.py:1.3
Jeremy Hylton
jeremy at zope.com
Fri Jan 16 10:47:20 EST 2004
Update of /cvs-repository/ZODB3/ZODB/FileStorage
In directory cvs.zope.org:/tmp/cvs-serv19901/ZODB/FileStorage
Modified Files:
fspack.py
Log Message:
Add test and fix for the redundant pack bug.
Also remove some unused imports and a somewhat irrelevant comment.
=== ZODB3/ZODB/FileStorage/fspack.py 1.2 => 1.3 ===
--- ZODB3/ZODB/FileStorage/fspack.py:1.2 Wed Dec 24 11:01:59 2003
+++ ZODB3/ZODB/FileStorage/fspack.py Fri Jan 16 10:46:34 2004
@@ -24,17 +24,10 @@
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
from ZODB.referencesf import referencesf
-from ZODB.utils import p64, u64, z64, oid_repr
-from zLOG import LOG, BLATHER, WARNING, ERROR, PANIC
+from ZODB.utils import p64, u64, z64
from ZODB.fsIndex import fsIndex
from ZODB.FileStorage.format \
@@ -232,11 +225,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 = False
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 = True
tpos = pos
end = pos + th.tlen
@@ -260,6 +261,25 @@
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.
+ # XXX put exceptions in a separate module
+ from ZODB.FileStorage.FileStorage import FileStorageError
+ print "Yow!"
+ 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."""
todo = list(roots)
@@ -645,3 +665,4 @@
if self._lock_counter % 20 == 0:
self._commit_lock_acquire()
return ipos
+
More information about the Zodb-checkins
mailing list