-
Notifications
You must be signed in to change notification settings - Fork 59
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
Env open with Flags::MdbNoSubDir
flag requires target file to exists
#145
Comments
I had the same issue, as a new Rust user the error message was super confusing |
Thank you @shedar and @missinglink for the feedback. Unfortunately, heed tries to make LMDB safe to use, and one limitation of LMDB is that one process must not open the same environment twice. Therefore, heed ensures that the targeted path doesn't point to the same env by canonicalizing it. I can propose different solutions to fix this issue:
What do you think about those solutions? Do you have more solutions to propose? |
I was thinking about something like this:
This way, the lock prevents parallel attempts to create the file (probably with an additional check that the file doesn't exist after acquiring the lock). At the same time, we only do additional file operations within the lock when opening non-existing env, so it shouldn’t be a performance hit for regular flow. And it doesn't require additional options. The edge case I see is the following scenario:
But I have a hard time coming up with a real-world scenario where this edge-case flow makes sense. What do you think? |
Your solution is perfect for me. I implemented it in #158, but only the great lines. Can you review it and test it? Be careful. It is on the main branch, part of the v0.20.0 version. A lot of breaking changes are coming for the best. |
@Kerollmops Thank you for the quick implementation. I've tried the PR branch with my test project - works great. BTW, do you have any plans for #41 any time soon? I see it's not in the v0.20.0 milestone for now. |
The amount of work to implement it in a correct and idiomatic way would be too much, but could you propose something on #41 and help me? I also see an issue with the |
Hi @Kerollmops, I'm new to Rust (but have used LMDB in a few other languages), this doesn't seem right to me 🤔 I believe it's still possible to open the same file twice, once using the
I could be wrong here, but isn't only the directory The merged patch seems to use a fallback method, running My suggestion would be to only ever canonicalize the actual data file and never a directory. |
Hey @missinglink, Thank you very much for this feedback. So what you recommend could be something like this: If the This way, we will only canonicalize the path once and always store the environment under the data file itself. We can only open the same environment once with different options. What do you think about this? |
That sounds reasonable, I'm just unclear about the naming convention 'data.mdb'. I wonder where this is defined and whether the extension is influenced by the user path 🤔 I can have a look through the C source tomorrow and post links. |
It looks like the names are static and will always be the same when the |
Yeah nice, FWIW checking the paths isn't ever going to be perfect, what you'd really need to do is check that the two paths refer to the same device and inode as per https://github.com/BurntSushi/same-file It's a convoluted example I admit, but you can open a database as This is one of those things that's actually way trickier than it initially seems. |
I'm trying to create a DB like "some_dir/custom.mdb". Where "custom.mdb" is a file, not a directory. I use
Flags::MdbNoSubDir
to achieve it.The current implementation requires the target file to exist due to the use of canonicalize, even though underlying
mdb_env_open
works without creating the file.It works if I create an empty file manually, but it would be great to not touch the DB file explicitly.
The text was updated successfully, but these errors were encountered: