New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Race condition in storage.py for NestedDirectoryStore writes #272
Comments
Thanks Justin. On Python 3 I think we could just do os.makedirs(...,
exist_ok=True). Not available in Python 2 unfortunately.
There's also another race condition issue in DirectoryStore, would be good
to get both resolved, could be addressed in same PR:
#263
…On Fri, 6 Jul 2018, 06:02 Justin Swaney, ***@***.***> wrote:
I've encountered a FileExistsError when writing in parallel to a
NestedDirectoryStore that says:
FileExistsError: [Errno 17] File exists:
'/media/jswaney/Drive/Justin/coregistration/whole_brain_tde/fixed/zarr/4/10'
The error points to the os.makedirs(dir_path) line in __setitem__ for the
DirectoryStore class:
dir_path, file_name = os.path.split(file_path)if os.path.isfile(dir_path):
raise KeyError(key)if not os.path.exists(dir_path):
try:
os.makedirs(dir_path) # Error raised here
except Exception:
raise KeyError(key)
I was doing the chunk compression with 12 workers, so I think one of them
created the subdirectory while another had already checked that it didn't
exist. When it got to os.makedirs, it gave the expected error. A quick
fix would just be to catch this error, but a better fix might be to just
make all the directories for a NestedDirectoryStore ahead of time.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#272>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAq8QoBvx_MpUqzyNOrahocByEx2mK8aks5uDu9wgaJpZM4VE4sR>
.
|
It looks like there are a couple options for the Python 2 vs 3 problem listed here. They mention the |
It sounds like we are already interested in using |
Note: Work on this is currently being pursued in PR ( #318 ). |
* #272 fix race condition to make folders in directory store * #272 remove FileNotFoundError for python 2 support * Change OSError to KeyError to make tests pass * Only catch `OSError` if its `errno` equal `EEXIST` On Python 3, we would only want to catch the race case here by checking for the `FileExistsError` and suppressing raising for that case. However there is no `FileExistsError` on Python 2. Only `OSError` exists on Python 2/3. However that catches some other errors that we might not want to suppress here. So we check the `errno` of the `OSError` instance to verify it is caused by an existing file/directory represented by the `EEXIST` error number. This amounts to catching the `FileExistsError` in a Python 2/3 friendly way. All other `OSErrors` we raise as before. * Drop generic `Exception` case in `DirectoryStore` As we now properly handle the existing file case properly, go ahead and drop the generic exception case. This should now raise some errors that were hidden previously.
I've encountered a
FileExistsError
when writing in parallel to aNestedDirectoryStore
that says:FileExistsError: [Errno 17] File exists: '/media/jswaney/Drive/Justin/coregistration/whole_brain_tde/fixed/zarr/4/10'
The error points to the
os.makedirs(dir_path)
line in__setitem__
for theDirectoryStore
class:I was doing the chunk compression with 12 workers, so I think one of them created the subdirectory while another had already checked that it didn't exist. When it got to
os.makedirs
, it gave the expected error. A quick fix would just be to catch this error, but a better fix might be to just make all the directories for aNestedDirectoryStore
ahead of time.The text was updated successfully, but these errors were encountered: