Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZODB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
ZODB
Commits
bc99890a
Commit
bc99890a
authored
Dec 04, 2008
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allocate oids sequentially from random starting points so as not to
defeat FileStorage's index optimization.
parent
c2225847
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
23 deletions
+18
-23
src/ZODB/DemoStorage.py
src/ZODB/DemoStorage.py
+15
-20
src/ZODB/DemoStorage.test
src/ZODB/DemoStorage.test
+3
-3
No files found.
src/ZODB/DemoStorage.py
View file @
bc99890a
...
...
@@ -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
:
...
...
src/ZODB/DemoStorage.test
View file @
bc99890a
...
...
@@ -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
()
'\x1
0\x01\xa6bZ\x12\x98\xa2
'
'\x1
a,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...
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment