Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for nosync option, and increase map size #89

Merged
merged 4 commits into from
Jun 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions prairiedog/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@

"""Console script for prairiedog."""
import click
import os

from prairiedog.logger import setup_logging
from prairiedog.prairiedog import Prairiedog
from prairiedog.lemon_graph import LGGraph
from prairiedog.lemon_graph import LGGraph, DB_PATH

# If cli is imported, re-setup logging to level INFO
setup_logging("INFO")

pdg = Prairiedog(g=LGGraph())
# If the path doesn't exist (ie. a tempfile for tests), LemonGraph will
# error out if you set readonly
if os.path.exists(DB_PATH):
pdg = Prairiedog(g=LGGraph(readonly=True))
else:
pdg = Prairiedog(g=LGGraph(readonly=False))


@click.command()
Expand Down
10 changes: 6 additions & 4 deletions prairiedog/lemon_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@ class LGGraph(prairiedog.graph.Graph):
LemonGraph defines directed edges.
"""

def __init__(self, db_path: str = None, delete_on_exit=False):
def __init__(self, db_path: str = None, delete_on_exit=False, nosync=True,
noreadahead=True, readonly=False):
if db_path is not None:
self.db_path = db_path
else:
os.makedirs(prairiedog.config.OUTPUT_DIRECTORY, exist_ok=True)
self.db_path = DB_PATH
log.debug("Creating LemonGraph with backing file {}".format(
self.db_path))
self.g = LemonGraph.Graph(self.db_path)
ret = LemonGraph.lib.graph_set_mapsize(self.g._graph, (4 << 30) * 10)
self.g = LemonGraph.Graph(path=self.db_path, nosync=nosync,
noreadahead=noreadahead, readonly=readonly)
ret = LemonGraph.lib.graph_set_mapsize(self.g._graph, (20 << 30) * 10)
assert (0 == ret)
self._ctx = None
self._txn = None
Expand All @@ -44,7 +46,7 @@ def __del__(self):
Deletes the database file on garbage collection
:return:
"""
if self.delete_on_exit:
if self.delete_on_exit is True:
log.debug("Wiping LemonGraph with backing file {}".format(
self.db_path))
self.clear()
Expand Down