[Zodb-checkins] SVN: ZODB/trunk/src/ZODB/ Windows tests exposed a bug in MVCCMappingStorage: the transaction ID

Shane Hathaway shane at hathawaymix.org
Tue Apr 28 18:57:31 EDT 2009


Log message for revision 99567:
  Windows tests exposed a bug in MVCCMappingStorage: the transaction ID
  did not necessarily increase for every transaction.  Fixed and tested.
  

Changed:
  U   ZODB/trunk/src/ZODB/MappingStorage.py
  U   ZODB/trunk/src/ZODB/tests/MVCCMappingStorage.py
  U   ZODB/trunk/src/ZODB/tests/testMVCCMappingStorage.py

-=-
Modified: ZODB/trunk/src/ZODB/MappingStorage.py
===================================================================
--- ZODB/trunk/src/ZODB/MappingStorage.py	2009-04-28 22:21:34 UTC (rev 99566)
+++ ZODB/trunk/src/ZODB/MappingStorage.py	2009-04-28 22:57:31 UTC (rev 99567)
@@ -280,7 +280,11 @@
         self._transaction = transaction
         self._tdata = {}
         if tid is None:
-            tid = ZODB.utils.newTid(self._ltid)
+            if self._transactions:
+                old_tid = self._transactions.maxKey()
+            else:
+                old_tid = None
+            tid = ZODB.utils.newTid(old_tid)
         self._tid = tid
 
     # ZODB.interfaces.IStorage

Modified: ZODB/trunk/src/ZODB/tests/MVCCMappingStorage.py
===================================================================
--- ZODB/trunk/src/ZODB/tests/MVCCMappingStorage.py	2009-04-28 22:21:34 UTC (rev 99566)
+++ ZODB/trunk/src/ZODB/tests/MVCCMappingStorage.py	2009-04-28 22:57:31 UTC (rev 99567)
@@ -50,7 +50,10 @@
     def poll_invalidations(self):
         """Poll the storage for changes by other connections.
         """
-        new_tid = self._transactions.maxKey()
+        if self._transactions:
+            new_tid = self._transactions.maxKey()
+        else:
+            new_tid = ''
 
         if self._polled_tid:
             if not self._transactions.has_key(self._polled_tid):

Modified: ZODB/trunk/src/ZODB/tests/testMVCCMappingStorage.py
===================================================================
--- ZODB/trunk/src/ZODB/tests/testMVCCMappingStorage.py	2009-04-28 22:21:34 UTC (rev 99566)
+++ ZODB/trunk/src/ZODB/tests/testMVCCMappingStorage.py	2009-04-28 22:57:31 UTC (rev 99567)
@@ -45,16 +45,10 @@
             r2 = c2.root()
             self.assert_('myobj' not in r2)
 
-            old_tid = c1._storage._polled_tid
             c1.transaction_manager.commit()
-            new_tid = c1._storage._polled_tid
+            self.assert_('myobj' not in r2)
 
-            self.assertNotEqual(new_tid, old_tid)
-            self.assertEqual(c2._storage._polled_tid, old_tid)
-
-            self.assert_('myobj' not in r2)
             c2.sync()
-            self.assertEqual(new_tid, c2._storage._polled_tid)
             self.assert_('myobj' in r2)
             self.assert_(r2['myobj'] == 'yes')
         finally:
@@ -153,7 +147,27 @@
         pass # we don't support undo yet
     checkUndoZombie = checkLoadBeforeUndo
 
+    def checkTransactionIdIncreases(self):
+        import time
+        from ZODB.utils import newTid
+        from ZODB.TimeStamp import TimeStamp
+        t = transaction.Transaction()
+        self._storage.tpc_begin(t)
+        self._storage.tpc_vote(t)
+        self._storage.tpc_finish(t)
 
+        # Add a fake transaction
+        transactions = self._storage._transactions
+        self.assertEqual(1, len(transactions))
+        fake_timestamp = 'zzzzzzzy'  # the year 5735 ;-)
+        transactions[fake_timestamp] = transactions.values()[0]
+
+        # Verify the next transaction comes after the fake transaction
+        t = transaction.Transaction()
+        self._storage.tpc_begin(t)
+        self.assertEqual(self._storage._tid, 'zzzzzzzz')
+
+
 def test_suite():
     suite = unittest.makeSuite(MVCCMappingStorageTests, 'check')
     return suite



More information about the Zodb-checkins mailing list