Commit 469d7f62 authored by Jim Fulton's avatar Jim Fulton

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.
parent d5cfadcb
......@@ -475,7 +475,7 @@ class DB(object):
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 @@ class DB(object):
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:
......
......@@ -345,6 +345,29 @@ def minimally_test_connection_timeout():
"""
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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment