Commit 844a079a authored by Tim Peters's avatar Tim Peters

Merge rev 30984 from 3.4 branch.

read_index():  Mechanical reformat for easier reading.
parent ee9d1302
...@@ -1620,7 +1620,7 @@ def read_index(file, name, index, vindex, tindex, stop='\377'*8, ...@@ -1620,7 +1620,7 @@ def read_index(file, name, index, vindex, tindex, stop='\377'*8,
read = file.read read = file.read
seek = file.seek seek = file.seek
seek(0, 2) seek(0, 2)
file_size=file.tell() file_size = file.tell()
fmt = TempFormatter(file) fmt = TempFormatter(file)
if file_size: if file_size:
...@@ -1634,16 +1634,17 @@ def read_index(file, name, index, vindex, tindex, stop='\377'*8, ...@@ -1634,16 +1634,17 @@ def read_index(file, name, index, vindex, tindex, stop='\377'*8,
file.write(packed_version) file.write(packed_version)
return 4L, z64, ltid return 4L, z64, ltid
index_get=index.get index_get = index.get
pos=start pos = start
seek(start) seek(start)
tid='\0'*7+'\1' tid = '\0' * 7 + '\1'
while 1: while 1:
# Read the transaction record # Read the transaction record
h=read(TRANS_HDR_LEN) h = read(TRANS_HDR_LEN)
if not h: break if not h:
break
if len(h) != TRANS_HDR_LEN: if len(h) != TRANS_HDR_LEN:
if not read_only: if not read_only:
logger.warning('%s truncated at %s', name, pos) logger.warning('%s truncated at %s', name, pos)
...@@ -1651,8 +1652,9 @@ def read_index(file, name, index, vindex, tindex, stop='\377'*8, ...@@ -1651,8 +1652,9 @@ def read_index(file, name, index, vindex, tindex, stop='\377'*8,
file.truncate() file.truncate()
break break
tid, tl, status, ul, dl, el = unpack(TRANS_HDR,h) tid, tl, status, ul, dl, el = unpack(TRANS_HDR, h)
if el < 0: el=t32-el if el < 0:
el = t32 - el
if tid <= ltid: if tid <= ltid:
logger.warning("%s time-stamp reduction at %s", name, pos) logger.warning("%s time-stamp reduction at %s", name, pos)
...@@ -1672,14 +1674,14 @@ def read_index(file, name, index, vindex, tindex, stop='\377'*8, ...@@ -1672,14 +1674,14 @@ def read_index(file, name, index, vindex, tindex, stop='\377'*8,
logger.warning('%s has invalid status, %s, at %s', logger.warning('%s has invalid status, %s, at %s',
name, status, pos) name, status, pos)
if tl < (TRANS_HDR_LEN+ul+dl+el): if tl < TRANS_HDR_LEN + ul + dl + el:
# We're in trouble. Find out if this is bad data in the # 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 # middle of the file, or just a turd that Win 9x dropped
# at the end when the system crashed. # at the end when the system crashed.
# Skip to the end and read what should be the transaction length # Skip to the end and read what should be the transaction length
# of the last transaction. # of the last transaction.
seek(-8, 2) seek(-8, 2)
rtl=u64(read(8)) rtl = u64(read(8))
# Now check to see if the redundant transaction length is # Now check to see if the redundant transaction length is
# reasonable: # reasonable:
if file_size - rtl < pos or rtl < TRANS_HDR_LEN: if file_size - rtl < pos or rtl < TRANS_HDR_LEN:
...@@ -1693,7 +1695,8 @@ def read_index(file, name, index, vindex, tindex, stop='\377'*8, ...@@ -1693,7 +1695,8 @@ def read_index(file, name, index, vindex, tindex, stop='\377'*8,
_truncate(file, name, pos) _truncate(file, name, pos)
break break
else: else:
if recover: return pos, None, None if recover:
return pos, None, None
panic('%s has invalid transaction header at %s', name, pos) panic('%s has invalid transaction header at %s', name, pos)
if tid >= stop: if tid >= stop:
...@@ -1702,18 +1705,19 @@ def read_index(file, name, index, vindex, tindex, stop='\377'*8, ...@@ -1702,18 +1705,19 @@ def read_index(file, name, index, vindex, tindex, stop='\377'*8,
tpos = pos tpos = pos
tend = tpos + tl tend = tpos + tl
if status=='u': if status == 'u':
# Undone transaction, skip it # Undone transaction, skip it
seek(tend) seek(tend)
h = u64(read(8)) h = u64(read(8))
if h != tl: if h != tl:
if recover: return tpos, None, None if recover:
return tpos, None, None
panic('%s has inconsistent transaction length at %s', panic('%s has inconsistent transaction length at %s',
name, pos) name, pos)
pos = tend + 8 pos = tend + 8
continue continue
pos = tpos+ TRANS_HDR_LEN + ul + dl + el pos = tpos + TRANS_HDR_LEN + ul + dl + el
while pos < tend: while pos < tend:
# Read the data records for this transaction # Read the data records for this transaction
h = fmt._read_data_header(pos) h = fmt._read_data_header(pos)
...@@ -1731,7 +1735,8 @@ def read_index(file, name, index, vindex, tindex, stop='\377'*8, ...@@ -1731,7 +1735,8 @@ def read_index(file, name, index, vindex, tindex, stop='\377'*8,
if index_get(h.oid, 0) != h.prev: if index_get(h.oid, 0) != h.prev:
if prev: if prev:
if recover: return tpos, None, None if recover:
return tpos, None, None
logger.error("%s incorrect previous pointer at %s", logger.error("%s incorrect previous pointer at %s",
name, pos) name, pos)
else: else:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment