[Zodb-checkins] SVN: ZODB/branches/gocept-iteration/src/Z - Removed MappingStorage and DemoStorage iterator() implementation as they both

Christian Theune ct at gocept.com
Mon Feb 18 10:58:04 EST 2008


Log message for revision 84026:
  - Removed MappingStorage and DemoStorage iterator() implementation as they both
  are unnecessary and hard to get right.
  
  - Clarified over which set of data iterator() is guaranteed to work and added
    a test for it
  
  There are some tests broken right now.
  
  

Changed:
  U   ZODB/branches/gocept-iteration/src/ZEO/tests/testZEO.py
  U   ZODB/branches/gocept-iteration/src/ZODB/DemoStorage.py
  U   ZODB/branches/gocept-iteration/src/ZODB/MappingStorage.py
  U   ZODB/branches/gocept-iteration/src/ZODB/interfaces.py
  U   ZODB/branches/gocept-iteration/src/ZODB/tests/IteratorStorage.py
  U   ZODB/branches/gocept-iteration/src/ZODB/tests/testDemoStorage.py
  U   ZODB/branches/gocept-iteration/src/ZODB/tests/testMappingStorage.py

-=-
Modified: ZODB/branches/gocept-iteration/src/ZEO/tests/testZEO.py
===================================================================
--- ZODB/branches/gocept-iteration/src/ZEO/tests/testZEO.py	2008-02-18 15:52:35 UTC (rev 84025)
+++ ZODB/branches/gocept-iteration/src/ZEO/tests/testZEO.py	2008-02-18 15:58:03 UTC (rev 84026)
@@ -177,11 +177,9 @@
     Synchronization.SynchronizedStorage,
     MTStorage.MTStorage,
     ReadOnlyStorage.ReadOnlyStorage,
-    IteratorStorage.IteratorStorage,
     # ZEO test mixin classes (in the same order as imported)
     CommitLockTests.CommitLockVoteTests,
     ThreadTests.ThreadTests,
-    IterationTests.IterationTests,
     # Locally defined (see above)
     MiscZEOTests,
     ):
@@ -251,6 +249,8 @@
     PackableStorage.PackableUndoStorage,
     RevisionStorage.RevisionStorage,
     TransactionalUndoStorage.TransactionalUndoStorage,
+    IteratorStorage.IteratorStorage,
+    IterationTests.IterationTests,
     ):
     """Extend GenericTests with tests that MappingStorage can't pass."""
 
@@ -594,7 +594,7 @@
         self._storage.close()
 
 
-class BlobAdaptedFileStorageTests(GenericTests, CommonBlobTests):
+class BlobAdaptedFileStorageTests(FullGenericTests, CommonBlobTests):
     """ZEO backed by a BlobStorage-adapted FileStorage."""
 
     def setUp(self):
@@ -685,7 +685,7 @@
         check_data(filename)
 
 
-class BlobWritableCacheTests(GenericTests, CommonBlobTests):
+class BlobWritableCacheTests(FullGenericTests, CommonBlobTests):
 
     def setUp(self):
         self.blobdir = self.blob_cache_dir = tempfile.mkdtemp()
@@ -863,7 +863,7 @@
     >>> st = StorageServerWrapper(sv, 'fs')
     >>> s = st.server
     
-Now, if we ask fior the invalidations since the last committed
+Now, if we ask for the invalidations since the last committed
 transaction, we'll get a result:
 
     >>> tid, oids = s.getInvalidations(last[-1])

Modified: ZODB/branches/gocept-iteration/src/ZODB/DemoStorage.py
===================================================================
--- ZODB/branches/gocept-iteration/src/ZODB/DemoStorage.py	2008-02-18 15:52:35 UTC (rev 84025)
+++ ZODB/branches/gocept-iteration/src/ZODB/DemoStorage.py	2008-02-18 15:58:03 UTC (rev 84026)
@@ -575,39 +575,3 @@
     def close(self):
         if self._base is not None:
             self._base.close()
-
-    def iterator(self, start=None, stop=None):
-        for tid, (packed, user, description, extension, records) \
-                in self._data.items():
-            if tid < start:
-                continue
-            if stop is not None and tid > stop:
-                break
-            if packed:
-                status = 'p'
-            else:
-                status = ' '
-            extension = cPickle.loads(extension)
-            yield TransactionRecord(
-                tid, status, user, description, extension, records)
-
-
-class TransactionRecord(ZODB.BaseStorage.TransactionRecord):
-
-    def __init__(self, tid, status, user, description, extension, records):
-        super(TransactionRecord, self).__init__(
-            tid, status, user, description, extension)
-        self._records = list(records)
-
-    def __iter__(self):
-        while self._records:
-            oid, prev, vdata, data, tid = self._records.pop()
-            if vdata is None:
-                version = ''
-            else:
-                version, data = vdata
-            if prev is not None:
-                # prev is supposed to be the previous data record,
-                # which has its tid as its last element
-                prev = prev[-1]
-            yield ZODB.BaseStorage.DataRecord(oid, tid, data, version, prev)

Modified: ZODB/branches/gocept-iteration/src/ZODB/MappingStorage.py
===================================================================
--- ZODB/branches/gocept-iteration/src/ZODB/MappingStorage.py	2008-02-18 15:52:35 UTC (rev 84025)
+++ ZODB/branches/gocept-iteration/src/ZODB/MappingStorage.py	2008-02-18 15:58:03 UTC (rev 84026)
@@ -140,36 +140,3 @@
 
     def close(self):
         pass
-
-    def iterator(self, start=None, stop=None):
-        """Return an IStorageTransactionInformation iterator."""
-        tid2oid = {}
-        for oid, odata in self._index.items():
-            tid = odata[:8]
-            oids = tid2oid.setdefault(tid, [])
-            oids.append(oid)
-        for tid, oids in sorted(tid2oid.items()):
-            if tid < start:
-                continue
-            if stop is not None and tid > stop:
-                break
-            yield TransactionRecord(self, tid, oids)
-
-
-class TransactionRecord(ZODB.BaseStorage.TransactionRecord):
-
-    def __init__(self, storage, tid, oids):
-        super(TransactionRecord, self).__init__(tid, 'p', '', '', {})
-        self._storage = storage
-        self._oids = list(oids)
-
-    def __iter__(self):
-        return self
-
-    def next(self):
-        while self._oids:
-            oid = self._oids.pop()
-            storage_data = self._storage._index[oid]
-            tid, data = storage_data[:8], storage_data[8:]
-            return ZODB.BaseStorage.DataRecord(oid, tid, data, '', None)
-        raise StopIteration

Modified: ZODB/branches/gocept-iteration/src/ZODB/interfaces.py
===================================================================
--- ZODB/branches/gocept-iteration/src/ZODB/interfaces.py	2008-02-18 15:52:35 UTC (rev 84025)
+++ ZODB/branches/gocept-iteration/src/ZODB/interfaces.py	2008-02-18 15:58:03 UTC (rev 84026)
@@ -807,13 +807,8 @@
 
 
 class IStorageIteration(Interface):
-    """API for iterating over the contents of a storage
+    """API for iterating over the contents of a storage."""
 
-    Note that this is a future API.  Some storages now provide an
-    approximation of this.
-
-    """
-
     def iterator(start=None, stop=None):
         """Return an IStorageTransactionInformation iterator.
 
@@ -825,6 +820,9 @@
         the last transaction whose identifier is less than or equal to
         stop.
 
+        The iterator provides access to the data as available at the time when
+        the iterator was retrieved.
+
         """
 
 

Modified: ZODB/branches/gocept-iteration/src/ZODB/tests/IteratorStorage.py
===================================================================
--- ZODB/branches/gocept-iteration/src/ZODB/tests/IteratorStorage.py	2008-02-18 15:52:35 UTC (rev 84025)
+++ ZODB/branches/gocept-iteration/src/ZODB/tests/IteratorStorage.py	2008-02-18 15:58:03 UTC (rev 84026)
@@ -148,7 +148,19 @@
         # The iterator can only be consumed once:
         self.assertEquals(0, len(list(tinfo)))
 
+    def checkIterateWhileWriting(self):
+        self._dostore()
+        iterator = self._storage.iterator()
+        # We have one transaction with 1 modified object.
+        txn_1 = iterator.next()
+        self.assertEquals(1, len(list(txn_1)))
 
+        # We store another transaction with 1 object, the already running
+        # iterator does not pick this up.
+        self._dostore()
+        self.assertRaises(StopIteration, iterator.next)
+
+
 class ExtendedIteratorStorage(IteratorCompare):
 
     def checkExtendedIteration(self):

Modified: ZODB/branches/gocept-iteration/src/ZODB/tests/testDemoStorage.py
===================================================================
--- ZODB/branches/gocept-iteration/src/ZODB/tests/testDemoStorage.py	2008-02-18 15:52:35 UTC (rev 84025)
+++ ZODB/branches/gocept-iteration/src/ZODB/tests/testDemoStorage.py	2008-02-18 15:58:03 UTC (rev 84026)
@@ -18,12 +18,11 @@
 import ZODB.utils
 import ZODB.DemoStorage
 from ZODB.tests import StorageTestBase, BasicStorage
-from ZODB.tests import Synchronization, IteratorStorage
+from ZODB.tests import Synchronization
 
 class DemoStorageTests(StorageTestBase.StorageTestBase,
                        BasicStorage.BasicStorage,
                        Synchronization.SynchronizedStorage,
-                       IteratorStorage.IteratorStorage
                        ):
 
     def setUp(self):
@@ -45,10 +44,6 @@
         self.assertEqual(s2.load(ZODB.utils.z64, ''),
                          self._storage.load(ZODB.utils.z64, ''))
 
-    def checkUndoZombie(self):
-        # The test base class IteratorStorage assumes that we keep undo data
-        # to construct our iterator, which we don't, so we disable this test.
-        pass
 
 class DemoStorageWrappedBase(DemoStorageTests):
 

Modified: ZODB/branches/gocept-iteration/src/ZODB/tests/testMappingStorage.py
===================================================================
--- ZODB/branches/gocept-iteration/src/ZODB/tests/testMappingStorage.py	2008-02-18 15:52:35 UTC (rev 84025)
+++ ZODB/branches/gocept-iteration/src/ZODB/tests/testMappingStorage.py	2008-02-18 15:58:03 UTC (rev 84026)
@@ -16,14 +16,13 @@
 
 from ZODB.tests import StorageTestBase
 from ZODB.tests import BasicStorage, MTStorage, Synchronization
-from ZODB.tests import PackableStorage, IteratorStorage
+from ZODB.tests import PackableStorage
 
 class MappingStorageTests(StorageTestBase.StorageTestBase,
                           BasicStorage.BasicStorage,
                           MTStorage.MTStorage,
                           PackableStorage.PackableStorage,
                           Synchronization.SynchronizedStorage,
-                          IteratorStorage.IteratorStorage
                           ):
 
     def setUp(self):
@@ -38,16 +37,7 @@
         # have this limit, so we inhibit this test here.
         pass
 
-    def checkSimpleIteration(self):
-        # The test base class IteratorStorage assumes that we keep undo data
-        # to construct our iterator, which we don't, so we disable this test.
-        pass
 
-    def checkUndoZombie(self):
-        # The test base class IteratorStorage assumes that we keep undo data
-        # to construct our iterator, which we don't, so we disable this test.
-        pass
-
 def test_suite():
     suite = unittest.makeSuite(MappingStorageTests, 'check')
     return suite



More information about the Zodb-checkins mailing list