Commit ba8132de authored by Tim Peters's avatar Tim Peters

Replaced the FileStorage _packt member with a _pack_is_in_progress bool.

The only values _packt ever had were z64 and None.  The only thing _packt
was used for that appeared to make sense was to block undo while a pack
was in progress, and a bool works better for that.  tids were compared
to _packt in a few spots, but since the only values _packt could have
were in {z64, None}, the comparisons were doomed to (regardless of tid)
return "greater than" (z64) or to be undefined (None; although in recent
Pythons None is reliably less than objects of other types, so "greater
than" was the only outcome possible from these comparisons under 2.3.3).
Removed these comparisons, collapsing surrounding expressions to
equivalents taking into account that tid < self._packt was always false.
parent c555b20c
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
############################################################################## ##############################################################################
"""Storage implementation using a log written to a single file. """Storage implementation using a log written to a single file.
$Revision: 1.9 $ $Revision: 1.10 $
""" """
import base64 import base64
...@@ -106,10 +106,8 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -106,10 +106,8 @@ class FileStorage(BaseStorage.BaseStorage,
ConflictResolution.ConflictResolvingStorage, ConflictResolution.ConflictResolvingStorage,
FileStorageFormatter): FileStorageFormatter):
# default pack time is 0 # Set True while a pack is in progress; undo is blocked for the duration.
# XXX It's unclear what this is for. Looks like the only values it _pack_is_in_progress = False
# XXX can ever have are z64 and None.
_packt = z64
_records_before_save = 10000 _records_before_save = 10000
...@@ -1062,11 +1060,10 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -1062,11 +1060,10 @@ class FileStorage(BaseStorage.BaseStorage,
last = first - last + 1 last = first - last + 1
self._lock_acquire() self._lock_acquire()
try: try:
if self._packt is None: if self._pack_is_in_progress:
raise UndoError( raise UndoError(
'Undo is currently disabled for database maintenance.<p>') 'Undo is currently disabled for database maintenance.<p>')
us = UndoSearch(self._file, self._pos, self._packt, us = UndoSearch(self._file, self._pos, first, last, filter)
first, last, filter)
while not us.finished(): while not us.finished():
# Hold lock for batches of 20 searches, so default search # Hold lock for batches of 20 searches, so default search
# parameters will finish without letting another thread run. # parameters will finish without letting another thread run.
...@@ -1130,9 +1127,7 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -1130,9 +1127,7 @@ class FileStorage(BaseStorage.BaseStorage,
return pos return pos
if stop_at_pack: if stop_at_pack:
# check the status field of the transaction header # check the status field of the transaction header
# XXX Looks like self._packt is either z64 or None, so unclear if h[16] == 'p':
# XXX what the _tid < self._packt is trying to say.
if h[16] == 'p' or _tid < self._packt:
break break
raise UndoError("Invalid transaction id") raise UndoError("Invalid transaction id")
...@@ -1319,16 +1314,11 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -1319,16 +1314,11 @@ class FileStorage(BaseStorage.BaseStorage,
if not self._index: if not self._index:
return return
# Set _packt to None for the duration, which blocks undo for the
# duration.
# XXX That appears to be the only use for _packt; if so, could be
# XXX cleaner.
self._lock_acquire() self._lock_acquire()
try: try:
if self._packt != z64: if self._pack_is_in_progress:
# Already packing.
raise FileStorageError, 'Already packing' raise FileStorageError, 'Already packing'
self._packt = None self._pack_is_in_progress = True
finally: finally:
self._lock_release() self._lock_release()
...@@ -1366,7 +1356,7 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -1366,7 +1356,7 @@ class FileStorage(BaseStorage.BaseStorage,
if p.locked: if p.locked:
self._commit_lock_release() self._commit_lock_release()
self._lock_acquire() self._lock_acquire()
self._packt = z64 self._pack_is_in_progress = False
self._lock_release() self._lock_release()
def iterator(self, start=None, stop=None): def iterator(self, start=None, stop=None):
...@@ -1980,10 +1970,9 @@ class Record(BaseStorage.DataRecord): ...@@ -1980,10 +1970,9 @@ class Record(BaseStorage.DataRecord):
class UndoSearch: class UndoSearch:
def __init__(self, file, pos, packt, first, last, filter=None): def __init__(self, file, pos, first, last, filter=None):
self.file = file self.file = file
self.pos = pos self.pos = pos
self.packt = packt
self.first = first self.first = first
self.last = last self.last = last
self.filter = filter self.filter = filter
...@@ -2011,7 +2000,7 @@ class UndoSearch: ...@@ -2011,7 +2000,7 @@ class UndoSearch:
self.file.seek(self.pos) self.file.seek(self.pos)
h = self.file.read(TRANS_HDR_LEN) h = self.file.read(TRANS_HDR_LEN)
tid, tl, status, ul, dl, el = struct.unpack(TRANS_HDR, h) tid, tl, status, ul, dl, el = struct.unpack(TRANS_HDR, h)
if tid < self.packt or status == 'p': if status == 'p':
self.stop = 1 self.stop = 1
return None return None
if status != ' ': if status != ' ':
......
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