[Zope3-checkins] CVS: Zope3/src/zodb/storage/file - copy.py:1.3.2.1 main.py:1.2.2.2
Jeremy Hylton
jeremy@zope.com
Wed, 30 Apr 2003 18:08:26 -0400
Update of /cvs-repository/Zope3/src/zodb/storage/file
In directory cvs.zope.org:/tmp/cvs-serv13942
Modified Files:
Tag: jeremy-query-branch
copy.py main.py
Log Message:
Eliminate _packt variable.
This means it isn't possible to perform undo at any time during a
pack().
=== Zope3/src/zodb/storage/file/copy.py 1.3 => 1.3.2.1 ===
--- Zope3/src/zodb/storage/file/copy.py:1.3 Fri Apr 25 15:28:46 2003
+++ Zope3/src/zodb/storage/file/copy.py Wed Apr 30 18:08:25 2003
@@ -54,9 +54,7 @@
if _tid == tid:
return pos
if stop_at_pack:
- # check the status field of the transaction header
- # XXX _packt seems to be either ZERO or None
- if h[16] == 'p' or _tid < self._packt:
+ if h[16] == 'p':
break
raise UndoError(None, "Invalid transaction id")
=== Zope3/src/zodb/storage/file/main.py 1.2.2.1 => 1.2.2.2 ===
--- Zope3/src/zodb/storage/file/main.py:1.2.2.1 Wed Apr 30 15:09:49 2003
+++ Zope3/src/zodb/storage/file/main.py Wed Apr 30 18:08:25 2003
@@ -65,8 +65,6 @@
self._file = afile
class FileStorage(BaseStorage, DataCopier):
- # default pack time is 0
- _packt = ZERO
__implements__ = IStorage, IUndoStorage, IVersionStorage
@@ -90,6 +88,10 @@
stop=MAXTID
self._file_name = file_name
+ # pack() and UndoSearch() are mutually exclusive, so use
+ # each must check the other's flag before starting.
+ self._packing = False
+ self._undoing = False
super(FileStorage, self).__init__(file_name)
self._initIndex()
if not read_only:
@@ -710,10 +712,10 @@
last = first - last + 1
self._lock_acquire()
try:
- if self._packt is None:
+ if self._packing:
raise UndoError("Can't undo during pack")
- us = UndoSearch(self._file, self._pos, self._packt,
- first, last, filter)
+ self._undoing = False
+ us = UndoSearch(self._file, self._pos, first, last, filter)
while not us.finished():
# Hold lock for batches of 20 searches, so default search
# parameters will finish without letting another thread run.
@@ -727,6 +729,7 @@
self._lock_acquire()
return us.results
finally:
+ self._undoing = False
self._lock_release()
def undo(self, transaction_id, transaction):
@@ -748,6 +751,8 @@
self._lock_acquire()
try:
+ if self._packing:
+ raise UndoError("Can't undo during pack")
return self._txn_undo(transaction_id)
finally:
self._lock_release()
@@ -869,13 +874,14 @@
# Record pack time so we don't undo while packing
self._lock_acquire()
try:
- # XXX _packt should just be a flag
- if self._packt != ZERO:
+ while self._undoing:
+ # XXX poll for the thread running UndoSearch()
+ # to finish
+ time.sleep(0.1)
+ if self._packing:
# Already packing.
raise FileStorageError("Already packing")
- # when undo sees _packt == None, it raises an error that
- # says "can't undo during pack"
- self._packt = None
+ self._packing = True
finally:
self._lock_release()
@@ -912,7 +918,7 @@
self._commit_lock_release()
self._lock_release()
self._lock_acquire()
- self._packt = ZERO
+ self._packing = False
self._lock_release()
@@ -1181,10 +1187,9 @@
class UndoSearch(FileStorageFormatter):
- def __init__(self, file, pos, packt, first, last, filter=None):
+ def __init__(self, file, pos, first, last, filter=None):
self._file = file
self.pos = pos
- self.packt = packt
self.first = first
self.last = last
self.filter = filter
@@ -1214,7 +1219,7 @@
if self.pos < 1024:
return None
h = self._read_txn_header(self.pos)
- if h.tid < self.packt or h.status == 'p':
+ if h.status == 'p':
self.stop = 1
return None
assert h.status == " "