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
794fb62b
Commit
794fb62b
authored
Jun 10, 2009
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored to avoid a race condition between saving a blob to the
cache and cleaning the cache.
parent
1abda8ac
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
22 deletions
+29
-22
src/ZEO/ClientStorage.py
src/ZEO/ClientStorage.py
+29
-22
No files found.
src/ZEO/ClientStorage.py
View file @
794fb62b
...
...
@@ -1006,15 +1006,7 @@ class ClientStorage(object):
# getting it multiple times even accross separate client
# processes on the same machine. We'll use file locking.
lockfilename
=
os
.
path
.
join
(
os
.
path
.
dirname
(
blob_filename
),
'.lock'
)
while
1
:
try
:
lock
=
zc
.
lockfile
.
LockFile
(
lockfilename
)
except
zc
.
lockfile
.
LockError
:
time
.
sleep
(
0.01
)
else
:
break
lock
=
_lock_blob
(
blob_filename
)
try
:
# We got the lock, so it's our job to download it. First,
# we'll double check that someone didn't download it while we
...
...
@@ -1049,15 +1041,7 @@ class ClientStorage(object):
# Fall through and try again with the protection of the lock.
pass
lockfilename
=
os
.
path
.
join
(
os
.
path
.
dirname
(
blob_filename
),
'.lock'
)
while
1
:
try
:
lock
=
zc
.
lockfile
.
LockFile
(
lockfilename
)
except
zc
.
lockfile
.
LockError
:
time
.
sleep
(.
01
)
else
:
break
lock
=
_lock_blob
(
blob_filename
)
try
:
blob_filename
=
self
.
fshelper
.
getBlobFilename
(
oid
,
serial
)
if
not
os
.
path
.
exists
(
blob_filename
):
...
...
@@ -1216,14 +1200,23 @@ class ClientStorage(object):
if
self
.
fshelper
is
not
None
:
blobs
=
self
.
_tbuf
.
blobs
had_blobs
=
False
while
blobs
:
oid
,
blobfilename
=
blobs
.
pop
()
self
.
_blob_data_bytes_loaded
+=
os
.
stat
(
blobfilename
).
st_size
targetpath
=
self
.
fshelper
.
getPathForOID
(
oid
,
create
=
True
)
ZODB
.
blob
.
rename_or_copy_blob
(
blobfilename
,
self
.
fshelper
.
getBlobFilename
(
oid
,
tid
),
)
target_blob_file_name
=
self
.
fshelper
.
getBlobFilename
(
oid
,
tid
)
lock
=
_lock_blob
(
target_blob_file_name
)
try
:
ZODB
.
blob
.
rename_or_copy_blob
(
blobfilename
,
target_blob_file_name
,
)
finally
:
lock
.
close
()
had_blobs
=
True
if
had_blobs
:
self
.
_check_blob_size
(
self
.
_blob_data_bytes_loaded
)
self
.
_tbuf
.
clear
()
...
...
@@ -1724,3 +1717,17 @@ def check_blob_size_script(args=None):
args
=
sys
.
argv
[
1
:]
blob_dir
,
target
=
args
_check_blob_cache_size
(
blob_dir
,
int
(
target
))
def
_lock_blob
(
path
):
lockfilename
=
os
.
path
.
join
(
os
.
path
.
dirname
(
path
),
'.lock'
)
n
=
0
while
1
:
try
:
return
zc
.
lockfile
.
LockFile
(
lockfilename
)
except
zc
.
lockfile
.
LockError
:
time
.
sleep
(
0.01
)
n
+=
1
if
n
>
60000
:
raise
else
:
break
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