From 38eba846f8c38f52a348fa30f71207c5aa891305 Mon Sep 17 00:00:00 2001 From: Scott Lamb Date: Fri, 29 Dec 2023 16:31:06 -0800 Subject: [PATCH] use `unix-excl` sqlite3 vfs --- server/src/cmds/mod.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/server/src/cmds/mod.rs b/server/src/cmds/mod.rs index fdcbc7f..b7be4e3 100644 --- a/server/src/cmds/mod.rs +++ b/server/src/cmds/mod.rs @@ -72,7 +72,7 @@ fn open_conn(db_dir: &Path, mode: OpenMode) -> Result<(dir::Fd, rusqlite::Connec mode, rusqlite::version() ); - let conn = rusqlite::Connection::open_with_flags( + let conn = rusqlite::Connection::open_with_flags_and_vfs( db_path, match mode { OpenMode::ReadOnly => rusqlite::OpenFlags::SQLITE_OPEN_READ_ONLY, @@ -81,9 +81,17 @@ fn open_conn(db_dir: &Path, mode: OpenMode) -> Result<(dir::Fd, rusqlite::Connec rusqlite::OpenFlags::SQLITE_OPEN_READ_WRITE | rusqlite::OpenFlags::SQLITE_OPEN_CREATE }, } | - // rusqlite::Connection is not Sync, so there's no reason to tell SQLite3 to use the + // `rusqlite::Connection` is not Sync, so there's no reason to tell SQLite3 to use the // serialized threading mode. rusqlite::OpenFlags::SQLITE_OPEN_NO_MUTEX, + // In read/write mode, Moonfire holds a directory lock for its entire operation, as + // described above. There's then no point in SQLite releasing its lock after each + // transaction and reacquiring it, or in using shared memory for the wal-index. + // See the following page: + match mode { + OpenMode::ReadOnly => "unix", + _ => "unix-excl", + }, )?; Ok((dir, conn)) }