Skip to content

Commit 36f8f55

Browse files
committed
[lmdb facebookincubator#10] Set mapsize to 1TB by default for r/w DBs
1 parent 4b1262f commit 36f8f55

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

glean/lmdb/container-impl.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,19 @@ ContainerImpl::ContainerImpl(
7474
MDB_env *db_ptr;
7575
check( mdb_env_create(&db_ptr) );
7676
check( mdb_env_set_maxdbs(db_ptr, Family::count()) );
77-
check( mdb_env_set_mapsize(db_ptr, 10*1024*1024*1024UL) );
77+
78+
// LMDB needs us to pre-set the memory map size, which determines
79+
// the maximum size of the DB. Setting it to zero uses the mapsize
80+
// when the DB was created, while setting it to a value smaller than
81+
// the actual size of the DB causes LMDB to use the DB size - this
82+
// is what we want for a read-only DB. For a read/write DB we have
83+
// to pick a huge value, because the mapsize can only be increased
84+
// if there are no transactions in progress, and we don't have a good
85+
// way to do that aside from closing and re-opening the DB.
86+
check( mdb_env_set_mapsize(
87+
db_ptr,
88+
m == Mode::ReadOnly ? 1 : 1024*1024*1024*1024UL) );
89+
7890
check( mdb_env_open(db_ptr, path.c_str(), flags, 0666) );
7991
SCOPE_FAIL { mdb_env_close(db_ptr); };
8092

0 commit comments

Comments
 (0)