From 10655114e829d4d196c7aca0e5780af7ad1595b9 Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Fri, 14 Feb 2025 22:55:06 -0600 Subject: [PATCH] fix(sqlite): set connection journal_mode to WAL and busy_timeout to 5000 ms This prevents: Error { code: DatabaseBusy, extended_code: 5 }, Some("database is locked") which occured when syncing very large number of utxos. See: electrum::test::test_electrum_large_num_utxos --- src/database/sqlite.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/database/sqlite.rs b/src/database/sqlite.rs index 59ce8985..a6047b1d 100644 --- a/src/database/sqlite.rs +++ b/src/database/sqlite.rs @@ -86,7 +86,13 @@ impl SqliteDatabase { /// Instantiate a new SqliteDatabase instance by creating a connection /// to the database stored at path pub fn new>(path: T) -> Self { - let connection = get_connection(&path).unwrap(); + let connection = get_connection(&path).expect("Failed to open database"); + connection + .execute_batch("PRAGMA journal_mode = WAL") + .expect("Failed to set WAL journal mode"); + connection + .execute_batch("PRAGMA busy_timeout = 5000") + .expect("Failed to set busy_timeout"); SqliteDatabase { path: PathBuf::from(path.as_ref()), connection, -- 2.49.0