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
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
Show 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.
...
@@ -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.utils
import
u64
,
z64
from
ZODB
import
BaseStorage
from
ZODB
.BaseStorage
import
BaseStorage
from
ZODB
import
POSException
from
ZODB
import
POSException
from
persistent.TimeStamp
import
TimeStamp
from
persistent.TimeStamp
import
TimeStamp
class
MappingStorage
(
BaseStorage
.
BaseStorage
):
class
MappingStorage
(
BaseStorage
):
def
__init__
(
self
,
name
=
'Mapping Storage'
):
def
__init__
(
self
,
name
=
'Mapping Storage'
):
BaseStorage
.
BaseStorage
.
__init__
(
self
,
name
)
BaseStorage
.
__init__
(
self
,
name
)
self
.
_index
=
{}
self
.
_index
=
{}
# FIXME: Why we don't use dict for _tindex?
self
.
_tindex
=
[]
self
.
_tindex
=
[]
self
.
_ltid
=
None
self
.
_ltid
=
None
# Note: If you subclass this and use a persistent mapping facility
# Note: If you subclass this and use a persistent mapping facility
...
@@ -41,12 +43,15 @@ class MappingStorage(BaseStorage.BaseStorage):
...
@@ -41,12 +43,15 @@ class MappingStorage(BaseStorage.BaseStorage):
return
len
(
self
.
_index
)
return
len
(
self
.
_index
)
def
getSize
(
self
):
def
getSize
(
self
):
self
.
_lock_acquire
()
try
:
# These constants are for Python object memory overheads
# These constants are for Python object memory overheads
s
=
32
s
=
32
for
oid
in
self
.
_index
.
keys
():
for
p
in
self
.
_index
.
itervalues
():
p
=
self
.
_index
[
oid
]
s
+=
56
+
len
(
p
)
s
+=
56
+
len
(
p
)
return
s
return
s
finally
:
self
.
_lock_release
()
def
load
(
self
,
oid
,
version
):
def
load
(
self
,
oid
,
version
):
self
.
_lock_acquire
()
self
.
_lock_acquire
()
...
@@ -70,8 +75,7 @@ class MappingStorage(BaseStorage.BaseStorage):
...
@@ -70,8 +75,7 @@ class MappingStorage(BaseStorage.BaseStorage):
self
.
_lock_acquire
()
self
.
_lock_acquire
()
try
:
try
:
# The tid is the first 8 bytes of the buffer.
# The tid is the first 8 bytes of the buffer.
s
=
self
.
_index
[
oid
]
return
self
.
_index
[
oid
][:
8
]
return
s
[:
8
]
finally
:
finally
:
self
.
_lock_release
()
self
.
_lock_release
()
...
@@ -81,13 +85,12 @@ class MappingStorage(BaseStorage.BaseStorage):
...
@@ -81,13 +85,12 @@ class MappingStorage(BaseStorage.BaseStorage):
raise
POSException
.
StorageTransactionError
(
self
,
transaction
)
raise
POSException
.
StorageTransactionError
(
self
,
transaction
)
if
version
:
if
version
:
raise
POSException
.
Unsupported
,
"Versions aren't supported"
raise
POSException
.
Unsupported
(
"Versions aren't supported"
)
self
.
_lock_acquire
()
self
.
_lock_acquire
()
try
:
try
:
if
self
.
_index
.
has_key
(
oid
):
if
oid
in
self
.
_index
:
old
=
self
.
_index
[
oid
]
oserial
=
self
.
_index
[
oid
][:
8
]
oserial
=
old
[:
8
]
if
serial
!=
oserial
:
if
serial
!=
oserial
:
raise
POSException
.
ConflictError
(
oid
=
oid
,
raise
POSException
.
ConflictError
(
oid
=
oid
,
serials
=
(
oserial
,
serial
),
serials
=
(
oserial
,
serial
),
...
@@ -102,8 +105,7 @@ class MappingStorage(BaseStorage.BaseStorage):
...
@@ -102,8 +105,7 @@ class MappingStorage(BaseStorage.BaseStorage):
self
.
_tindex
=
[]
self
.
_tindex
=
[]
def
_finish
(
self
,
tid
,
user
,
desc
,
ext
):
def
_finish
(
self
,
tid
,
user
,
desc
,
ext
):
for
oid
,
p
in
self
.
_tindex
:
self
.
_index
.
update
(
dict
(
self
.
_tindex
))
self
.
_index
[
oid
]
=
p
self
.
_ltid
=
self
.
_tid
self
.
_ltid
=
self
.
_tid
def
lastTransaction
(
self
):
def
lastTransaction
(
self
):
...
@@ -119,17 +121,16 @@ class MappingStorage(BaseStorage.BaseStorage):
...
@@ -119,17 +121,16 @@ class MappingStorage(BaseStorage.BaseStorage):
pindex
=
{}
pindex
=
{}
while
rootl
:
while
rootl
:
oid
=
rootl
.
pop
()
oid
=
rootl
.
pop
()
if
pindex
.
has_key
(
oid
)
:
if
oid
in
pindex
:
continue
continue
# Scan non-version pickle for references
# Scan non-version pickle for references
r
=
self
.
_index
[
oid
]
r
=
self
.
_index
[
oid
]
pindex
[
oid
]
=
r
pindex
[
oid
]
=
r
p
=
r
[
8
:]
referencesf
(
r
[
8
:],
rootl
)
referencesf
(
p
,
rootl
)
# Now delete any unreferenced entries:
# Now delete any unreferenced entries:
for
oid
in
self
.
_index
.
keys
():
for
oid
in
self
.
_index
.
keys
():
if
not
pindex
.
has_key
(
oid
)
:
if
oid
not
in
pindex
:
del
self
.
_index
[
oid
]
del
self
.
_index
[
oid
]
finally
:
finally
:
...
@@ -137,13 +138,12 @@ class MappingStorage(BaseStorage.BaseStorage):
...
@@ -137,13 +138,12 @@ class MappingStorage(BaseStorage.BaseStorage):
def
_splat
(
self
):
def
_splat
(
self
):
"""Spit out a string showing state."""
"""Spit out a string showing state."""
o
=
[]
o
=
[
'Index:'
]
o
.
append
(
'Index:'
)
keys
=
self
.
_index
.
keys
()
keys
=
self
.
_index
.
keys
()
keys
.
sort
()
keys
.
sort
()
for
oid
in
keys
:
for
oid
in
keys
:
r
=
self
.
_index
[
oid
]
r
=
self
.
_index
[
oid
]
o
.
append
(
' %s: %s, %s'
%
o
.
append
(
' %s: %s, %s'
%
(
u64
(
oid
),
TimeStamp
(
r
[:
8
]),
`r[8:]`
))
(
u64
(
oid
),
TimeStamp
(
r
[:
8
]),
repr
(
r
[
8
:])
))
return
'
\
n
'
.
join
(
o
)
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