[Zodb-checkins] CVS: ZODB3/ZODB - fsrecover.py:1.8
Jeremy Hylton
jeremy at zope.com
Thu May 1 19:29:38 EDT 2003
Update of /cvs-repository/ZODB3/ZODB
In directory cvs.zope.org:/tmp/cvs-serv24754
Modified Files:
fsrecover.py
Log Message:
Rewrite scan for clarity. Add doc string and comment.
=== ZODB3/ZODB/fsrecover.py 1.7 => 1.8 ===
--- ZODB3/ZODB/fsrecover.py:1.7 Thu May 1 17:58:09 2003
+++ ZODB3/ZODB/fsrecover.py Thu May 1 18:29:37 2003
@@ -84,7 +84,7 @@
import getopt, ZODB.FileStorage, struct, time
from struct import unpack
-from ZODB.utils import t32, p64, U64
+from ZODB.utils import t32, p64, u64
from ZODB.TimeStamp import TimeStamp
from cPickle import loads
from ZODB.FileStorage import RecordIterator
@@ -150,25 +150,37 @@
return pos, result
-def scan(file, pos, file_size):
- seek=file.seek
- read=file.read
+def scan(file, pos):
+ """Return a potential transaction location following pos in file.
+
+ This routine scans forward from pos looking for the last data
+ record in a transaction. A period '.' always occurs at the end of
+ a pickle, and an 8-byte transaction length follows the last
+ pickle. If a period is followed by a plausible 8-byte transaction
+ length, assume that we have found the end of a transaction.
+
+ The caller should try to verify that the returned location is
+ actually a transaction header.
+ """
while 1:
- seek(pos)
- data=read(8096)
- if not data: return 0
+ file.seek(pos)
+ data = file.read(8096)
+ if not data:
+ return 0
- s=0
+ s = 0
while 1:
- l=data.find('.', s)
+ l = data.find('.', s)
if l < 0:
- pos=pos+8096
+ pos += len(data)
break
- if l > 8080:
- pos = pos + l
+ # If we are less than 8 bytes from the end of the
+ # string, we need to read more data.
+ if l > len(data) - 8:
+ pos += l
break
- s=l+1
- tl=U64(data[s:s+8])
+ s = l + 1
+ tl = u64(data[s:s+8])
if tl < pos:
return pos + s + 8
@@ -234,7 +246,7 @@
print "\n%s: %s\n" % sys.exc_info()[:2]
if not verbose:
progress(prog1)
- pos = scan(file, pos, file_size)
+ pos = scan(file, pos)
continue
if transaction is None:
@@ -298,7 +310,7 @@
print "\n%s: %s\n" % sys.exc_info()[:2]
if not verbose:
progress(prog1)
- pos = scan(file, pos, file_size)
+ pos = scan(file, pos)
else:
ofs.tpc_vote(transaction)
ofs.tpc_finish(transaction)
More information about the Zodb-checkins
mailing list