mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-27 05:13:25 +01:00
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.
This commit is contained in:
parent
f85cd8e10b
commit
f37ee2f304
@ -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"));
|
throw0(DB_ERROR("Failed to set max number of dbs"));
|
||||||
|
|
||||||
size_t mapsize = DEFAULT_MAPSIZE;
|
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))
|
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()));
|
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;
|
int txn_flags = 0;
|
||||||
if (mdb_flags & MDB_RDONLY)
|
if (mdb_flags & MDB_RDONLY)
|
||||||
txn_flags |= MDB_RDONLY;
|
txn_flags |= MDB_RDONLY;
|
||||||
|
Loading…
Reference in New Issue
Block a user