Skip to content

Commit

Permalink
Open LMDB files with MDB_NOLOCK if no write access
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeyeager committed Sep 18, 2015
1 parent 3d12b5d commit 274c88a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/caffe/util/db_lmdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,18 @@ void LMDB::Open(const string& source, Mode mode) {
if (mode == READ) {
flags = MDB_RDONLY | MDB_NOTLS;
}
MDB_CHECK(mdb_env_open(mdb_env_, source.c_str(), flags, 0664));
int rc = mdb_env_open(mdb_env_, source.c_str(), flags, 0664);
if (rc == EACCES) {
LOG(WARNING) << "Permission denied. Trying with MDB_NOLOCK ...";
// Close and re-open environment handle
mdb_env_close(mdb_env_);
MDB_CHECK(mdb_env_create(&mdb_env_));
flags |= MDB_NOLOCK;
// Try again
MDB_CHECK(mdb_env_open(mdb_env_, source.c_str(), flags, 0664));
} else {
MDB_CHECK(rc);
}
LOG(INFO) << "Opened lmdb " << source;
}

Expand Down

0 comments on commit 274c88a

Please sign in to comment.