From e5f68184bfe91f6874fe8c2344dbd5fa613d6bee Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 9 Jan 2021 16:52:35 +0200 Subject: feat! use SQLite db for chunk index on server This speeds startup a lot. However, the backup repository needs to be re-created from scratch and internal APIs have change in incompatible ways. --- src/bin/obnam-server.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'src/bin/obnam-server.rs') diff --git a/src/bin/obnam-server.rs b/src/bin/obnam-server.rs index 76d018f..19f2e99 100644 --- a/src/bin/obnam-server.rs +++ b/src/bin/obnam-server.rs @@ -36,9 +36,7 @@ async fn main() -> anyhow::Result<()> { return Err(ConfigError::BadServerAddress.into()); } - let mut store = IndexedStore::new(&config.chunks); - store.fill_index()?; - println!("existing generations: {:?}", store.find_generations()); + let store = IndexedStore::new(&config.chunks)?; let store = Arc::new(Mutex::new(store)); let store = warp::any().map(move || Arc::clone(&store)); @@ -165,9 +163,7 @@ pub async fn fetch_chunk( let store = store.lock().await; let id: ChunkId = id.parse().unwrap(); match store.load(&id) { - Ok(loaded) => { - let meta = loaded.meta().clone(); - let data = loaded.data().clone(); + Ok((data, meta)) => { info!("found chunk {}: {:?}", id, meta); Ok(ChunkResult::Fetched(meta, data)) } @@ -191,9 +187,9 @@ pub async fn search_chunks( return Ok(ChunkResult::BadRequest); } if key == "generation" && value == "true" { - store.find_generations() + store.find_generations().expect("SQL lookup failed") } else if key == "sha256" { - store.find_by_sha256(value) + store.find_by_sha256(value).expect("SQL lookup failed") } else { error!("unknown search key {:?}", key); return Ok(ChunkResult::BadRequest); @@ -210,10 +206,10 @@ pub async fn search_chunks( info!("search found chunk {}", chunk_id); meta } - Err(_) => { + Err(err) => { error!( - "search found chunk {} in index, but but not on disk", - chunk_id + "search found chunk {} in index, but but not on disk: {}", + chunk_id, err ); return Ok(ChunkResult::InternalServerError); } -- cgit v1.2.1