Server tools to backfill, tail, mirror, and verify PLC logs

fjall: add option to major compact on startup

ptr.pet b4923abf 1ef913f4

verified
+19 -1
+13 -1
src/bin/mirror.rs
··· 22 22 /// path to a local fjall database directory (alternative to postgres) 23 23 #[arg(long, env = "ALLEGEDLY_WRAP_FJALL", conflicts_with_all = ["wrap_pg", "wrap_pg_cert"])] 24 24 wrap_fjall: Option<PathBuf>, 25 + /// compact the fjall db on startup 26 + #[arg( 27 + long, 28 + env = "ALLEGEDLY_FJALL_COMPACT", 29 + conflicts_with_all = ["wrap_pg", "wrap_pg_cert"] 30 + )] 31 + compact_fjall: bool, 25 32 /// wrapping server listen address 26 33 #[arg(short, long, env = "ALLEGEDLY_BIND")] 27 34 #[clap(default_value = "127.0.0.1:8000")] ··· 74 81 wrap_pg, 75 82 wrap_pg_cert, 76 83 wrap_fjall, 84 + compact_fjall, 77 85 bind, 78 86 acme_domain, 79 87 acme_cache_path, ··· 112 120 113 121 if let Some(fjall_path) = wrap_fjall { 114 122 let db = FjallDb::open(&fjall_path)?; 123 + if compact_fjall { 124 + log::info!("compacting fjall..."); 125 + db.compact()?; // blocking here is fine, we didn't start anything yet 126 + } 115 127 116 128 log::debug!("getting the latest op from fjall..."); 117 129 let latest = db 118 130 .get_latest()? 119 131 .expect("there to be at least one op in the db. did you backfill?"); 120 - log::debug!("starting polling from {latest}..."); 132 + log::info!("starting polling from {latest}..."); 121 133 122 134 let (send_page, recv_page) = mpsc::channel(8); 123 135
+6
src/plc_fjall.rs
··· 137 137 self.inner.db.persist(PersistMode::SyncAll) 138 138 } 139 139 140 + pub fn compact(&self) -> fjall::Result<()> { 141 + self.inner.ops.major_compact()?; 142 + self.inner.by_did.major_compact()?; 143 + Ok(()) 144 + } 145 + 140 146 pub fn get_latest(&self) -> anyhow::Result<Option<Dt>> { 141 147 let Some(guard) = self.inner.ops.last_key_value() else { 142 148 return Ok(None);