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

Open LMDB files with MDB_NOLOCK if no write access #3088

Merged
merged 2 commits into from
Oct 21, 2015

Conversation

lukeyeager
Copy link
Contributor

Similar to [the first half of] #2384. The difference is that MDB_NOLOCK is only used if you were unable to acquire the lock, and a WARNING will appear in the logs.

/cc @cypof @hyc

@longjon
Copy link
Contributor

longjon commented Sep 19, 2015

I think if we're going to allow this kind of behavior, it should be explicitly specified by the user, no? (This is still subject to @hyc's concerns, right?)

Allowing the user to demand something dangerous is okay; falling back to dangerous behavior isn't, IMO, log messages notwithstanding.

@longjon
Copy link
Contributor

longjon commented Sep 25, 2015

In fact I've been running into this myself lately, so I think I'm favor of having this functionality, but as an explicit (build?) option.

@lukeyeager
Copy link
Contributor Author

I think I'm favor of having this functionality, but as an explicit (build?) option.

Ok, build option added. Does ALLOW_LMDB_READONLY sound like the right name?

I also rearranged a few lines in the build files from #2523 and #3081 to standardize on the order USE_OPENCV, USE_LEVELDB, USE_LMDB and ALLOW_LMDB_READONLY. I did that mostly so that I could put the new option right below USE_LMDB.

@longjon
Copy link
Contributor

longjon commented Sep 25, 2015

"Allow readonly" doesn't feel right to me; you're always allowed to read a read-only LMDB. The issue is whether you're allowed to open an LMDB without locking (and indeed, the flag in question is MDB_NOLOCK). ALLOW_LMDB_NOLOCK seems more appropriate to me. The Makefile.config comment also needs to explain the issue (i.e., you should not set this flag if you will be reading LMDBs with any possibility of simultaneous read and write).

Rearranging lines is fine, but let's have a separate commit for that.

Enforcing a consistent ordering - OpenCV, LevelDB, LMDB

This will allow me to add the ALLOW_LMDB_NOLOCK option just after the
USE_LMDB option, while keeping the IO dependency options together.
This option lets you open LMDB files with the MDB_NOLOCK flag. You
should not set this flag if you will be reading LMDBs with any
possibility of simultaneous read and write.
@lukeyeager
Copy link
Contributor Author

ALLOW_LMDB_NOLOCK seems more appropriate to me

Haha ok that's what I started with initially but I changed my mind. Changed it back.

The Makefile.config comment also needs to explain the issue

Done.

Rearranging lines is fine, but let's have a separate commit for that.

Done.

@longjon
Copy link
Contributor

longjon commented Sep 25, 2015

Looks good except:

  • The default seems to be different between CMake and Makefile; should it be on or off? (I guess I'm in favor of off as the more conservative option.)
  • Is it necessary to call mdb_env_close and recall mdb_env_create if mdb_env_open fails? That seems odd to me but I'm not that familiar with the LMDB API.

@lukeyeager
Copy link
Contributor Author

The default seems to be different between CMake and Makefile; should it be on or off? (I guess I'm in favor of off as the more conservative option.)

They both default to OFF/0 already. I didn't add the ALLOW_LMDB_NOLOCK ?= 1 line.

Is it necessary to call mdb_env_close and recall mdb_env_create if mdb_env_open fails? That seems odd to me but I'm not that familiar with the LMDB API.

Seemed strange to me too. I think it gave me an error. Either way, it's what the docs say to do:

If this function fails, mdb_env_close() must be called to discard the MDB_env handle.
http://symas.com/mdb/doc/group__mdb.html#ga32a193c6bf4d7d5c5d579e71f22e9340

@longjon
Copy link
Contributor

longjon commented Sep 25, 2015

They both default to OFF/0 already. I didn't add the ALLOW_LMDB_NOLOCK ?= 1 line.

Oops, I misread it.

This seems pretty ready to me, I'll leave it momentarily to see if there is further discussion, but then I think we can merge.

@lukeyeager
Copy link
Contributor Author

This seems pretty ready to me, I'll leave it momentarily to see if there is further discussion, but then I think we can merge.

Ping.

longjon added a commit that referenced this pull request Oct 21, 2015
Open LMDB files with MDB_NOLOCK if no write access
@longjon longjon merged commit b02db7f into BVLC:master Oct 21, 2015
@longjon
Copy link
Contributor

longjon commented Oct 21, 2015

Sorry for the wait! This looks good to me, merging.

Thanks @lukeyeager, this provides a nice workaround for a common annoyance.

@lukeyeager lukeyeager deleted the bvlc/lmdb-nolock branch October 21, 2015 16:42
gheinrich added a commit to gheinrich/DIGITS that referenced this pull request Nov 12, 2015
Implement similar patch to BVLC/caffe#3088

If we can't open the LMDB database, try again with no locking.

If this fails again, throw a human-readable error, for example:
2015-11-11 21:29:33 [INFO ] opening LMDB database: /fast-scratch/gheinrich/ws/digits/digits/jobs/20151111-210842-a4ec/train_db
/fast-scratch/gheinrich/ws/torch/install/bin/luajit: ...nrich/ws/torch/install/share/lua/5.1/threads/threads.lua:264:
[thread 4 callback] /fast-scratch/gheinrich/ws/digits/tools/torch/data.lua:117: Failed to open LMDB database: Permission denied
gheinrich added a commit to gheinrich/DIGITS that referenced this pull request Nov 12, 2015
Implement similar patch to BVLC/caffe#3088

If we can't open the LMDB database, try again with no locking.

If this fails again, throw a human-readable error, for example:
2015-11-11 21:29:33 [INFO ] opening LMDB database: /fast-scratch/gheinrich/ws/digits/digits/jobs/20151111-210842-a4ec/train_db
/fast-scratch/gheinrich/ws/torch/install/bin/luajit: ...nrich/ws/torch/install/share/lua/5.1/threads/threads.lua:264:
[thread 4 callback] /fast-scratch/gheinrich/ws/digits/tools/torch/data.lua:117: Failed to open LMDB database: Permission denied
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants