Commit 5083216e authored by Jim Fulton's avatar Jim Fulton

Use an instance-specific set, rather than a shared dict. Also lock

new_oids to avoid a race.
parent 53a30f02
...@@ -56,7 +56,9 @@ class DemoStorage(object): ...@@ -56,7 +56,9 @@ class DemoStorage(object):
self._temporary_changes = False self._temporary_changes = False
self.changes = changes self.changes = changes
self._issued_oids = set()
if name is None: if name is None:
name = 'DemoStorage(%r, %r)' % (base.getName(), changes.getName()) name = 'DemoStorage(%r, %r)' % (base.getName(), changes.getName())
self.__name__ = name self.__name__ = name
...@@ -176,8 +178,7 @@ class DemoStorage(object): ...@@ -176,8 +178,7 @@ class DemoStorage(object):
except ZODB.POSException.POSKeyError: except ZODB.POSException.POSKeyError:
return self.base.loadSerial(oid, serial) return self.base.loadSerial(oid, serial)
_issued_oids = {} @ZODB.utils.locked
def new_oid(self): def new_oid(self):
while 1: while 1:
oid = ZODB.utils.p64(random.randint(1, 9223372036854775807)) oid = ZODB.utils.p64(random.randint(1, 9223372036854775807))
...@@ -198,7 +199,7 @@ class DemoStorage(object): ...@@ -198,7 +199,7 @@ class DemoStorage(object):
else: else:
continue continue
self._issued_oids[oid] = None self._issued_oids.add(oid)
return oid return oid
def pack(self, t, referencesf, gc=None): def pack(self, t, referencesf, gc=None):
...@@ -231,8 +232,7 @@ class DemoStorage(object): ...@@ -231,8 +232,7 @@ class DemoStorage(object):
# Since the OID is being used, we don't have to keep up with it any # Since the OID is being used, we don't have to keep up with it any
# more. # more.
if oid in self._issued_oids: self._issued_oids.discard(oid)
del self._issued_oids[oid]
# See if we already have changes for this oid # See if we already have changes for this oid
try: try:
...@@ -254,8 +254,7 @@ class DemoStorage(object): ...@@ -254,8 +254,7 @@ class DemoStorage(object):
# Since the OID is being used, we don't have to keep up with it any # Since the OID is being used, we don't have to keep up with it any
# more. # more.
if oid in self._issued_oids: self._issued_oids.discard(oid)
del self._issued_oids[oid]
try: try:
return self.changes.storeBlob( return self.changes.storeBlob(
......
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