Skip to content

Commit 9dc8716

Browse files
chore: always checkpoint before shutdown
Signed-off-by: Henry Gressmann <[email protected]>
1 parent e672284 commit 9dc8716

File tree

6 files changed

+44
-9
lines changed

6 files changed

+44
-9
lines changed

.cargo/config.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,3 @@
22

33
[target.x86_64-unknown-linux-musl]
44
rustflags=["-C", "target_cpu=x86-64-v2"]
5-
6-
[env]
7-
DUCKDB_STATIC="1"
8-
DUCKDB_EXTENSIONS="core_functions"

Cargo.lock

Lines changed: 30 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 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.44", default-features=false, features=["macros", "rt-multi-thread"]}
19+
tokio={version="1.44", default-features=false, features=["macros", "rt-multi-thread", "signal"]}
2020
tokio-util={version="0.7", features=["io"]}
2121
futures-lite="2.6"
2222
crossbeam-utils="0.8"
@@ -67,6 +67,7 @@ rustls={version="0.23", features=["aws_lc_rs"]}
6767

6868
# database
6969
duckdb={git="https://github.com/explodingcamera-contrib/duckdb-rs", features=[
70+
"buildtime_bindgen",
7071
"bundled",
7172
"time",
7273
"r2d2",

src/app/db.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ pub(super) fn init_duckdb(
1616
let mut flags = duckdb::Config::default()
1717
.enable_autoload_extension(true)?
1818
.access_mode(duckdb::AccessMode::ReadWrite)?
19-
.with("enable_fsst_vectors", "true")?;
19+
.with("enable_fsst_vectors", "true")?
20+
.with("allocator_background_threads", "true")?;
2021

2122
if let Some(duckdb_config) = duckdb_config {
2223
if let Some(memory_limit) = duckdb_config.memory_limit {
@@ -32,7 +33,7 @@ pub(super) fn init_duckdb(
3233
let pool = r2d2::Pool::new(conn)?;
3334
{
3435
let conn = pool.get()?;
35-
conn.execute_batch("PRAGMA enable_checkpoint_on_shutdown;")?;
36+
conn.execute("PRAGMA enable_checkpoint_on_shutdown", [])?;
3637
conn.pragma_update(None, "autoload_known_extensions", &"true")?;
3738
conn.pragma_update(None, "allow_community_extensions", &"false")?;
3839
}

src/app/mod.rs

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

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

src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ async fn main() -> Result<()> {
2222
}
2323

2424
let app = Liwan::try_new(config)?;
25-
25+
let app_copy = app.clone();
2626
app.run_background_tasks();
27+
2728
tokio::select! {
29+
_ = tokio::signal::ctrl_c() => app_copy.shutdown(),
2830
res = web::start_webserver(app.clone(), s) => res,
2931
res = tokio::task::spawn_blocking(move || app.clone().events.process(r)) => res?
3032
}

0 commit comments

Comments
 (0)