[Zodb-checkins] CVS: StandaloneZODB/ZODB - FileStorage.py:1.80
Jeremy Hylton
jeremy@zope.com
Fri, 25 Jan 2002 11:52:07 -0500
Update of /cvs-repository/StandaloneZODB/ZODB
In directory cvs.zope.org:/tmp/cvs-serv31344
Modified Files:
FileStorage.py
Log Message:
Code cleanup.
Replace three small integers with symbolic constants.
TRANS_HDR_LEN = 23
DATA_HDR_LEN = 42
DATA_VERSION_HDR_LEN = 58
The constants make it easier to remember what kind of header is being
read and/or what kind of offset is being computed.
Refactor commitVersion():
- Keep locking & arg checking in commitVersion(), but move actual
commit logic to _commitVersion(). This removes a level of
indentation.
- Remove local vars that alias attributes of other vars
Add a few more POSKeyError exceptions.
=== StandaloneZODB/ZODB/FileStorage.py 1.79 => 1.80 === (604/704 lines abridged)
z64='\0'*8
+# constants to support various header sizes
+TRANS_HDR_LEN = 23
+DATA_HDR_LEN = 42
+DATA_VERSION_HDR_LEN = 58
def warn(message, *data):
LOG('ZODB FS',WARNING, "%s warn: %s\n" % (packed_version, (message % data)))
@@ -329,25 +333,26 @@
pos=pos-tl-8
if pos < 4: return 0
seek(pos)
- tid, stl, status, ul, dl, el = unpack(">8s8scHHH", read(23))
+ s = read(TRANS_HDR_LEN)
+ tid, stl, status, ul, dl, el = unpack(">8s8scHHH", s)
if not ltid: ltid=tid
if stl != rstl: return 0 # inconsistent lengths
if status == 'u': continue # undone trans, search back
if status not in ' p': return 0
- if tl < (23+ul+dl+el): return 0
+ if tl < (TRANS_HDR_LEN + ul + dl + el): return 0
tend=pos+tl
- opos=pos+(23+ul+dl+el)
+ opos=pos+(TRANS_HDR_LEN + ul + dl + el)
if opos==tend: continue # empty trans
while opos < tend:
# Read the data records for this transaction
seek(opos)
- h=read(42)
+ h=read(DATA_HDR_LEN)
oid,serial,sprev,stloc,vlen,splen = unpack(">8s8s8s8sH8s", h)
tloc=U64(stloc)
plen=U64(splen)
- dlen=42+(plen or 8)
+ dlen=DATA_HDR_LEN+(plen or 8)
if vlen: dlen=dlen+(16+vlen)
if opos+dlen > tend or tloc != pos: return 0
@@ -422,86 +427,85 @@
self._lock_acquire()
try:
- read=self._file.read
- seek=self._file.seek
- tfile=self._tfile
- write=tfile.write
- tindex=self._tindex
[-=- -=- -=- 604 lines omitted -=- -=- -=-]
- if tl < (23+ul+dl+el):
+ if tl < (TRANS_HDR_LEN+ul+dl+el):
# We're in trouble. Find out if this is bad data in
# the middle of the file, or just a turd that Win 9x
# dropped at the end when the system crashed. Skip to
@@ -2192,7 +2201,7 @@
rtl=U64(read(8))
# Now check to see if the redundant transaction length is
# reasonable:
- if self._file_size - rtl < pos or rtl < 23:
+ if self._file_size - rtl < pos or rtl < TRANS_HDR_LEN:
nearPanic('%s has invalid transaction header at %s',
self._file.name, pos)
warn("It appears that there is invalid data at the end of "
@@ -2225,7 +2234,7 @@
pos=tend+8
continue
- pos=tpos+(23+ul+dl+el)
+ pos=tpos+(TRANS_HDR_LEN+ul+dl+el)
user=read(ul)
description=read(dl)
if el:
@@ -2273,15 +2282,14 @@
tend, file, seek, read, tpos = self._stuff
while pos < tend:
# Read the data records for this transaction
-
seek(pos)
- h=read(42)
+ h=read(DATA_HDR_LEN)
oid,serial,sprev,stloc,vlen,splen = unpack(">8s8s8s8sH8s", h)
prev=U64(sprev)
tloc=U64(stloc)
plen=U64(splen)
- dlen=42+(plen or 8)
+ dlen=DATA_HDR_LEN+(plen or 8)
if vlen:
dlen=dlen+(16+vlen)
@@ -2312,7 +2320,7 @@
else:
p = _loadBack(file, oid, p)[0]
- r=Record(oid, serial, version, p)
+ r = Record(oid, serial, version, p)
return r