From b4923abf4618d7810e2700f705ce7d9b97fecb2d Mon Sep 17 00:00:00 2001 From: dawn <90008@gaze.systems> Date: Sat, 21 Feb 2026 05:15:58 +0000 Subject: [PATCH] fjall: add option to major compact on startup --- src/plc_fjall.rs | 6 ++++++ src/bin/mirror.rs | 14 +++++++++++++- 2 file(s) changed, 19 insertion(s)(+), 1 deletion(s)(-) diff --git a/src/plc_fjall.rs b/src/plc_fjall.rs --- a/src/plc_fjall.rs +++ b/src/plc_fjall.rs @@ -137,6 +137,12 @@ self.inner.db.persist(PersistMode::SyncAll) } + pub fn compact(&self) -> fjall::Result<()> { + self.inner.ops.major_compact()?; + self.inner.by_did.major_compact()?; + Ok(()) + } + pub fn get_latest(&self) -> anyhow::Result> { let Some(guard) = self.inner.ops.last_key_value() else { return Ok(None); diff --git a/src/bin/mirror.rs b/src/bin/mirror.rs --- a/src/bin/mirror.rs +++ b/src/bin/mirror.rs @@ -22,6 +22,13 @@ /// path to a local fjall database directory (alternative to postgres) #[arg(long, env = "ALLEGEDLY_WRAP_FJALL", conflicts_with_all = ["wrap_pg", "wrap_pg_cert"])] wrap_fjall: Option, + /// compact the fjall db on startup + #[arg( + long, + env = "ALLEGEDLY_FJALL_COMPACT", + conflicts_with_all = ["wrap_pg", "wrap_pg_cert"] + )] + compact_fjall: bool, /// wrapping server listen address #[arg(short, long, env = "ALLEGEDLY_BIND")] #[clap(default_value = "127.0.0.1:8000")] @@ -74,6 +81,7 @@ wrap_pg, wrap_pg_cert, wrap_fjall, + compact_fjall, bind, acme_domain, acme_cache_path, @@ -112,12 +120,16 @@ if let Some(fjall_path) = wrap_fjall { let db = FjallDb::open(&fjall_path)?; + if compact_fjall { + log::info!("compacting fjall..."); + db.compact()?; // blocking here is fine, we didn't start anything yet + } log::debug!("getting the latest op from fjall..."); let latest = db .get_latest()? .expect("there to be at least one op in the db. did you backfill?"); - log::debug!("starting polling from {latest}..."); + log::info!("starting polling from {latest}..."); let (send_page, recv_page) = mpsc::channel(8); -- tangled.sh