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
1b31d7da
Commit
1b31d7da
authored
Feb 25, 2006
by
Christian Theune
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- better locking strategy
parent
ef881ad3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
81 additions
and
21 deletions
+81
-21
src/ZEO/ClientStorage.py
src/ZEO/ClientStorage.py
+81
-21
No files found.
src/ZEO/ClientStorage.py
View file @
1b31d7da
...
@@ -112,7 +112,7 @@ class ClientStorage(object):
...
@@ -112,7 +112,7 @@ class ClientStorage(object):
wait
=
None
,
wait_timeout
=
None
,
wait
=
None
,
wait_timeout
=
None
,
read_only
=
0
,
read_only_fallback
=
0
,
read_only
=
0
,
read_only_fallback
=
0
,
username
=
''
,
password
=
''
,
realm
=
None
,
username
=
''
,
password
=
''
,
realm
=
None
,
blob_dir
=
tempfile
.
gettempdir
()
):
blob_dir
=
None
):
"""ClientStorage constructor.
"""ClientStorage constructor.
This is typically invoked from a custom_zodb.py file.
This is typically invoked from a custom_zodb.py file.
...
@@ -316,6 +316,10 @@ class ClientStorage(object):
...
@@ -316,6 +316,10 @@ class ClientStorage(object):
self
.
blob_dir
=
blob_dir
self
.
blob_dir
=
blob_dir
# Initialize locks
self
.
blob_status_lock
=
threading
.
Lock
()
self
.
blob_status
=
{}
# Decide whether to use non-temporary files
# Decide whether to use non-temporary files
if
client
is
not
None
:
if
client
is
not
None
:
dir
=
var
or
os
.
getcwd
()
dir
=
var
or
os
.
getcwd
()
...
@@ -759,6 +763,7 @@ class ClientStorage(object):
...
@@ -759,6 +763,7 @@ class ClientStorage(object):
return
self
.
loadEx
(
oid
,
version
)[:
2
]
return
self
.
loadEx
(
oid
,
version
)[:
2
]
def
loadEx
(
self
,
oid
,
version
):
def
loadEx
(
self
,
oid
,
version
):
print
"LOAD"
self
.
_lock
.
acquire
()
# for atomic processing of invalidations
self
.
_lock
.
acquire
()
# for atomic processing of invalidations
try
:
try
:
t
=
self
.
_cache
.
load
(
oid
,
version
)
t
=
self
.
_cache
.
load
(
oid
,
version
)
...
@@ -899,6 +904,7 @@ class ClientStorage(object):
...
@@ -899,6 +904,7 @@ class ClientStorage(object):
return
self
.
_check_serials
()
return
self
.
_check_serials
()
def
storeBlob
(
self
,
oid
,
serial
,
data
,
blobfilename
,
version
,
txn
):
def
storeBlob
(
self
,
oid
,
serial
,
data
,
blobfilename
,
version
,
txn
):
"""Storage API: store a blob object."""
serials
=
self
.
store
(
oid
,
serial
,
data
,
version
,
txn
)
serials
=
self
.
store
(
oid
,
serial
,
data
,
version
,
txn
)
blobfile
=
open
(
blobfilename
,
"rb"
)
blobfile
=
open
(
blobfilename
,
"rb"
)
while
True
:
while
True
:
...
@@ -925,16 +931,14 @@ class ClientStorage(object):
...
@@ -925,16 +931,14 @@ class ClientStorage(object):
BLOB_SUFFIX
,)
BLOB_SUFFIX
,)
)
)
def
loadBlob
(
self
,
oid
,
serial
,
version
):
def
_do_load_blob
(
self
,
oid
,
serial
):
"""Do the actual loading from the RPC server."""
blob_filename
=
self
.
_getCleanFilename
(
oid
,
serial
)
blob_filename
=
self
.
_getCleanFilename
(
oid
,
serial
)
if
os
.
path
.
exists
(
blob_filename
):
# XXX see race condition below
return
blob_filename
self
.
_load_lock
.
acquire
()
try
:
if
self
.
_server
is
None
:
if
self
.
_server
is
None
:
raise
ClientDisconnected
()
raise
ClientDisconnected
()
# We write to a temporary file first, so we do not accidentally
# allow half-baked copies of this blob be loaded
tempfilename
=
self
.
_getDirtyFilename
(
oid
,
serial
)
tempfilename
=
self
.
_getDirtyFilename
(
oid
,
serial
)
tempfile
=
open
(
tempfilename
,
"wb"
)
tempfile
=
open
(
tempfilename
,
"wb"
)
...
@@ -949,8 +953,64 @@ class ClientStorage(object):
...
@@ -949,8 +953,64 @@ class ClientStorage(object):
tempfile
.
close
()
tempfile
.
close
()
utils
.
best_rename
(
tempfilename
,
blob_filename
)
utils
.
best_rename
(
tempfilename
,
blob_filename
)
return
blob_filename
return
blob_filename
def
loadBlob
(
self
,
oid
,
serial
,
version
):
"""Loading a blob has to know about loading the same blob
from another thread as the same time.
1. Check if the blob is downloaded already
2. Check whether it is currently beeing downloaded
2a. Wait for other download to finish, return
3. If not beeing downloaded, start download
"""
if
self
.
blob_dir
is
None
:
raise
POSException
.
Unsupported
(
"No blob cache directory is configured. Can not load blob."
)
blob_filename
=
self
.
_getCleanFilename
(
oid
,
serial
)
# Case 1: Blob is available already, just use it
if
os
.
path
.
exists
(
blob_filename
):
return
blob_filename
# Case 2,3: Blob might still be downloading or not there yet
# Try to get or create a lock for the downloading of this blob,
# identified by it's oid and serial
lock_key
=
(
oid
,
serial
)
# We need to make the check for an existing lock and the possible
# creation of a new one atomic, so there is another lock:
self
.
blob_status_lock
.
acquire
()
try
:
if
not
self
.
blob_status
.
has_key
(
oid
):
self
.
blob_status
[
lock_key
]
=
Lock
()
lock
=
self
.
blob_status
[
lock_key
]
finally
:
finally
:
self
.
_load_lock
.
release
()
self
.
blob_status_lock
.
release
()
# We acquire the lock to either start downloading, or wait
# for another download to finish
lock
.
acquire
()
try
:
# If there was another download that is finished by now,
# we just take the result.
if
os
.
path
.
exists
(
blob_filename
):
return
blob_filename
# Otherwise we download and use that
return
self
.
_do_load_blob
(
oid
,
serial
)
finally
:
# When done we remove the download lock ...
lock
.
release
()
# And the status information isn't needed as well,
# but we have to use the second lock here as well, to avoid
# making the creation of this status lock non-atomic (see above)
self
.
blob_status_lock
.
acquire
()
try
:
del
self
.
blob_status_lock
[
lock_key
]
finally
:
self
.
blob_status_lock
.
release
()
def
tpc_vote
(
self
,
txn
):
def
tpc_vote
(
self
,
txn
):
"""Storage API: vote on a transaction."""
"""Storage API: vote on a transaction."""
...
...
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