Skip to content

Commit

Permalink
feat: KERI_LMDB_MAP_SIZE for setting LMDB file size (#889)
Browse files Browse the repository at this point in the history
  • Loading branch information
kentbull authored Nov 14, 2024
1 parent f96d746 commit 3299987
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/keri_db.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ keri.db.dbing
.. automodule:: keri.db.dbing
:members:

The `KERI_LMDB_MAP_SIZE` environment variable can be used to set the size of the LMDB map. The default size is 4GB.

keri.db.escrowing
-----------------

Expand Down
7 changes: 6 additions & 1 deletion src/keri/db/dbing.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,12 @@ def reopen(self, readonly=False, **kwa):

# open lmdb major database instance
# creates files data.mdb and lock.mdb in .dbDirPath
self.env = lmdb.open(self.path, max_dbs=self.MaxNamedDBs, map_size=104857600,
map_size = os.getenv("KERI_LMDB_MAP_SIZE", '4294967296') # 4GB
try:
map_size = int(map_size)
except ValueError:
map_size = 4 * 1024**3 # 4GB
self.env = lmdb.open(self.path, max_dbs=self.MaxNamedDBs, map_size=map_size,
mode=self.perm, readonly=self.readonly)

self.opened = True if opened and self.env else False
Expand Down
7 changes: 7 additions & 0 deletions tests/db/test_dbing.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,15 @@ def test_lmdber():
assert databaser.path == None
assert databaser.env == None

os.environ['KERI_LMDB_MAP_SIZE'] = f'{2 * 1024**3}' # 2GB
databaser.reopen()
assert databaser.opened
assert databaser.env.info()['map_size'] == 2 * 1024**3 # 2GB

os.environ['KERI_LMDB_MAP_SIZE'] = f'invalid-size' # will trigger default
databaser.reopen()
assert databaser.opened
assert databaser.env.info()['map_size'] == 4 * 1024 ** 3 # 4GB default value
assert isinstance(databaser.env, lmdb.Environment)
assert databaser.path.endswith("keri/db/main")
assert databaser.env.path() == databaser.path
Expand Down

0 comments on commit 3299987

Please sign in to comment.