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
e0f1a9d5
Commit
e0f1a9d5
authored
May 02, 2010
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean imports, docstrings; add an instance-level hook for GC parms.
parent
d49d49a3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
47 deletions
+47
-47
src/tempstorage/TemporaryStorage.py
src/tempstorage/TemporaryStorage.py
+45
-33
src/tempstorage/tests/testTemporaryStorage.py
src/tempstorage/tests/testTemporaryStorage.py
+2
-14
No files found.
src/tempstorage/TemporaryStorage.py
View file @
e0f1a9d5
...
...
@@ -10,45 +10,50 @@
# FOR A PARTICULAR PURPOSE
#
##############################################################################
""" A storage implementation which uses RAM to persist objects
"""
A storage implementation which uses RAM to persist objects, much like
MappingStorage. Unlike MappingStorage, it needs not be packed to get rid of
non-cyclic garbage and it does rudimentary conflict resolution. This is a
ripoff of Jim's Packless bsddb3 storage.
Although this storage is much like MappingStorage, it does not need to be
packed to get rid of non-cyclic garbage and it does rudimentary conflict
resolution.
$Id$
This is a ripoff of Jim's Packless bsddb3 storage.
"""
__version__
=
'$Revision: 1.1.2.2 $'
[
11
:
-
2
]
import
bisect
from
logging
import
getLogger
from
ZODB.serialize
import
referencesf
from
ZODB.utils
import
z64
import
time
from
ZODB
import
POSException
from
ZODB.BaseStorage
import
BaseStorage
from
ZODB.ConflictResolution
import
ConflictResolvingStorage
,
ResolvedSerial
import
time
import
bisect
from
ZODB.ConflictResolution
import
ConflictResolvingStorage
from
ZODB.ConflictResolution
import
ResolvedSerial
from
ZODB.serialize
import
referencesf
from
ZODB.utils
import
z64
# keep old object revisions for CONFLICT_CACHE_MAXAGE seconds
CONFLICT_CACHE_MAXAGE
=
60
# garbage collect conflict cache every CONFLICT_CACHE_GCEVERY seconds
CONFLICT_CACHE_GCEVERY
=
60
# keep history of recently gc'ed oids of length RECENTLY_GC_OIDS_LEN
RECENTLY_GC_OIDS_LEN
=
200
LOG
=
getLogger
(
'TemporaryStorage'
)
class
ReferenceCountError
(
POSException
.
POSError
):
""" An error occured while decrementing a reference to an object in
the commit phase. The object's reference count was below zero."""
""" Error while decrementing a reference to an object in the commit phase.
The object's reference count was below zero.
"""
class
TemporaryStorageError
(
POSException
.
POSError
):
""" A Temporary Storage exception occurred. This probably indicates that
there is a low memory condition or a tempfile space shortage. Check
available tempfile space and RAM consumption and restart the server
process."""
""" A Temporary Storage exception occurred.
This probably indicates that there is a low memory condition or a
tempfile space shortage. Check available tempfile space and RAM
consumption and restart the server process.
"""
class
TemporaryStorage
(
BaseStorage
,
ConflictResolvingStorage
):
...
...
@@ -76,8 +81,13 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
self
.
_oid
=
z64
self
.
_ltid
=
z64
# Alow overrides for testing.
self
.
_conflict_cache_gcevery
=
CONFLICT_CACHE_GCEVERY
self
.
_conflict_cache_maxage
=
CONFLICT_CACHE_MAXAGE
def
lastTransaction
(
self
):
""" Return tid for last committed transaction (for ZEO) """
""" Return tid for last committed transaction (for ZEO)
"""
return
self
.
_ltid
def
__len__
(
self
):
...
...
@@ -88,17 +98,16 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
def
_clear_temp
(
self
):
now
=
time
.
time
()
if
now
>
(
self
.
_last_cache_gc
+
CONFLICT_CACHE_GCEVERY
):
if
now
>
(
self
.
_last_cache_gc
+
self
.
_conflict_cache_gcevery
):
for
k
,
v
in
self
.
_conflict_cache
.
items
():
data
,
t
=
v
if
now
>
(
t
+
CONFLICT_CACHE_MAXAGE
):
if
now
>
(
t
+
self
.
_conflict_cache_maxage
):
del
self
.
_conflict_cache
[
k
]
self
.
_last_cache_gc
=
now
self
.
_tmp
=
[]
def
close
(
self
):
"""
Close the storage
""" Close the storage
"""
def
load
(
self
,
oid
,
version
):
...
...
@@ -140,9 +149,11 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
return
(
data
[
0
],
data
[
1
],
""
)
def
loadSerial
(
self
,
oid
,
serial
,
marker
=
[]):
""" this is only useful to make conflict resolution work. It
does not actually implement all the semantics that a revisioning
storage needs! """
""" This is only useful to make conflict resolution work.
It does not actually implement all the semantics that a revisioning
storage needs!
"""
self
.
_lock_acquire
()
try
:
data
=
self
.
_conflict_cache
.
get
((
oid
,
serial
),
marker
)
...
...
@@ -156,9 +167,10 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
self
.
_lock_release
()
def
loadBefore
(
self
,
oid
,
tid
):
"""Return most recent revision of oid before tid committed
(for MVCC)
."""
""" Return most recent revision of oid before tid committed.
Needed for MVCC.
"""
# implementation stolen from ZODB.test_storage.MinimalMemoryStorage
self
.
_lock_acquire
()
try
:
...
...
@@ -186,8 +198,8 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
if
version
:
# we allow a version to be in use although we don't
# support versions in the storage.
LOG
.
debug
(
'versions in use with TemporaryStorage although
Temporary
'
'Storage doesnt support versions'
)
LOG
.
debug
(
'versions in use with TemporaryStorage although'
'
Temporary
Storage doesnt support versions'
)
self
.
_lock_acquire
()
try
:
...
...
src/tempstorage/tests/testTemporaryStorage.py
View file @
e0f1a9d5
...
...
@@ -17,8 +17,6 @@ class TemporaryStorageTests(StorageTestBase.StorageTestBase,
MTStorage
.
MTStorage
,
):
_old_conflict_cache
=
None
def
open
(
self
,
**
kwargs
):
from
tempstorage.TemporaryStorage
import
TemporaryStorage
self
.
_storage
=
TemporaryStorage
(
'foo'
)
...
...
@@ -29,17 +27,6 @@ class TemporaryStorageTests(StorageTestBase.StorageTestBase,
def
tearDown
(
self
):
StorageTestBase
.
StorageTestBase
.
tearDown
(
self
)
if
self
.
_old_conflict_cache
is
not
None
:
from
tempstorage
import
TemporaryStorage
as
TS
(
TS
.
CONFLICT_CACHE_GCEVERY
,
TS
.
CONFLICT_CACHE_MAXAGE
)
=
self
.
_old_conflict_cache
def
_set_conflict_cache
(
self
,
gcevery
,
maxage
):
from
tempstorage
import
TemporaryStorage
as
TS
self
.
_old_conflict_cache
=
(
TS
.
CONFLICT_CACHE_GCEVERY
,
TS
.
CONFLICT_CACHE_MAXAGE
)
TS
.
CONFLICT_CACHE_GCEVERY
=
gcevery
TS
.
CONFLICT_CACHE_MAXAGE
=
maxage
def
_do_read_conflict
(
self
,
db
,
mvcc
):
import
transaction
...
...
@@ -78,7 +65,8 @@ class TemporaryStorageTests(StorageTestBase.StorageTestBase,
def
checkConflictCacheIsCleared
(
self
):
import
time
from
ZODB.tests.MinPO
import
MinPO
self
.
_set_conflict_cache
(
1
,
1
)
self
.
_storage
.
_conflict_cache_gcevery
=
1
# second
self
.
_storage
.
_conflict_cache_maxage
=
1
# second
oid
=
self
.
_storage
.
new_oid
()
self
.
_dostore
(
oid
,
data
=
MinPO
(
5
))
...
...
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