Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
tempstorage
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
nexedi
tempstorage
Commits
1955289d
Commit
1955289d
authored
May 02, 2010
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Approximate PEP8 compliance.
parent
adb57282
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
60 deletions
+87
-60
src/tempstorage/TemporaryStorage.py
src/tempstorage/TemporaryStorage.py
+87
-60
No files found.
src/tempstorage/TemporaryStorage.py
View file @
1955289d
...
@@ -59,21 +59,36 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
...
@@ -59,21 +59,36 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
def
__init__
(
self
,
name
=
'TemporaryStorage'
):
def
__init__
(
self
,
name
=
'TemporaryStorage'
):
"""
"""
index -- mapping of oid to current serial
_index -- mapping, oid => current serial
referenceCount -- mapping of oid to count
oreferences -- mapping of oid to a sequence of its referenced oids
_referenceCount -- mapping, oid => count
opickle -- mapping of oid to pickle
_oreferences -- mapping, oid => sequence of referenced oids
_opickle -- mapping, oid => pickle
_tmp -- used by 'store' to collect changes before finalization
_tmp -- used by 'store' to collect changes before finalization
_conflict_cache -- cache of recently-written object revisions
_conflict_cache -- cache of recently-written object revisions
_last_cache_gc -- last time that conflict cache was garbage collected
_last_cache_gc -- last time that conflict cache was garbage collected
_recently_gc_oids -- a queue of recently gc'ed oids
_recently_gc_oids -- a queue of recently GC'ed oids
_oid -- ???
_ltid -- serial of last committed transaction (required by ZEO)
_conflict_cache_gcevery -- interval for doing GC on conflict cache
_conflict_cache_maxage -- age at whic conflict cache items are GC'ed
"""
"""
BaseStorage
.
__init__
(
self
,
name
)
BaseStorage
.
__init__
(
self
,
name
)
self
.
_index
=
{}
self
.
_index
=
{}
self
.
_referenceCount
=
{}
self
.
_referenceCount
=
{}
self
.
_oreferences
=
{}
self
.
_oreferences
=
{}
self
.
_opickle
=
{}
self
.
_opickle
=
{}
self
.
_tmp
=
[]
self
.
_tmp
=
[]
self
.
_conflict_cache
=
{}
self
.
_conflict_cache
=
{}
self
.
_last_cache_gc
=
0
self
.
_last_cache_gc
=
0
...
@@ -114,8 +129,8 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
...
@@ -114,8 +129,8 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
self
.
_lock_acquire
()
self
.
_lock_acquire
()
try
:
try
:
try
:
try
:
s
=
self
.
_index
[
oid
]
s
=
self
.
_index
[
oid
]
p
=
self
.
_opickle
[
oid
]
p
=
self
.
_opickle
[
oid
]
return
p
,
s
# pickle, serial
return
p
,
s
# pickle, serial
except
KeyError
:
except
KeyError
:
# this oid was probably garbage collected while a thread held
# this oid was probably garbage collected while a thread held
...
@@ -176,7 +191,7 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
...
@@ -176,7 +191,7 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
try
:
try
:
tids
=
[
stid
for
soid
,
stid
in
self
.
_conflict_cache
if
soid
==
oid
]
tids
=
[
stid
for
soid
,
stid
in
self
.
_conflict_cache
if
soid
==
oid
]
if
not
tids
:
if
not
tids
:
raise
KeyError
,
oid
raise
KeyError
(
oid
)
tids
.
sort
()
tids
.
sort
()
i
=
bisect
.
bisect_left
(
tids
,
tid
)
-
1
i
=
bisect
.
bisect_left
(
tids
,
tid
)
-
1
if
i
==
-
1
:
if
i
==
-
1
:
...
@@ -204,45 +219,45 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
...
@@ -204,45 +219,45 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
self
.
_lock_acquire
()
self
.
_lock_acquire
()
try
:
try
:
if
self
.
_index
.
has_key
(
oid
):
if
self
.
_index
.
has_key
(
oid
):
oserial
=
self
.
_index
[
oid
]
oserial
=
self
.
_index
[
oid
]
if
serial
!=
oserial
:
if
serial
!=
oserial
:
newdata
=
self
.
tryToResolveConflict
(
newdata
=
self
.
tryToResolveConflict
(
oid
,
oserial
,
serial
,
data
)
oid
,
oserial
,
serial
,
data
)
if
not
newdata
:
if
not
newdata
:
raise
POSException
.
ConflictError
(
raise
POSException
.
ConflictError
(
oid
=
oid
,
oid
=
oid
,
serials
=
(
oserial
,
serial
),
serials
=
(
oserial
,
serial
),
data
=
data
)
data
=
data
)
else
:
else
:
data
=
newdata
data
=
newdata
else
:
else
:
oserial
=
serial
oserial
=
serial
newserial
=
self
.
_tid
newserial
=
self
.
_tid
self
.
_tmp
.
append
((
oid
,
data
))
self
.
_tmp
.
append
((
oid
,
data
))
return
serial
==
oserial
and
newserial
or
ResolvedSerial
return
serial
==
oserial
and
newserial
or
ResolvedSerial
finally
:
finally
:
self
.
_lock_release
()
self
.
_lock_release
()
def
_finish
(
self
,
tid
,
u
,
d
,
e
):
def
_finish
(
self
,
tid
,
u
,
d
,
e
):
zeros
=
{}
zeros
=
{}
referenceCount
=
self
.
_referenceCount
referenceCount
=
self
.
_referenceCount
referenceCount_get
=
referenceCount
.
get
referenceCount_get
=
referenceCount
.
get
oreferences
=
self
.
_oreferences
oreferences
=
self
.
_oreferences
serial
=
self
.
_tid
serial
=
self
.
_tid
index
=
self
.
_index
index
=
self
.
_index
opickle
=
self
.
_opickle
opickle
=
self
.
_opickle
self
.
_ltid
=
tid
self
.
_ltid
=
tid
# iterate over all the objects touched by/created within this
# iterate over all the objects touched by/created within this
# transaction
# transaction
for
entry
in
self
.
_tmp
:
for
entry
in
self
.
_tmp
:
oid
,
data
=
entry
[:]
oid
,
data
=
entry
[:]
referencesl
=
[]
referencesl
=
[]
referencesf
(
data
,
referencesl
)
referencesf
(
data
,
referencesl
)
references
=
{}
references
=
{}
for
roid
in
referencesl
:
for
roid
in
referencesl
:
references
[
roid
]
=
1
references
[
roid
]
=
1
referenced
=
references
.
has_key
referenced
=
references
.
has_key
# Create a reference count for this object if one
# Create a reference count for this object if one
# doesn't already exist
# doesn't already exist
...
@@ -265,16 +280,16 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
...
@@ -265,16 +280,16 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
oreferences
[
oid
].
remove
(
roid
)
oreferences
[
oid
].
remove
(
roid
)
# decrement refcnt:
# decrement refcnt:
rc
=
referenceCount_get
(
roid
,
1
)
rc
=
referenceCount_get
(
roid
,
1
)
rc
=
rc
-
1
rc
=
rc
-
1
if
rc
<
0
:
if
rc
<
0
:
# This should never happen
# This should never happen
raise
ReferenceCountError
,
(
raise
ReferenceCountError
(
"%s (Oid %
s
had refcount %s)"
%
"%s (Oid %
r
had refcount %s)"
%
(
ReferenceCountError
.
__doc__
,
`roid`
,
rc
)
(
ReferenceCountError
.
__doc__
,
roid
,
rc
)
)
)
referenceCount
[
roid
]
=
rc
referenceCount
[
roid
]
=
rc
if
rc
==
0
:
if
rc
==
0
:
zeros
[
roid
]
=
1
zeros
[
roid
]
=
1
# Create a reference list for this object if one
# Create a reference list for this object if one
# doesn't already exist
# doesn't already exist
...
@@ -285,37 +300,46 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
...
@@ -285,37 +300,46 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
for
roid
in
references
.
keys
():
for
roid
in
references
.
keys
():
oreferences
[
oid
].
append
(
roid
)
oreferences
[
oid
].
append
(
roid
)
# Create/update refcnt
# Create/update refcnt
rc
=
referenceCount_get
(
roid
,
0
)
rc
=
referenceCount_get
(
roid
,
0
)
if
rc
==
0
and
zeros
.
get
(
roid
)
is
not
None
:
if
rc
==
0
and
zeros
.
get
(
roid
)
is
not
None
:
del
zeros
[
roid
]
del
zeros
[
roid
]
referenceCount
[
roid
]
=
rc
+
1
referenceCount
[
roid
]
=
rc
+
1
index
[
oid
]
=
serial
index
[
oid
]
=
serial
opickle
[
oid
]
=
data
opickle
[
oid
]
=
data
now
=
time
.
time
()
now
=
time
.
time
()
self
.
_conflict_cache
[(
oid
,
serial
)]
=
data
,
now
self
.
_conflict_cache
[(
oid
,
serial
)]
=
data
,
now
if
zeros
:
if
zeros
:
for
oid
in
zeros
.
keys
():
for
oid
in
zeros
.
keys
():
if
oid
==
'
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
'
:
continue
if
oid
==
'
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
'
:
continue
self
.
_takeOutGarbage
(
oid
)
self
.
_takeOutGarbage
(
oid
)
self
.
_tmp
=
[]
self
.
_tmp
=
[]
def
_takeOutGarbage
(
self
,
oid
):
def
_takeOutGarbage
(
self
,
oid
):
# take out the garbage.
# take out the garbage.
referenceCount
=
self
.
_referenceCount
referenceCount
=
self
.
_referenceCount
referenceCount_get
=
referenceCount
.
get
referenceCount_get
=
referenceCount
.
get
self
.
_recently_gc_oids
.
pop
()
self
.
_recently_gc_oids
.
pop
()
self
.
_recently_gc_oids
.
insert
(
0
,
oid
)
self
.
_recently_gc_oids
.
insert
(
0
,
oid
)
try
:
del
referenceCount
[
oid
]
try
:
except
:
pass
del
referenceCount
[
oid
]
try
:
del
self
.
_opickle
[
oid
]
except
:
except
:
pass
pass
try
:
del
self
.
_index
[
oid
]
except
:
pass
try
:
del
self
.
_opickle
[
oid
]
except
:
pass
try
:
del
self
.
_index
[
oid
]
except
:
pass
# remove this object from the conflict cache if it exists there
# remove this object from the conflict cache if it exists there
for
k
in
self
.
_conflict_cache
.
keys
():
for
k
in
self
.
_conflict_cache
.
keys
():
...
@@ -329,32 +353,35 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
...
@@ -329,32 +353,35 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
# decrement refcnt:
# decrement refcnt:
# DM 2005-01-07: decrement *before* you make the test!
# DM 2005-01-07: decrement *before* you make the test!
# rc=referenceCount_get(roid, 0)
# rc=referenceCount_get(roid, 0)
rc
=
referenceCount_get
(
roid
,
0
)
-
1
rc
=
referenceCount_get
(
roid
,
0
)
-
1
if
rc
==
0
:
if
rc
==
0
:
self
.
_takeOutGarbage
(
roid
)
self
.
_takeOutGarbage
(
roid
)
elif
rc
<
0
:
elif
rc
<
0
:
raise
ReferenceCountError
,
(
raise
ReferenceCountError
(
"%s (Oid %
s
had refcount %s)"
%
"%s (Oid %
r
had refcount %s)"
%
(
ReferenceCountError
.
__doc__
,
`roid`
,
rc
)
(
ReferenceCountError
.
__doc__
,
roid
,
rc
)
)
)
else
:
else
:
# DM 2005-01-07: decremented *before* the test! see above
# DM 2005-01-07: decremented *before* the test! see above
#referenceCount[roid] = rc - 1
#referenceCount[roid] = rc - 1
referenceCount
[
roid
]
=
rc
referenceCount
[
roid
]
=
rc
try
:
del
self
.
_oreferences
[
oid
]
try
:
except
:
pass
del
self
.
_oreferences
[
oid
]
except
:
pass
def
pack
(
self
,
t
,
referencesf
):
def
pack
(
self
,
t
,
referencesf
):
self
.
_lock_acquire
()
self
.
_lock_acquire
()
try
:
try
:
rindex
=
{}
rindex
=
{}
referenced
=
rindex
.
has_key
referenced
=
rindex
.
has_key
rootl
=
[
'
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
'
]
rootl
=
[
'
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
'
]
# mark referenced objects
# mark referenced objects
while
rootl
:
while
rootl
:
oid
=
rootl
.
pop
()
oid
=
rootl
.
pop
()
if
referenced
(
oid
):
continue
if
referenced
(
oid
):
continue
p
=
self
.
_opickle
[
oid
]
p
=
self
.
_opickle
[
oid
]
referencesf
(
p
,
rootl
)
referencesf
(
p
,
rootl
)
rindex
[
oid
]
=
None
rindex
[
oid
]
=
None
...
...
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