[Zodb-checkins] CVS: ZODB3/bsddb3Storage/bsddb3Storage - Full.py:1.44.2.7

Barry Warsaw barry@wooz.org
Thu, 24 Oct 2002 17:41:26 -0400


Update of /cvs-repository/ZODB3/bsddb3Storage/bsddb3Storage
In directory cvs.zope.org:/tmp/cvs-serv22813

Modified Files:
      Tag: bdb-nolocks
	Full.py 
Log Message:
iterator(): Implemented the extended iterator API.

_nexttxn(): Takes a `first' flag, which is unfortunately necessary to
know whether the tid we're passing in is the one we want or the one
/before/ the one we want.  Also, use set_range() in case the tid we're
given isn't exactly found in the database.

Use True/False everywhere a binary flag is needed (with a NameError
protected local definition if missing in the globals).


=== ZODB3/bsddb3Storage/bsddb3Storage/Full.py 1.44.2.6 => 1.44.2.7 ===
--- ZODB3/bsddb3Storage/bsddb3Storage/Full.py:1.44.2.6	Thu Oct 24 16:19:22 2002
+++ ZODB3/bsddb3Storage/bsddb3Storage/Full.py	Thu Oct 24 17:41:25 2002
@@ -65,6 +65,12 @@
     def incr(refcount, delta):
         return p64(U64(refcount) + delta)
 
+try:
+    True, False
+except NameError:
+    True = 1
+    False = 0
+
 
 
 class Full(BerkeleyBase, ConflictResolvingStorage):
@@ -472,7 +478,7 @@
     #
 
     def _dostore(self, txn, oid, serial, data, version):
-        conflictresolved = 0
+        conflictresolved = False
         vid = nvrevid = ZERO
         # Check for conflict errors.  JF says: under some circumstances,
         # it is possible that we'll get two stores for the same object in
@@ -490,7 +496,7 @@
             # resolution, and if that fails, raise a ConflictError.
             data = self.tryToResolveConflict(oid, oserial, serial, data)
             if data:
-                conflictresolved = 1
+                conflictresolved = True
             else:
                 raise POSException.ConflictError(serials=(oserial, serial))
         # Do we already know about this version?  If not, we need to record
@@ -836,11 +842,11 @@
             missing = []
             vid = self._vids.get(version, missing)
             if vid is missing:
-                return 1
+                return True
             if self._currentVersions.has_key(vid):
-                return 0
+                return False
             else:
-                return 1
+                return True
         finally:
             self._lock_release()
 
@@ -1023,7 +1029,7 @@
             # metadata records for multiple modifications of the object in the
             # same transaction).
             elif mrec[0][8:] == ctid:
-                assert 0
+                assert False, 'storage invariant violated'
             # All is good, so just restore this metadata record
             else:
                 return oid, mrec[1], None
@@ -1593,12 +1599,11 @@
     # Iterator protocol
     #
 
-    # XXX extended iterator
-    def iterator(self):
+    def iterator(self, start=None, stop=None):
         """Get a transactions iterator for the storage."""
-        return _TransactionsIterator(self)
+        return _TransactionsIterator(self, start, stop)
 
-    def _nexttxn(self, tid):
+    def _nexttxn(self, tid, first=False):
         self._lock_acquire()
         c = self._txnMetadata.cursor()
         try:
@@ -1611,10 +1616,14 @@
                     rec = c.first()
                 else:
                     # Get the next transaction after the specified one.
-                    c.set(tid)
-                    rec = c.next()
+                    rec = c.set_range(tid)
             except KeyError:
                 raise IndexError
+            # We're now pointing at the tid >= the requested one.  For all
+            # calls but the first one, tid will be the last transaction id we
+            # returned, so we really want the next one.
+            if not first:
+                rec = c.next()
             if rec is None:
                 raise IndexError
             tid, data = rec
@@ -1652,13 +1661,13 @@
 
     # Other interface assertions
     def supportsTransactionalUndo(self):
-        return 1
+        return True
 
     def supportsUndo(self):
-        return 1
+        return True
 
     def supportsVersions(self):
-        return 1
+        return True
 
 
 
@@ -1676,10 +1685,12 @@
 
     Transactions *must* be accessed sequentially (e.g. with a for loop).
     """
-    def __init__(self, storage):
+    def __init__(self, storage, start, stop):
         self._storage = storage
-        self._tid = None
-        self._closed = 0
+        self._tid = start
+        self._stop = stop
+        self._closed = False
+        self._first = True
 
     def next(self):
         """Return the ith item in the sequence of transaction data.
@@ -1691,12 +1702,17 @@
         if self._closed:
             raise IOError, 'iterator is closed'
         # Let IndexErrors percolate up.
-        tid, status, user, desc, ext = self._storage._nexttxn(self._tid)
+        tid, status, user, desc, ext = self._storage._nexttxn(
+            self._tid, self._first)
+        self._first = False
+        # Did we reach the specified end?
+        if self._stop is not None and tid > self._stop:
+            raise IndexError
         self._tid = tid
         return _RecordsIterator(self._storage, tid, status, user, desc, ext)
 
     def close(self):
-        self._closed = 1
+        self._closed = True