[Zodb-checkins] CVS: ZODB/src/ZODB/FileStorage - FileStorage.py:1.10

Tim Peters tim.one at comcast.net
Tue Mar 16 17:41:27 EST 2004


Update of /cvs-repository/ZODB/src/ZODB/FileStorage
In directory cvs.zope.org:/tmp/cvs-serv17599/src/ZODB/FileStorage

Modified Files:
	FileStorage.py 
Log Message:
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.


=== ZODB/src/ZODB/FileStorage/FileStorage.py 1.9 => 1.10 ===
--- ZODB/src/ZODB/FileStorage/FileStorage.py:1.9	Tue Mar 16 16:09:04 2004
+++ ZODB/src/ZODB/FileStorage/FileStorage.py	Tue Mar 16 17:41:22 2004
@@ -106,10 +106,8 @@
                   ConflictResolution.ConflictResolvingStorage,
                   FileStorageFormatter):
 
-    # default pack time is 0
-    # XXX It's unclear what this is for.  Looks like the only values it
-    # XXX can ever have are z64 and None.
-    _packt = z64
+    # Set True while a pack is in progress; undo is blocked for the duration.
+    _pack_is_in_progress = False
 
     _records_before_save = 10000
 
@@ -1062,11 +1060,10 @@
             last = first - last + 1
         self._lock_acquire()
         try:
-            if self._packt is None:
+            if self._pack_is_in_progress:
                 raise UndoError(
                     'Undo is currently disabled for database maintenance.<p>')
-            us = UndoSearch(self._file, self._pos, self._packt,
-                            first, last, filter)
+            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.
@@ -1130,9 +1127,7 @@
                 return pos
             if stop_at_pack:
                 # check the status field of the transaction header
-                # XXX Looks like self._packt is either z64 or None, so unclear
-                # XXX what the _tid < self._packt is trying to say.
-                if h[16] == 'p' or _tid < self._packt:
+                if h[16] == 'p':
                     break
         raise UndoError("Invalid transaction id")
 
@@ -1319,16 +1314,11 @@
         if not self._index:
             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()
         try:
-            if self._packt != z64:
-                # Already packing.
+            if self._pack_is_in_progress:
                 raise FileStorageError, 'Already packing'
-            self._packt = None
+            self._pack_is_in_progress = True
         finally:
             self._lock_release()
 
@@ -1366,7 +1356,7 @@
             if p.locked:
                 self._commit_lock_release()
             self._lock_acquire()
-            self._packt = z64
+            self._pack_is_in_progress = False
             self._lock_release()
 
     def iterator(self, start=None, stop=None):
@@ -1980,10 +1970,9 @@
 
 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.pos = pos
-        self.packt = packt
         self.first = first
         self.last = last
         self.filter = filter
@@ -2011,7 +2000,7 @@
         self.file.seek(self.pos)
         h = self.file.read(TRANS_HDR_LEN)
         tid, tl, status, ul, dl, el = struct.unpack(TRANS_HDR, h)
-        if tid < self.packt or status == 'p':
+        if status == 'p':
             self.stop = 1
             return None
         if status != ' ':




More information about the Zodb-checkins mailing list