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