[Zodb-checkins] SVN: ZODB/trunk/src/ZODB/ Make sure saved oids don't get duped.

Jim Fulton jim at zope.com
Tue Oct 26 14:07:20 EDT 2010


Log message for revision 117925:
  Make sure saved oids don't get duped.
  This is added insurance on
  https://bugs.launchpad.net/zodb/+bug/665452.
  In particular, because we saved dups, the damage persisted, requiring
  a process restart to clear.
  

Changed:
  U   ZODB/trunk/src/ZODB/DB.py
  U   ZODB/trunk/src/ZODB/tests/testDB.py

-=-
Modified: ZODB/trunk/src/ZODB/DB.py
===================================================================
--- ZODB/trunk/src/ZODB/DB.py	2010-10-26 17:51:40 UTC (rev 117924)
+++ ZODB/trunk/src/ZODB/DB.py	2010-10-26 18:07:20 UTC (rev 117925)
@@ -475,7 +475,7 @@
         databases[database_name] = self
         self.xrefs = xrefs
 
-        self._saved_oids = []
+        self._saved_oids = set()
         self._max_saved_oids = max_saved_oids
         self.large_record_size = large_record_size
 
@@ -959,8 +959,10 @@
 
 
     def save_oid(self, oid):
+        if oid in self._saved_oids:
+            raise ValueError("Duplicate saved object ids.")
         if len(self._saved_oids) < self._max_saved_oids:
-            self._saved_oids.append(oid)
+            self._saved_oids.add(oid)
 
     def new_oid(self):
         if self._saved_oids:

Modified: ZODB/trunk/src/ZODB/tests/testDB.py
===================================================================
--- ZODB/trunk/src/ZODB/tests/testDB.py	2010-10-26 17:51:40 UTC (rev 117924)
+++ ZODB/trunk/src/ZODB/tests/testDB.py	2010-10-26 18:07:20 UTC (rev 117925)
@@ -345,7 +345,30 @@
 
     """
 
+def saving_oid_multiple_times_doesnt_cause_dups():
+    r"""Duplicate saves of an oid shouldn't happen unless there's a bug elsewhere
 
+    But saving dups makes matters worse, because it dooms the process,
+    not just the transaction.
+
+    >>> db = ZODB.DB(None)
+    >>> oid = db.new_oid()
+    >>> db.save_oid(oid)
+    >>> db.new_oid() is oid
+    True
+    >>> db.save_oid(oid)
+    >>> db.save_oid(oid)
+    Traceback (most recent call last):
+    ...
+    ValueError: Duplicate saved object ids.
+
+    >>> db.new_oid() is oid
+    True
+    >>> db.new_oid()
+    '\x00\x00\x00\x00\x00\x00\x00\x02'
+
+    """
+
 def test_suite():
     s = unittest.makeSuite(DBTests)
     s.addTest(doctest.DocTestSuite(



More information about the Zodb-checkins mailing list