[Zodb-checkins] CVS: StandaloneZODB/ZODB - FileStorage.py:1.71.2.1
Jeremy Hylton
jeremy@zope.com
Fri, 5 Oct 2001 22:19:13 -0400
Update of /cvs-repository/StandaloneZODB/ZODB
In directory cvs.zope.org:/tmp/cvs-serv25557
Modified Files:
Tag: jeremy-Standby-branch
FileStorage.py
Log Message:
Extended iterator() call to support optional start and stop arguments.
Add lastTransaction() method.
=== StandaloneZODB/ZODB/FileStorage.py 1.71 => 1.71.2.1 ===
read_only=read_only,
)
+ self._ltid = tid
self._ts=tid=TimeStamp(tid)
t=time.time()
@@ -798,6 +799,7 @@
self._index.update(self._tindex)
self._vindex.update(self._tvindex)
+ self._ltid = tid
def _abort(self):
if self._nextpos:
@@ -1592,8 +1594,11 @@
self._packt=z64
_lock_release()
- def iterator(self):
- return FileIterator(self._file_name)
+ def iterator(self, start=None, stop=None):
+ return FileIterator(self._file_name, start, stop)
+
+ def lastTransaction(self):
+ return self._ltid
def shift_transactions_forward(index, vindex, tindex, file, pos, opos):
"""Copy transactions forward in the data file
@@ -2010,7 +2015,7 @@
"""
_ltid=z64
- def __init__(self, file):
+ def __init__(self, file, start=None, stop=None):
if isinstance(file, StringType):
file=open(file, 'rb')
self._file=file
@@ -2018,6 +2023,29 @@
file.seek(0,2)
self._file_size=file.tell()
self._pos=4L
+ if start:
+ self._skip_to_start(start)
+ self._stop = stop
+
+ def _skip_to_start(self, start):
+ # Scan through the transaction records doing almost no sanity
+ # checks.
+ self._file.seek(self._pos)
+ while 1:
+ h = self._file.read(8)
+ if len(h) < 8:
+ return
+ tid, stl = unpack(">8s8s", h)
+ tl = U64(stl)
+ if tid >= start:
+ self._file.seek(-8, 1)
+ return
+ self._file.seek(tl - 8)
+ rtl = self._file.read(8)
+ if rtl != stl:
+ pos = self._file.tell() - 8
+ panic("%s has inconsistent transaction length at %s",
+ self._file.name, pos)
def next(self, index=0):
file=self._file
@@ -2072,6 +2100,9 @@
else:
warn('%s has invalid transaction header at %s', name, pos)
break
+
+ if self._stop is not None and tid >= self._stop:
+ raise IndexError, index
tpos=pos
tend=tpos+tl