[Zodb-checkins] SVN: ZODB/trunk/src/ZODB/DemoStorage.py Use an instance-specific set, rather than a shared dict. Also lock

Jim Fulton jim at zope.com
Tue Nov 4 17:05:27 EST 2008


Log message for revision 92783:
  Use an instance-specific set, rather than a shared dict. Also lock
  new_oids to avoid a race.
  

Changed:
  U   ZODB/trunk/src/ZODB/DemoStorage.py

-=-
Modified: ZODB/trunk/src/ZODB/DemoStorage.py
===================================================================
--- ZODB/trunk/src/ZODB/DemoStorage.py	2008-11-04 19:32:51 UTC (rev 92782)
+++ ZODB/trunk/src/ZODB/DemoStorage.py	2008-11-04 22:05:26 UTC (rev 92783)
@@ -56,7 +56,9 @@
             self._temporary_changes = False
 
         self.changes = changes
-        
+
+        self._issued_oids = set()
+
         if name is None:
             name = 'DemoStorage(%r, %r)' % (base.getName(), changes.getName())
         self.__name__ = name
@@ -176,8 +178,7 @@
         except ZODB.POSException.POSKeyError:
             return self.base.loadSerial(oid, serial)
 
-    _issued_oids = {}
-
+    @ZODB.utils.locked
     def new_oid(self):
         while 1:
             oid = ZODB.utils.p64(random.randint(1, 9223372036854775807))
@@ -198,7 +199,7 @@
             else:
                 continue
             
-            self._issued_oids[oid] = None
+            self._issued_oids.add(oid)
             return oid
 
     def pack(self, t, referencesf, gc=None):
@@ -231,8 +232,7 @@
 
         # Since the OID is being used, we don't have to keep up with it any
         # more.
-        if oid in self._issued_oids:
-            del self._issued_oids[oid]
+        self._issued_oids.discard(oid)
 
         # See if we already have changes for this oid
         try:
@@ -254,8 +254,7 @@
 
         # Since the OID is being used, we don't have to keep up with it any
         # more.
-        if oid in self._issued_oids:
-            del self._issued_oids[oid]
+        self._issued_oids.discard(oid)
 
         try:
             return self.changes.storeBlob(



More information about the Zodb-checkins mailing list