Explorar el Código

fix: busy_timeout(5000) + WAL journal mode on SQLite connections — eliminates 'database is locked' under concurrent readers

clanker hace 6 días
padre
commit
dd86ceab8f
Se han modificado 1 ficheros con 15 adiciones y 0 borrados
  1. 15 0
      src/sqlite/sqlite-connection.vala

+ 15 - 0
src/sqlite/sqlite-connection.vala

@@ -56,6 +56,15 @@ namespace InvercargillSql {
         
         
         /**
         /**
          * Opens the database connection.
          * Opens the database connection.
+         *
+         * A 5-second busy timeout is applied so concurrent readers (another
+         * process inspecting the store, a second connection) make writers
+         * wait instead of failing immediately with "database is locked",
+         * and WAL journaling is enabled where available so readers never
+         * block the writer at all. Both pragmas are best effort: a
+         * filesystem or build without WAL support falls back silently to
+         * the defaults.
+         *
          * @throws SqlError if the connection cannot be opened
          * @throws SqlError if the connection cannot be opened
          */
          */
         public void open() throws SqlError {
         public void open() throws SqlError {
@@ -67,6 +76,12 @@ namespace InvercargillSql {
                 );
                 );
             }
             }
             _is_open = true;
             _is_open = true;
+            _db.busy_timeout(5000);
+            try {
+                execute("PRAGMA journal_mode=WAL");
+            } catch (SqlError e) {
+                // Best effort only.
+            }
         }
         }
         
         
         /**
         /**