Commit bc99890a authored by Jim Fulton's avatar Jim Fulton

Allocate oids sequentially from random starting points so as not to

defeat FileStorage's index optimization.
parent c2225847
......@@ -69,6 +69,8 @@ class DemoStorage(object):
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,26 +185,19 @@ class DemoStorage(object):
@ZODB.utils.locked
def new_oid(self):
while 1:
oid = ZODB.utils.p64(random.randint(1, 9223372036854775807))
if oid in self._issued_oids:
continue
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
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
self._next_oid = random.randint(1, 1<<62)
def pack(self, t, referencesf, gc=None):
if gc is None:
......
......@@ -96,7 +96,7 @@ the new underlying storages:
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 @@ First we'll get a single OID.
>>> 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 @@ subsequent call to "new_oid" and show that we get a different OID.
>>> 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...
......
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