[Zodb-checkins] CVS: Zope3/src/zodb/storage - file.py:1.8.2.2
Jeremy Hylton
jeremy@zope.com
Tue, 18 Feb 2003 19:53:00 -0500
Update of /cvs-repository/Zope3/src/zodb/storage
In directory cvs.zope.org:/tmp/cvs-serv14806
Modified Files:
Tag: ZODB3-2-integration-branch
file.py
Log Message:
Remove unused Xread_index() function.
=== Zope3/src/zodb/storage/file.py 1.8.2.1 => 1.8.2.2 ===
--- Zope3/src/zodb/storage/file.py:1.8.2.1 Fri Feb 14 15:33:53 2003
+++ Zope3/src/zodb/storage/file.py Tue Feb 18 19:52:59 2003
@@ -1984,171 +1984,6 @@
pos-opos, npos)
-
-def Xread_index(file, name, index, vindex, tindex, stop='\377'*8,
- ltid=z64, start=4L, maxoid=z64, recover=0, read_only=0):
- """Scan the entire file storage and recreate the index.
-
- Returns file position, max oid, and last transaction id. It also
- stores index information in the three dictionary arguments.
-
- Arguments:
- file -- a file object (the Data.fs)
- name -- the name of the file (presumably file.name)
- index -- dictionary, oid -> data record
- vindex -- dictionary, oid -> data record for version data
- tindex -- dictionary, oid -> data record
- XXX tindex is cleared before return, so it will be empty
-
- There are several default arguments that affect the scan or the
- return values. XXX should document them.
-
- The file position returned is the position just after the last
- valid transaction record. The oid returned is the maximum object
- id in the data. The transaction id is the tid of the last
- transaction.
- """
- read = file.read
- seek = file.seek
- seek(0, 2)
- file_size=file.tell()
-
- if file_size:
- if file_size < start: raise FileStorageFormatError, file.name
- seek(0)
- if read(4) != packed_version: raise FileStorageFormatError, name
- else:
- if not read_only: file.write(packed_version)
- return 4L, maxoid, ltid
-
- index_get=index.get
-
- pos=start
- seek(start)
- tid='\0'*7+'\1'
-
- while 1:
- # Read the transaction record
- h=read(TRANS_HDR_LEN)
- if not h: break
- if len(h) != TRANS_HDR_LEN:
- if not read_only:
- warn('%s truncated at %s', name, pos)
- seek(pos)
- file.truncate()
- break
-
- tid, tl, status, ul, dl, el = unpack(TRANS_HDR,h)
- if el < 0: el=t32-el
-
- if tid <= ltid:
- warn("%s time-stamp reduction at %s", name, pos)
- ltid=tid
-
- if pos+(tl+8) > file_size or status=='c':
- # Hm, the data were truncated or the checkpoint flag wasn't
- # cleared. They may also be corrupted,
- # in which case, we don't want to totally lose the data.
- if not read_only:
- warn("%s truncated, possibly due to damaged records at %s",
- name, pos)
- _truncate(file, name, pos)
- break
-
- if status not in ' up':
- warn('%s has invalid status, %s, at %s', name, status, pos)
-
- 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 the end and read what should be the transaction length
- # of the last transaction.
- seek(-8, 2)
- rtl=u64(read(8))
- # Now check to see if the redundant transaction length is
- # reasonable:
- if file_size - rtl < pos or rtl < TRANS_HDR_LEN:
- nearPanic('%s has invalid transaction header at %s', name, pos)
- if not read_only:
- warn("It appears that there is invalid data at the end of "
- "the file, possibly due to a system crash. %s "
- "truncated to recover from bad data at end.",
- name)
- _truncate(file, name, pos)
- break
- else:
- if recover: return pos, None, None
- panic('%s has invalid transaction header at %s', name, pos)
-
- if tid >= stop: break
-
- tpos=pos
- tend=tpos+tl
-
- if status=='u':
- # Undone transaction, skip it
- seek(tend)
- h=read(8)
- if h != stl:
- if recover: return tpos, None, None
- panic('%s has inconsistent transaction length at %s',
- name, pos)
- pos=tend+8
- continue
-
- pos=tpos+(TRANS_HDR_LEN+ul+dl+el)
- while pos < tend:
- # Read the data records for this transaction
-
- seek(pos)
- h=read(DATA_HDR_LEN)
- oid,serial,prev,tloc,vlen,plen = unpack(DATA_HDR, h)
- dlen=DATA_HDR_LEN+(plen or 8)
- tindex[oid]=pos
-
- if vlen:
- dlen=dlen+(16+vlen)
- read(16)
- version=read(vlen)
- vindex[version]=pos
-
- if pos+dlen > tend or tloc != tpos:
- if recover: return tpos, None, None
- panic("%s data record exceeds transaction record at %s",
- name, pos)
-
- if index_get(oid, 0) != prev:
- if prev:
- if recover: return tpos, None, None
- error("%s incorrect previous pointer at %s", name, pos)
- else:
- warn("%s incorrect previous pointer at %s", name, pos)
-
- pos=pos+dlen
-
- if pos != tend:
- if recover: return tpos, None, None
- panic("%s data records don't add up at %s",name,tpos)
-
- # Read the (intentionally redundant) transaction length
- seek(pos)
- l = u64(read(8))
- if l != tl:
- if recover: return tpos, None, None
- panic("%s redundant transaction length check failed at %s",
- name, pos)
- pos += 8
-
- if tindex: # avoid the pathological empty transaction case
- _maxoid = max(tindex.keys()) # in 2.2, just max(tindex)
- maxoid = max(_maxoid, maxoid)
- index.update(tindex)
- tindex.clear()
-
- return pos, maxoid, ltid
-
-
def _truncate(file, name, pos):
seek=file.seek
seek(0,2)