aboutsummaryrefslogtreecommitdiff
path: root/core.j2.c
diff options
context:
space:
mode:
authorPaul Oliver <contact@pauloliver.dev>2025-11-26 02:20:36 +0100
committerPaul Oliver <contact@pauloliver.dev>2025-11-26 02:20:36 +0100
commitaadc47956edea63776c2d4466d6c3ee0557c0e43 (patch)
treeeca4da8a4f2702fa1ab824c26752aa673f3a2ba8 /core.j2.c
parentfcf5746e8defdacba2284581a6521f72096891c5 (diff)
Enable SQLite Write-Ahead Logging (WAL)
Diffstat (limited to 'core.j2.c')
-rw-r--r--core.j2.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/core.j2.c b/core.j2.c
index 45cd8b8..bd4b266 100644
--- a/core.j2.c
+++ b/core.j2.c
@@ -609,6 +609,31 @@ void salis_auto_save() {
}
{% endif %}
+{% if data_push_path is defined %}
+void salis_exec_sql(const char *sql) {
+ assert(sql);
+
+ int sql_res;
+ char *sql_err;
+
+ while ((sql_res = sqlite3_exec(g_sim_data, sql, NULL, NULL, &sql_err)) == SQLITE_BUSY) {
+ g_warn("SQLite database returned error '%d' with message:", sql_res);
+ g_warn(sql_err);
+ sqlite3_free(sql_err);
+
+ switch (sql_res) {
+ case SQLITE_BUSY:
+ // Only handle busy database errors
+ g_info("Will retry query...");
+ continue;
+ default:
+ // Application should fail on all other error conditions
+ assert(false);
+ }
+ }
+}
+{% endif %}
+
{% if args.command in ["bench", "new"] %}
void salis_init() {
assert(g_info);
@@ -631,6 +656,11 @@ void salis_init() {
// Install busy handler to retry transactions if DB is locked
sqlite3_busy_timeout(g_sim_data, {{ data_push_busy_timeout }});
+ // Enable Write-Ahead Logging (WAL)
+ // This seems to help prevent DB locks when displaying live data
+ // See: https://sqlite.org/wal.html
+ salis_exec_sql("pragma journal_mode=wal;");
+
arch_push_data_header();
arch_push_data_line();
{% endif %}