[Zodb-checkins] SVN: ZODB/trunk/src/ZODB/DemoStorage. Allocate oids sequentially from random starting points so as not to
Jim Fulton
jim at zope.com
Wed Dec 3 19:56:29 EST 2008
Log message for revision 93597:
Allocate oids sequentially from random starting points so as not to
defeat FileStorage's index optimization.
Changed:
U ZODB/trunk/src/ZODB/DemoStorage.py
U ZODB/trunk/src/ZODB/DemoStorage.test
-=-
Modified: ZODB/trunk/src/ZODB/DemoStorage.py
===================================================================
--- ZODB/trunk/src/ZODB/DemoStorage.py 2008-12-04 00:56:26 UTC (rev 93596)
+++ ZODB/trunk/src/ZODB/DemoStorage.py 2008-12-04 00:56:28 UTC (rev 93597)
@@ -69,6 +69,8 @@
self._copy_methods_from_changes(changes)
+ self._next_oid = random.randint(1, 1<<62)
+
def _blobify(self):
if (self._temporary_changes and
isinstance(self.changes, ZODB.MappingStorage.MappingStorage)
@@ -183,27 +185,20 @@
@ZODB.utils.locked
def new_oid(self):
while 1:
- oid = ZODB.utils.p64(random.randint(1, 9223372036854775807))
+ oid = ZODB.utils.p64(self._next_oid )
+ if oid not in self._issued_oids:
+ try:
+ self.changes.load(oid, '')
+ except ZODB.POSException.POSKeyError:
+ try:
+ self.base.load(oid, '')
+ except ZODB.POSException.POSKeyError:
+ self._next_oid += 1
+ self._issued_oids.add(oid)
+ return oid
- if oid in self._issued_oids:
- continue
+ self._next_oid = random.randint(1, 1<<62)
- try:
- self.changes.load(oid, '')
- except ZODB.POSException.POSKeyError:
- pass
- else:
- continue
- try:
- self.base.load(oid, '')
- except ZODB.POSException.POSKeyError:
- pass
- else:
- continue
-
- self._issued_oids.add(oid)
- return oid
-
def pack(self, t, referencesf, gc=None):
if gc is None:
if self._temporary_base:
Modified: ZODB/trunk/src/ZODB/DemoStorage.test
===================================================================
--- ZODB/trunk/src/ZODB/DemoStorage.test 2008-12-04 00:56:26 UTC (rev 93596)
+++ ZODB/trunk/src/ZODB/DemoStorage.test 2008-12-04 00:56:28 UTC (rev 93597)
@@ -96,7 +96,7 @@
The object id of the new object is quite random, and typically large:
>>> print u64(conn.root()['2']._p_oid)
- 7106521602475165646
+ 3553260803050964942
Let's look at some other methods:
@@ -345,7 +345,7 @@
>>> storage = DemoStorage.push(storage)
>>> random.seed(47)
>>> storage.new_oid()
- '\x10\x01\xa6bZ\x12\x98\xa2'
+ '\x1a,S\xa4\xe9\xbb\x17\xbd'
Then we'll force the random number generator to use the same seed for the
subsequent call to "new_oid" and show that we get a different OID.
@@ -353,7 +353,7 @@
>>> random.seed(47)
>>> oid = storage.new_oid()
>>> oid
- 'A\xe6\xcb\x06W\xed\xa2\x15'
+ '\x1a,S\xa4\xe9\xbb\x17\xbe'
DemoStorage keeps up with the issued OIDs to know when not to reissue them...
More information about the Zodb-checkins
mailing list