Skip to content
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

daf_persistence add functions to query if a storage exists at a location #50

Merged
merged 2 commits into from Mar 18, 2017

Conversation

n8pease
Copy link
Contributor

@n8pease n8pease commented Mar 17, 2017

No description provided.

jhoblitt
jhoblitt previously approved these changes Mar 17, 2017
bool
True if the storage exists, false if not
"""
return os.path.exists(PosixStorage._pathFromURI(uri))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this boils down to a stat(2) call, so this should be nice and atomic.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe @timj's concern is valid. Two threads could both make the stat(2) call while the dir does not exist and then collide on directory creation.

@jhoblitt
Copy link

This looks reasonable to me but I am unfamiliar with this code.

@@ -50,7 +50,7 @@ def __init__(self, uri):
:return:
"""
self.log = Log.getLogger("daf.persistence.butler")
self.root = urllib.parse.urlparse(uri).path
self.root = self._pathFromURI(uri)
if self.root and not os.path.exists(self.root):
os.makedirs(self.root)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should use the safe safeMakeDir().

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this... is using the exist_ok param not enough?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at safeMakeDir and I'm not sure if it is actually safe if the path it is given contains multiple [new] nested dirs.

Copy link
Member

@timj timj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with the code much and the code looks fine as such but I have a big BUT. Can you please explain in the commit message why this is fixing the race condition described in DM-9848? On the face of it the posixStorage code has just moved the URL parsing from one place to another without obviously adjusting how the os.makedirs is run.

@@ -601,6 +606,22 @@ def search(root, path, searchParents=False):
else:
return None

@staticmethod
def storageExists(uri):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is added but nothing in this commit seems to call it. Is it a specialization of a base implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's called by the new code in storageContinued.py

@n8pease n8pease merged commit a039304 into master Mar 18, 2017
@ktlim ktlim deleted the tickets/DM-9848 branch August 25, 2018 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants