diff --git a/src/bin/mirror.rs b/src/bin/mirror.rs index 1e6ad5a..99247d1 100644 --- a/src/bin/mirror.rs +++ b/src/bin/mirror.rs @@ -22,6 +22,13 @@ pub struct Args { /// 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 @@ pub async fn run( wrap_pg, wrap_pg_cert, wrap_fjall, + compact_fjall, bind, acme_domain, acme_cache_path, @@ -112,12 +120,16 @@ pub async fn run( 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); diff --git a/src/plc_fjall.rs b/src/plc_fjall.rs index 990c4aa..107dca2 100644 --- a/src/plc_fjall.rs +++ b/src/plc_fjall.rs @@ -137,6 +137,12 @@ impl FjallDb { 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);