From 8db64726eace1eaab371b1389da583fd42aed51a Mon Sep 17 00:00:00 2001 From: link2xt Date: Wed, 15 Mar 2023 21:08:06 +0000 Subject: [PATCH] sql: expect zero-column results from `PRAGMA incremental_vacuum` The fact that `PRAGMA incremental_vacuum` may return a zero-column SQLITE_ROW result is documented in `sqlite3_data_count()` documentation: Previously successful auto_vacuum worked, but resulted in a "Failed to run incremental vacuum" log. --- CHANGELOG.md | 1 + src/sql.rs | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e1612431..544a6ccf7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ or `dc_jsonrpc_instance_t` is unreferenced during handling the JSON-RPC request. #4153 - Delete expired messages using multiple SQL requests. #4158 +- Do not emit "Failed to run incremental vacuum" warnings on success. #4160 ## 1.111.0 diff --git a/src/sql.rs b/src/sql.rs index aec50171a..86f3bb4fa 100644 --- a/src/sql.rs +++ b/src/sql.rs @@ -713,12 +713,22 @@ pub async fn housekeeping(context: &Context) -> Result<()> { // Try to clear the freelist to free some space on the disk. This // only works if auto_vacuum is enabled. - if let Err(err) = context + match context .sql - .execute("PRAGMA incremental_vacuum", paramsv![]) + .query_row_optional("PRAGMA incremental_vacuum", (), |_row| Ok(())) .await { - warn!(context, "Failed to run incremental vacuum: {}", err); + Err(err) => { + warn!(context, "Failed to run incremental vacuum: {err:#}"); + } + Ok(Some(())) => { + // Incremental vacuum returns a zero-column result if it did anything. + info!(context, "Successfully ran incremental vacuum."); + } + Ok(None) => { + // Incremental vacuum returned `SQLITE_DONE` immediately, + // there were no pages to remove. + } } if let Err(e) = context