lmdb: how to determine free space left?
Asked Answered
E

1

7

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?

Eugeniaeugenics answered 9/11, 2016 at 0:20 Comment(0)
H
6

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);
Hartsock answered 10/11, 2016 at 11:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.