]> Untitled Git - bdk/commitdiff
fix(sqlite): set connection journal_mode to WAL and busy_timeout to 5000 ms
authorSteve Myers <steve@notmandatory.org>
Sat, 15 Feb 2025 04:55:06 +0000 (22:55 -0600)
committerSteve Myers <steve@notmandatory.org>
Tue, 18 Feb 2025 16:56:02 +0000 (10:56 -0600)
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

index 59ce898529dcf6e2bddca8a17b6b2640c61ae15e..a6047b1dc60138f5decb7b349f94c6f1fcb3d2fd 100644 (file)
@@ -86,7 +86,13 @@ impl SqliteDatabase {
     /// Instantiate a new SqliteDatabase instance by creating a connection
     /// to the database stored at path
     pub fn new<T: AsRef<Path>>(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,