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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Nicolas Wavrant
ZODB
Commits
2f9dbfde
Commit
2f9dbfde
authored
Oct 18, 2004
by
Dmitry Vasiliev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code cleanups
parent
3a1b8c09
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
24 deletions
+24
-24
src/ZODB/MappingStorage.py
src/ZODB/MappingStorage.py
+24
-24
No files found.
src/ZODB/MappingStorage.py
View file @
2f9dbfde
...
...
@@ -22,15 +22,17 @@ The Mapping storage uses a single data structure to map object ids to data.
"""
from
ZODB.utils
import
u64
,
z64
from
ZODB
import
BaseStorage
from
ZODB
.BaseStorage
import
BaseStorage
from
ZODB
import
POSException
from
persistent.TimeStamp
import
TimeStamp
class
MappingStorage
(
BaseStorage
.
BaseStorage
):
class
MappingStorage
(
BaseStorage
):
def
__init__
(
self
,
name
=
'Mapping Storage'
):
BaseStorage
.
BaseStorage
.
__init__
(
self
,
name
)
BaseStorage
.
__init__
(
self
,
name
)
self
.
_index
=
{}
# FIXME: Why we don't use dict for _tindex?
self
.
_tindex
=
[]
self
.
_ltid
=
None
# Note: If you subclass this and use a persistent mapping facility
...
...
@@ -41,12 +43,15 @@ class MappingStorage(BaseStorage.BaseStorage):
return
len
(
self
.
_index
)
def
getSize
(
self
):
# These constants are for Python object memory overheads
s
=
32
for
oid
in
self
.
_index
.
keys
():
p
=
self
.
_index
[
oid
]
s
+=
56
+
len
(
p
)
return
s
self
.
_lock_acquire
()
try
:
# These constants are for Python object memory overheads
s
=
32
for
p
in
self
.
_index
.
itervalues
():
s
+=
56
+
len
(
p
)
return
s
finally
:
self
.
_lock_release
()
def
load
(
self
,
oid
,
version
):
self
.
_lock_acquire
()
...
...
@@ -70,8 +75,7 @@ class MappingStorage(BaseStorage.BaseStorage):
self
.
_lock_acquire
()
try
:
# The tid is the first 8 bytes of the buffer.
s
=
self
.
_index
[
oid
]
return
s
[:
8
]
return
self
.
_index
[
oid
][:
8
]
finally
:
self
.
_lock_release
()
...
...
@@ -81,13 +85,12 @@ class MappingStorage(BaseStorage.BaseStorage):
raise
POSException
.
StorageTransactionError
(
self
,
transaction
)
if
version
:
raise
POSException
.
Unsupported
,
"Versions aren't supported"
raise
POSException
.
Unsupported
(
"Versions aren't supported"
)
self
.
_lock_acquire
()
try
:
if
self
.
_index
.
has_key
(
oid
):
old
=
self
.
_index
[
oid
]
oserial
=
old
[:
8
]
if
oid
in
self
.
_index
:
oserial
=
self
.
_index
[
oid
][:
8
]
if
serial
!=
oserial
:
raise
POSException
.
ConflictError
(
oid
=
oid
,
serials
=
(
oserial
,
serial
),
...
...
@@ -102,8 +105,7 @@ class MappingStorage(BaseStorage.BaseStorage):
self
.
_tindex
=
[]
def
_finish
(
self
,
tid
,
user
,
desc
,
ext
):
for
oid
,
p
in
self
.
_tindex
:
self
.
_index
[
oid
]
=
p
self
.
_index
.
update
(
dict
(
self
.
_tindex
))
self
.
_ltid
=
self
.
_tid
def
lastTransaction
(
self
):
...
...
@@ -119,17 +121,16 @@ class MappingStorage(BaseStorage.BaseStorage):
pindex
=
{}
while
rootl
:
oid
=
rootl
.
pop
()
if
pindex
.
has_key
(
oid
)
:
if
oid
in
pindex
:
continue
# Scan non-version pickle for references
r
=
self
.
_index
[
oid
]
pindex
[
oid
]
=
r
p
=
r
[
8
:]
referencesf
(
p
,
rootl
)
referencesf
(
r
[
8
:],
rootl
)
# Now delete any unreferenced entries:
for
oid
in
self
.
_index
.
keys
():
if
not
pindex
.
has_key
(
oid
)
:
if
oid
not
in
pindex
:
del
self
.
_index
[
oid
]
finally
:
...
...
@@ -137,13 +138,12 @@ class MappingStorage(BaseStorage.BaseStorage):
def
_splat
(
self
):
"""Spit out a string showing state."""
o
=
[]
o
.
append
(
'Index:'
)
o
=
[
'Index:'
]
keys
=
self
.
_index
.
keys
()
keys
.
sort
()
for
oid
in
keys
:
r
=
self
.
_index
[
oid
]
o
.
append
(
' %s: %s, %s'
%
(
u64
(
oid
),
TimeStamp
(
r
[:
8
]),
`r[8:]`
))
(
u64
(
oid
),
TimeStamp
(
r
[:
8
]),
repr
(
r
[
8
:])
))
return
'
\
n
'
.
join
(
o
)
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