Skip to content

Commit

Permalink
feat: use mmap by default in sqlite connections (256MB)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcnelson committed Oct 26, 2021
1 parent 4cef87b commit 36b2743
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/util/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ use serde_json::Error as serde_error;
pub type DBConn = rusqlite::Connection;
pub type DBTx<'a> = rusqlite::Transaction<'a>;

// 256MB
pub const SQLITE_MMAP_SIZE: i64 = 256 * 1024 * 1024;

#[derive(Debug)]
pub enum Error {
/// Not implemented
Expand Down Expand Up @@ -428,8 +431,8 @@ pub fn table_exists(conn: &Connection, table_name: &str) -> Result<bool, sqlite_
}

/// Set up an on-disk database with a MARF index if they don't exist yet.
/// Either way, returns (db path, MARF path)
pub fn db_mkdirs(path_str: &str) -> Result<(String, String), Error> {
/// Either way, returns the MARF path
pub fn db_mkdirs(path_str: &str) -> Result<String, Error> {
let mut path = PathBuf::from(path_str);
match fs::metadata(path_str) {
Ok(md) => {
Expand All @@ -449,11 +452,7 @@ pub fn db_mkdirs(path_str: &str) -> Result<(String, String), Error> {
path.push("marf.sqlite");
let marf_path = path.to_str().ok_or_else(|| Error::ParseError)?.to_string();

path.pop();
path.push("data.sqlite");
let data_path = path.to_str().ok_or_else(|| Error::ParseError)?.to_string();

Ok((data_path, marf_path))
Ok(marf_path)
}

/// Read-only connection to a MARF-indexed DB
Expand Down Expand Up @@ -568,6 +567,7 @@ pub fn sqlite_open<P: AsRef<Path>>(
let db = Connection::open_with_flags(path, flags)?;
db.busy_handler(Some(tx_busy_handler))?;
inner_sql_pragma(&db, "journal_mode", &"WAL")?;
inner_sql_pragma(&db, "mmap_size", &SQLITE_MMAP_SIZE)?;
if foreign_keys {
inner_sql_pragma(&db, "foreign_keys", &true)?;
}
Expand Down

0 comments on commit 36b2743

Please sign in to comment.