diff options
author | warptangent <warptangent@inbox.com> | 2015-05-30 07:48:16 -0700 |
---|---|---|
committer | warptangent <warptangent@inbox.com> | 2015-05-30 09:27:49 -0700 |
commit | f37ee2f30428040741ffc5c5bc96a12280f1ad93 (patch) | |
tree | 184299ab973087ad90a863921613e4fde498ca7a /src/blockchain_db/lmdb/db_lmdb.cpp | |
parent | Include database error in more error messages (diff) | |
download | monero-f37ee2f30428040741ffc5c5bc96a12280f1ad93.tar.xz |
Update database resize behavior
On an existing database, don't set LMDB map size to be the initial size
for a new database.
Check if resize is needed at startup.
Diffstat (limited to '')
-rw-r--r-- | src/blockchain_db/lmdb/db_lmdb.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index 30a641482..3ef5f3045 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -822,11 +822,29 @@ void BlockchainLMDB::open(const std::string& filename, const int mdb_flags) throw0(DB_ERROR("Failed to set max number of dbs")); size_t mapsize = DEFAULT_MAPSIZE; - if (auto result = mdb_env_set_mapsize(m_env, mapsize)) - throw0(DB_ERROR(std::string("Failed to set max memory map size: ").append(mdb_strerror(result)).c_str())); + if (auto result = mdb_env_open(m_env, filename.c_str(), mdb_flags, 0644)) throw0(DB_ERROR(std::string("Failed to open lmdb environment: ").append(mdb_strerror(result)).c_str())); + MDB_envinfo mei; + mdb_env_info(m_env, &mei); + uint64_t cur_mapsize = (double)mei.me_mapsize; + + if (cur_mapsize < mapsize) + { + if (auto result = mdb_env_set_mapsize(m_env, mapsize)) + throw0(DB_ERROR(std::string("Failed to set max memory map size: ").append(mdb_strerror(result)).c_str())); + mdb_env_info(m_env, &mei); + cur_mapsize = (double)mei.me_mapsize; + LOG_PRINT_L1("LMDB memory map size: " << cur_mapsize); + } + + if (need_resize()) + { + LOG_PRINT_L0("LMDB memory map needs resized, doing that now."); + do_resize(); + } + int txn_flags = 0; if (mdb_flags & MDB_RDONLY) txn_flags |= MDB_RDONLY; |