aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorannalee <150648636+a-n-n-a-l-e-e@users.noreply.github.com>2024-03-23 06:41:33 +0000
committerjade <lix@jade.fyi>2024-05-31 12:22:15 +0000
commit713cd7e9e7012a11d2347e9b1a5dee9b4d3c62c0 (patch)
tree4a3d6eb8d2588c6d6a7d6f471f95780b6c29eb24 /src
parent0c6cb34de6033d0ceab5de8cbfc37465afeefaa4 (diff)
truncate WAL files on exit
Fix for https://github.com/NixOS/nix/issues/10300 https://github.com/lix-project/lix/commit/18a26202737a74f216d285d92bd4a84761788026 enabled persistent WAL files that will never get truncated. to fix this, journal_size_limit is set to 2^40, which results in the WAL files being truncated to 0 on exit, as well as limiting the WAL files to 2^40 bytes following a checkpoint. this aligns lix with the nix change: https://github.com/NixOS/nix/pull/10301 https://www.sqlite.org/c3ref/c_fcntl_begin_atomic_write.html#sqlitefcntlpersistwal https://www.sqlite.org/pragma.html#pragma_journal_size_limit https://github.com/sqlite/sqlite/blob/ed517a708284b6e00b6ae5f1e3f702bbfcbd32ed/src/wal.c#L2518 PR-Link: https://github.com/lix-project/lix/pull/9 Co-Authored-By: paparodeo <170618376+paparodeo@users.noreply.github.com> Change-Id: I90ec1a467c92c582ff8c07dd363a4cf789782214
Diffstat (limited to 'src')
-rw-r--r--src/libstore/local-store.cc7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index 7bcbe3298..d92fafa1b 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -550,7 +550,12 @@ void LocalStore::openDB(State & state, bool create)
if (mode == "wal" ) {
/* persist the WAL files when the DB connection is closed.
* This allows for read-only connections without any write permissions
- * on the state directory to succeed on a closed database. */
+ * on the state directory to succeed on a closed database. Setting the
+ * journal_size_limit to 2^40 bytes results in the WAL files getting
+ * truncated to 0 on exit and limits the on disk size of the WAL files
+ * to 2^40 bytes following a checkpoint */
+ if (sqlite3_exec(db, "pragma main.journal_size_limit = 1099511627776;", 0, 0, 0) != SQLITE_OK)
+ SQLiteError::throw_(db, "setting journal_size_limit");
int enable = 1;
if (sqlite3_file_control(db, NULL, SQLITE_FCNTL_PERSIST_WAL, &enable) != SQLITE_OK)
SQLiteError::throw_(db, "setting persistent WAL mode");