When creating lmdb environment I can specify map size. Is there a way to determine at any point how much of the map size is used up?
In other words, I need to find out how much free space is left to be able to address the issue of running out of space before it happens.
The only thing I could think of is to go through all databases and use mdb_env_stat to get number of branch, leaf and overflow pages. Sum it all up across all dbs (times page size) and compare to the current map size. Is this the correct way to calculate used space?
That is indeed the approach I'm using as well (and the only I could find).
For every database:
MDB_stat stat;
mdb_stat(d->transaction, d->dbi, &stat);
auto dbSize = stat.ms_psize * (stat.ms_leaf_pages + stat.ms_branch_pages + stat.ms_overflow_pages);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With