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): ...@@ -69,6 +69,8 @@ class DemoStorage(object):
self._copy_methods_from_changes(changes) self._copy_methods_from_changes(changes)
self._next_oid = random.randint(1, 1<<62)
def _blobify(self): def _blobify(self):
if (self._temporary_changes and if (self._temporary_changes and
isinstance(self.changes, ZODB.MappingStorage.MappingStorage) isinstance(self.changes, ZODB.MappingStorage.MappingStorage)
...@@ -183,27 +185,20 @@ class DemoStorage(object): ...@@ -183,27 +185,20 @@ class DemoStorage(object):
@ZODB.utils.locked @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(self._next_oid )
if oid not in self._issued_oids:
if oid in self._issued_oids:
continue
try: try:
self.changes.load(oid, '') self.changes.load(oid, '')
except ZODB.POSException.POSKeyError: except ZODB.POSException.POSKeyError:
pass
else:
continue
try: try:
self.base.load(oid, '') self.base.load(oid, '')
except ZODB.POSException.POSKeyError: except ZODB.POSException.POSKeyError:
pass self._next_oid += 1
else:
continue
self._issued_oids.add(oid) self._issued_oids.add(oid)
return oid return oid
self._next_oid = random.randint(1, 1<<62)
def pack(self, t, referencesf, gc=None): def pack(self, t, referencesf, gc=None):
if gc is None: if gc is None:
if self._temporary_base: if self._temporary_base:
......
...@@ -96,7 +96,7 @@ the new underlying storages: ...@@ -96,7 +96,7 @@ the new underlying storages:
The object id of the new object is quite random, and typically large: The object id of the new object is quite random, and typically large:
>>> print u64(conn.root()['2']._p_oid) >>> print u64(conn.root()['2']._p_oid)
7106521602475165646 3553260803050964942
Let's look at some other methods: Let's look at some other methods:
...@@ -345,7 +345,7 @@ First we'll get a single OID. ...@@ -345,7 +345,7 @@ First we'll get a single OID.
>>> storage = DemoStorage.push(storage) >>> storage = DemoStorage.push(storage)
>>> random.seed(47) >>> random.seed(47)
>>> storage.new_oid() >>> 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 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. 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. ...@@ -353,7 +353,7 @@ subsequent call to "new_oid" and show that we get a different OID.
>>> random.seed(47) >>> random.seed(47)
>>> oid = storage.new_oid() >>> oid = storage.new_oid()
>>> 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... 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