Commit 9a94f905 authored by Tomas Krizek's avatar Tomas Krizek

dbhelper: always check db exists when not creating it

Explicit check for db existence is redundant. It should always be
checked when we're not creating the db -- otherwise, it will only crash with
a less readable exception later on.
parent a9af8ab7
......@@ -54,10 +54,10 @@ class LMDB:
def __exit__(self, exc_type, exc_val, exc_tb):
def open_db(self, dbname: bytes, create: bool = False, check_exists: bool = False,
def open_db(self, dbname: bytes, create: bool = False,
check_notexists: bool = False, drop: bool = False):
assert self.env is not None, "LMDB wasn't initialized!"
if check_exists and not self.exists_db(dbname):
if not create and not self.exists_db(dbname):
msg = 'LMDB environment "{}" does not contain DB {}! '.format(
self.path, dbname.decode('utf-8'))
raise RuntimeError(msg)
......@@ -240,7 +240,7 @@ def main():
with LMDB(args.envdir, fast=True) as lmdb_:
lmdb = lmdb_
lmdb.open_db(LMDB.ANSWERS, check_exists=True)
lmdb.open_db(LMDB.DIFFS, create=True, drop=True)
qid_stream = lmdb.key_stream(LMDB.ANSWERS)
func = partial(compare_lmdb_wrapper, criteria, target)
......@@ -74,7 +74,7 @@ def main():
with LMDB(args.envdir, fast=True) as lmdb:
lmdb.open_db(LMDB.QUERIES, check_exists=True)
adb = lmdb.open_db(LMDB.ANSWERS, create=True, check_notexists=True)
sdb = lmdb.open_db(LMDB.STATS, create=True)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment