Commit 973d486b authored by Jeremy Hylton's avatar Jeremy Hylton

Various small cleanups, mostly from pychecker.

Remove useless register_subsystem() calls.
Define PackError instead of raising string exception.
Remove unused _stuff argument from load().
Remove unused tid argument from _txn_undo_write().
Replace seek() and unused read()s with single read().
Remove unused local variables.
parent 423908a9
...@@ -115,7 +115,7 @@ ...@@ -115,7 +115,7 @@
# may have a back pointer to a version record or to a non-version # may have a back pointer to a version record or to a non-version
# record. # record.
# #
__version__='$Revision: 1.113 $'[11:-2] __version__='$Revision: 1.114 $'[11:-2]
import base64 import base64
from cPickle import Pickler, Unpickler, loads from cPickle import Pickler, Unpickler, loads
...@@ -145,7 +145,6 @@ except ImportError: ...@@ -145,7 +145,6 @@ except ImportError:
return {} return {}
from zLOG import LOG, BLATHER, WARNING, ERROR, PANIC, register_subsystem from zLOG import LOG, BLATHER, WARNING, ERROR, PANIC, register_subsystem
register_subsystem('ZODB FS')
z64='\0'*8 z64='\0'*8
# the struct formats for the headers # the struct formats for the headers
...@@ -176,7 +175,11 @@ def panic(message, *data): ...@@ -176,7 +175,11 @@ def panic(message, *data):
LOG('ZODB FS', PANIC, "%s ERROR: %s\n" % (packed_version, message)) LOG('ZODB FS', PANIC, "%s ERROR: %s\n" % (packed_version, message))
raise CorruptedTransactionError, message raise CorruptedTransactionError, message
class FileStorageError(POSException.StorageError): pass class FileStorageError(POSException.StorageError):
pass
class PackError(FileStorageError):
pass
class FileStorageFormatError(FileStorageError): class FileStorageFormatError(FileStorageError):
"""Invalid file format """Invalid file format
...@@ -617,7 +620,7 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -617,7 +620,7 @@ class FileStorage(BaseStorage.BaseStorage,
# will get checked when we store. # will get checked when we store.
return _loadBack(file, oid, pnv)[0], serial return _loadBack(file, oid, pnv)[0], serial
def load(self, oid, version, _stuff=None): def load(self, oid, version):
self._lock_acquire() self._lock_acquire()
try: try:
return self._load(oid, version, self._index, self._file) return self._load(oid, version, self._index, self._file)
...@@ -1135,7 +1138,7 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -1135,7 +1138,7 @@ class FileStorage(BaseStorage.BaseStorage,
tid = base64.decodestring(transaction_id + '\n') tid = base64.decodestring(transaction_id + '\n')
assert len(tid) == 8 assert len(tid) == 8
tpos = self._txn_find(tid) tpos = self._txn_find(tid)
tindex = self._txn_undo_write(tpos, tid) tindex = self._txn_undo_write(tpos)
self._tindex.update(tindex) self._tindex.update(tindex)
return tindex.keys() return tindex.keys()
...@@ -1155,7 +1158,7 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -1155,7 +1158,7 @@ class FileStorage(BaseStorage.BaseStorage,
break break
raise UndoError("Invalid transaction id") raise UndoError("Invalid transaction id")
def _txn_undo_write(self, tpos, tid): def _txn_undo_write(self, tpos):
# a helper function to write the data records for transactional undo # a helper function to write the data records for transactional undo
ostloc = p64(self._pos) ostloc = p64(self._pos)
...@@ -1295,8 +1298,7 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -1295,8 +1298,7 @@ class FileStorage(BaseStorage.BaseStorage,
prev=U64(prev) prev=U64(prev)
if vlen: if vlen:
nv = read(8) != z64 read(16)
file.seek(8,1) # Skip previous version record pointer
version=read(vlen) version=read(vlen)
if wantver is not None and version != wantver: if wantver is not None and version != wantver:
if prev: if prev:
...@@ -1412,8 +1414,6 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -1412,8 +1414,6 @@ class FileStorage(BaseStorage.BaseStorage,
pindex[oid]=0 pindex[oid]=0
error('Bad reference to %s', `(oid,v)`) error('Bad reference to %s', `(oid,v)`)
spackpos=p64(packpos)
################################################################## ##################################################################
# Step 2, copy data and compute new index based on new positions. # Step 2, copy data and compute new index based on new positions.
index, vindex, tindex, tvindex = self._newIndexes() index, vindex, tindex, tvindex = self._newIndexes()
...@@ -1506,7 +1506,7 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -1506,7 +1506,7 @@ class FileStorage(BaseStorage.BaseStorage,
thl=ul+dl+el thl=ul+dl+el
h=read(thl) h=read(thl)
if len(h) != thl: if len(h) != thl:
raise 'Pack Error', opos raise PackError(opos)
write(h) write(h)
thl=TRANS_HDR_LEN+thl thl=TRANS_HDR_LEN+thl
pos=tpos+thl pos=tpos+thl
...@@ -1771,7 +1771,6 @@ def shift_transactions_forward(index, vindex, tindex, file, pos, opos): ...@@ -1771,7 +1771,6 @@ def shift_transactions_forward(index, vindex, tindex, file, pos, opos):
p1=opos p1=opos
p2=pos p2=pos
offset=p2-p1 offset=p2-p1
packpos=opos
# Copy the data in two stages. In the packing stage, # Copy the data in two stages. In the packing stage,
# we skip records that are non-current or that are for # we skip records that are non-current or that are for
...@@ -1798,7 +1797,8 @@ def shift_transactions_forward(index, vindex, tindex, file, pos, opos): ...@@ -1798,7 +1797,8 @@ def shift_transactions_forward(index, vindex, tindex, file, pos, opos):
thl=ul+dl+el thl=ul+dl+el
h2=read(thl) h2=read(thl)
if len(h2) != thl: raise 'Pack Error', opos if len(h2) != thl:
raise PackError(opos)
# write out the transaction record # write out the transaction record
seek(opos) seek(opos)
...@@ -1950,11 +1950,9 @@ def read_index(file, name, index, vindex, tindex, stop='\377'*8, ...@@ -1950,11 +1950,9 @@ def read_index(file, name, index, vindex, tindex, stop='\377'*8,
return 4L, maxoid, ltid return 4L, maxoid, ltid
index_get=index.get index_get=index.get
vndexpos=vindex.get
pos=start pos=start
seek(start) seek(start)
unpack=struct.unpack
tid='\0'*7+'\1' tid='\0'*7+'\1'
while 1: while 1:
...@@ -2045,13 +2043,8 @@ def read_index(file, name, index, vindex, tindex, stop='\377'*8, ...@@ -2045,13 +2043,8 @@ def read_index(file, name, index, vindex, tindex, stop='\377'*8,
if vlen: if vlen:
dlen=dlen+(16+vlen) dlen=dlen+(16+vlen)
seek(8,1) read(16)
pv=U64(read(8))
version=read(vlen) version=read(vlen)
# Jim says: "It's just not worth the bother."
#if vndexpos(version, 0) != pv:
# panic("%s incorrect previous version pointer at %s",
# name, pos)
vindex[version]=pos vindex[version]=pos
if pos+dlen > tend or tloc != tpos: if pos+dlen > tend or tloc != tpos:
...@@ -2341,15 +2334,13 @@ class RecordIterator(Iterator, BaseStorage.TransactionRecord): ...@@ -2341,15 +2334,13 @@ class RecordIterator(Iterator, BaseStorage.TransactionRecord):
self._file.seek(pos) self._file.seek(pos)
h = self._file.read(DATA_HDR_LEN) h = self._file.read(DATA_HDR_LEN)
oid, serial, sprev, stloc, vlen, splen = unpack(DATA_HDR, h) oid, serial, sprev, stloc, vlen, splen = unpack(DATA_HDR, h)
prev = U64(sprev)
tloc = U64(stloc) tloc = U64(stloc)
plen = U64(splen) plen = U64(splen)
dlen = DATA_HDR_LEN + (plen or 8) dlen = DATA_HDR_LEN + (plen or 8)
if vlen: if vlen:
dlen += (16 + vlen) dlen += (16 + vlen)
tmp = self._file.read(16) self._file.read(16) # move to the right location
pv = U64(tmp[8:16])
version = self._file.read(vlen) version = self._file.read(vlen)
else: else:
version = '' version = ''
......
...@@ -17,7 +17,6 @@ __version__ = '3.1+' ...@@ -17,7 +17,6 @@ __version__ = '3.1+'
import sys import sys
import cPersistence, Persistence import cPersistence, Persistence
from zLOG import register_subsystem from zLOG import register_subsystem
register_subsystem('ZODB')
# This is lame. Don't look. :( # This is lame. Don't look. :(
sys.modules['cPersistence'] = cPersistence sys.modules['cPersistence'] = cPersistence
......
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