[Zodb-checkins] SVN: ZODB/branches/gocept-iteration/src/Z - Implement better iterator for MappingStorage.

Christian Theune ct at gocept.com
Thu Feb 14 09:10:31 EST 2008


Log message for revision 83836:
  - Implement better iterator for MappingStorage.
  - Remove invalid use of `_extension` from FileStorage and the iterator tests.
  - Apply all IteratorStorage tests to ZEO.
  - Make IteratorGCSpanTransaction test create an empty transaction.
  - Update IStorageTransactionInformation to make clear that `extension` is the
    (unpickled) dict of extension data.
  

Changed:
  U   ZODB/branches/gocept-iteration/src/ZEO/tests/IterationTests.py
  U   ZODB/branches/gocept-iteration/src/ZEO/tests/testZEO.py
  U   ZODB/branches/gocept-iteration/src/ZODB/FileStorage/FileStorage.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

-=-
Modified: ZODB/branches/gocept-iteration/src/ZEO/tests/IterationTests.py
===================================================================
--- ZODB/branches/gocept-iteration/src/ZEO/tests/IterationTests.py	2008-02-14 14:10:07 UTC (rev 83835)
+++ ZODB/branches/gocept-iteration/src/ZEO/tests/IterationTests.py	2008-02-14 14:10:31 UTC (rev 83836)
@@ -46,7 +46,10 @@
 
     def checkIteratorGCSpanTransactions(self):
         iterator = self._storage.iterator()
-        self._dostore()
+        t = transaction.Transaction()
+        self._storage.tpc_begin(t)
+        self._storage.tpc_vote(t)
+        self._storage.tpc_finish(t)
         self.assertEquals([], list(iterator))
 
     def checkIteratorGCStorageCommitting(self):

Modified: ZODB/branches/gocept-iteration/src/ZEO/tests/testZEO.py
===================================================================
--- ZODB/branches/gocept-iteration/src/ZEO/tests/testZEO.py	2008-02-14 14:10:07 UTC (rev 83835)
+++ ZODB/branches/gocept-iteration/src/ZEO/tests/testZEO.py	2008-02-14 14:10:31 UTC (rev 83836)
@@ -41,7 +41,7 @@
 from ZODB.tests import StorageTestBase, BasicStorage,  \
      TransactionalUndoStorage,  \
      PackableStorage, Synchronization, ConflictResolution, RevisionStorage, \
-     MTStorage, ReadOnlyStorage
+     MTStorage, ReadOnlyStorage, IteratorStorage
 
 from ZODB.tests.testDemoStorage import DemoStorageWrappedBase
 
@@ -177,6 +177,7 @@
     Synchronization.SynchronizedStorage,
     MTStorage.MTStorage,
     ReadOnlyStorage.ReadOnlyStorage,
+    IteratorStorage.IteratorStorage,
     # ZEO test mixin classes (in the same order as imported)
     CommitLockTests.CommitLockVoteTests,
     ThreadTests.ThreadTests,

Modified: ZODB/branches/gocept-iteration/src/ZODB/FileStorage/FileStorage.py
===================================================================
--- ZODB/branches/gocept-iteration/src/ZODB/FileStorage/FileStorage.py	2008-02-14 14:10:07 UTC (rev 83835)
+++ ZODB/branches/gocept-iteration/src/ZODB/FileStorage/FileStorage.py	2008-02-14 14:10:31 UTC (rev 83836)
@@ -1690,7 +1690,6 @@
     def __init__(self, tid, status, user, desc, ext, pos, tend, file, tpos):
         BaseStorage.TransactionRecord.__init__(
             self, tid, status, user, desc, ext)
-        self._extension = ext
         self._pos = pos
         self._tend = tend
         self._file = file

Modified: ZODB/branches/gocept-iteration/src/ZODB/MappingStorage.py
===================================================================
--- ZODB/branches/gocept-iteration/src/ZODB/MappingStorage.py	2008-02-14 14:10:07 UTC (rev 83835)
+++ ZODB/branches/gocept-iteration/src/ZODB/MappingStorage.py	2008-02-14 14:10:31 UTC (rev 83836)
@@ -21,16 +21,16 @@
 The Mapping storage uses a single data structure to map object ids to data.
 """
 
+import ZODB.BaseStorage
 from ZODB.utils import u64, z64
-from ZODB.BaseStorage import BaseStorage
 from ZODB import POSException
 from persistent.TimeStamp import TimeStamp
 
 
-class MappingStorage(BaseStorage):
+class MappingStorage(ZODB.BaseStorage.BaseStorage):
 
     def __init__(self, name='Mapping Storage'):
-        BaseStorage.__init__(self, name)
+        ZODB.BaseStorage.BaseStorage.__init__(self, name)
         # ._index maps an oid to a string s.  s[:8] is the tid of the
         # transaction that created oid's current state, and s[8:] is oid's
         # current state.
@@ -142,4 +142,26 @@
         pass
 
     def iterator(self, start=None, stop=None):
-        return iter(())
+        """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()):
+            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 = oids
+
+    def __iter__(self):
+        for oid in self._oids:
+            storage_data = self._storage._index[oid]
+            tid, data = storage_data[:8], storage_data[8:]
+            yield ZODB.BaseStorage.DataRecord(oid, tid, data, '', None)

Modified: ZODB/branches/gocept-iteration/src/ZODB/interfaces.py
===================================================================
--- ZODB/branches/gocept-iteration/src/ZODB/interfaces.py	2008-02-14 14:10:07 UTC (rev 83835)
+++ ZODB/branches/gocept-iteration/src/ZODB/interfaces.py	2008-02-14 14:10:31 UTC (rev 83836)
@@ -794,7 +794,7 @@
     status = Attribute("Transaction Status") # XXX what are valid values?
     user = Attribute("Transaction user")
     description = Attribute("Transaction Description")
-    extension = Attribute("Transaction extension data")
+    extension = Attribute("A dictionary carrying the transaction's extension data")
 
     def __iter__():
         """Return an iterable of IStorageRecordInformation

Modified: ZODB/branches/gocept-iteration/src/ZODB/tests/IteratorStorage.py
===================================================================
--- ZODB/branches/gocept-iteration/src/ZODB/tests/IteratorStorage.py	2008-02-14 14:10:07 UTC (rev 83835)
+++ ZODB/branches/gocept-iteration/src/ZODB/tests/IteratorStorage.py	2008-02-14 14:10:31 UTC (rev 83836)
@@ -89,7 +89,7 @@
         iter = self._storage.iterator()
         count = 0
         for txn in iter:
-            self.assertEqual(txn._extension, {})
+            self.assertEqual(txn.extension, {})
             count +=1
         self.assertEqual(count, 1)
 
@@ -183,7 +183,7 @@
             eq(txn1.status,      txn2.status)
             eq(txn1.user,        txn2.user)
             eq(txn1.description, txn2.description)
-            eq(txn1._extension,  txn2._extension)
+            eq(txn1.extension,  txn2.extension)
             for rec1, rec2 in zip(txn1, txn2):
                 eq(rec1.oid,     rec2.oid)
                 eq(rec1.tid,  rec2.tid)



More information about the Zodb-checkins mailing list