Skip to content

Commit

Permalink
database: attempt to install lmdb if missing
Browse files Browse the repository at this point in the history
When attempting a conversion, install the lmdb package if its missing.
This should resolve issues with containers or new installations that
want to migrate a previous db to sqlite.

Signed-off-by:  Eric Callahan <[email protected]>
  • Loading branch information
Arksine committed May 28, 2024
1 parent 5332eab commit 3b1c21a
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions moonraker/components/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,33 @@ def generate_lmdb_entries(
return
MAX_LMDB_NAMESPACES = 100
MAX_LMDB_SIZE = 200 * 2**20
try:
import lmdb
lmdb_env: LmdbEnvironment = lmdb.open(
str(db_folder), map_size=MAX_LMDB_SIZE, max_dbs=MAX_LMDB_NAMESPACES
)
except Exception:
logging.exception(
"Failed to open lmdb database, aborting conversion"
)
return
inst_attempted: bool = False
while True:
try:
import lmdb
lmdb_env: LmdbEnvironment = lmdb.open(
str(db_folder), map_size=MAX_LMDB_SIZE, max_dbs=MAX_LMDB_NAMESPACES
)
except ModuleNotFoundError:
if inst_attempted:
logging.info(
"Attempt to install LMDB failed, aborting conversion."
)
return
import sys
from ..utils import pip_utils
inst_attempted = True
logging.info("LMDB module not found, attempting installation...")
pip_cmd = f"{sys.executable} -m pip"
pip_exec = pip_utils.PipExecutor(pip_cmd, logging.info)
pip_exec.install_packages(["lmdb"])
except Exception:
logging.exception(
"Failed to open lmdb database, aborting conversion"
)
return
else:
break
lmdb_namespaces: List[Tuple[str, object]] = []
with lmdb_env.begin(buffers=True) as txn:
# lookup existing namespaces
Expand Down

0 comments on commit 3b1c21a

Please sign in to comment.