Skip to content

Commit cd19702

Browse files
fix: always checkpoint on shutdown
Signed-off-by: Henry Gressmann <mail@henrygressmann.de>
1 parent a46eb08 commit cd19702

File tree

6 files changed

+57
-25
lines changed

6 files changed

+57
-25
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ Since this is not a library, this changelog focuses on the changes that are rele
2424
- Added Country Code to Google Referrer URLs
2525
- Improved Multi-User Support (Non-admin users can now be granted access to specific projects)
2626

27+
## v1.1.0 - 2025-05-15
28+
29+
- Force duckdb to always checkpoint the database after shutting down. This is required for upgrading to the latest version of duckdb in liwan 1.2, which has issues loading the old checkpoint files when using musl libc.
30+
31+
## v1.1.0 - 2024-12-28
32+
33+
- Improved query caching to prevent unnecessary database queries
34+
- Added Country Code to Google Referrer URLs
35+
- Improved Multi-User Support (Non-admin users can now be granted access to specific projects)
36+
2737
## v1.0.0 - 2024-12-06
2838

2939
### 🚀 Features

Cargo.lock

Lines changed: 33 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ path="src/main.rs"
1616

1717
[dependencies]
1818
# async/concurrency
19-
tokio={version="1.38", default-features=false, features=["macros", "rt-multi-thread"]}
19+
tokio={version="1.38", default-features=false, features=["macros", "rt-multi-thread", "signal"]}
2020
tokio-util={version="0.7", features=["io"]}
2121
futures-util="0.3"
2222
crossbeam-utils="0.8"

src/app/db.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::utils::refinery_duckdb::DuckDBConnection;
33
use crate::utils::refinery_sqlite::RqlConnection;
44

55
use duckdb::DuckdbConnectionManager;
6-
use eyre::{bail, Result};
6+
use eyre::{Result, bail};
77
use r2d2_sqlite::SqliteConnectionManager;
88
use refinery::Runner;
99
use std::path::PathBuf;
@@ -30,6 +30,7 @@ pub(super) fn init_duckdb(
3030

3131
{
3232
let conn = pool.get()?;
33+
conn.execute("PRAGMA enable_checkpoint_on_shutdown", [])?;
3334
conn.pragma_update(None, "allow_community_extensions", &"false")?;
3435
conn.pragma_update(None, "autoinstall_known_extensions", &"false")?;
3536
conn.pragma_update(None, "autoload_known_extensions", &"false")?;

src/app/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ impl Liwan {
100100
pub fn run_background_tasks(&self) {
101101
core::geoip::keep_updated(self.geoip.clone());
102102
}
103+
104+
pub fn shutdown(&self) -> Result<()> {
105+
self.events_pool.get()?.execute("FORCE CHECKPOINT", [])?; // normal checkpoints don't seem to work consistently on shutdown
106+
tracing::info!("Shutting down");
107+
Ok(())
108+
}
103109
}
104110

105111
#[cfg(any(debug_assertions, test, feature = "_enable_seeding"))]

src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ async fn main() -> Result<()> {
2020
}
2121

2222
let app = Liwan::try_new(config)?;
23+
let app_copy = app.clone();
2324

2425
app.run_background_tasks();
2526
tokio::select! {
27+
_ = tokio::signal::ctrl_c() => {
28+
tracing::info!("Received Ctrl-C, shutting down");
29+
app_copy.shutdown()
30+
},
2631
res = web::start_webserver(app.clone(), s) => res,
2732
res = tokio::task::spawn_blocking(move || app.clone().events.process(r)) => res?
2833
}

0 commit comments

Comments
 (0)