Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lmdb: how to determine free space left?

Tags:

lmdb

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?

like image 886
Sumrak Avatar asked Nov 09 '16 00:11

Sumrak


1 Answers

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);
like image 116
cmollekopf Avatar answered Oct 18 '22 04:10

cmollekopf