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/benchmark-index.rs | 6 ++++-- src/bin/benchmark-indexedstore.rs | 2 +- src/bin/obnam-server.rs | 18 +++++++----------- 3 files changed, 12 insertions(+), 14 deletions(-) (limited to 'src/bin') diff --git a/src/bin/benchmark-index.rs b/src/bin/benchmark-index.rs index 5008660..d49a6c3 100644 --- a/src/bin/benchmark-index.rs +++ b/src/bin/benchmark-index.rs @@ -1,4 +1,5 @@ use obnam::benchmark::ChunkGenerator; +use obnam::chunkmeta::ChunkMeta; use obnam::index::Index; use std::path::PathBuf; use structopt::StructOpt; @@ -24,9 +25,10 @@ fn main() -> anyhow::Result<()> { let opt = Opt::from_args(); let gen = ChunkGenerator::new(opt.num); - let mut index = Index::default(); + let mut index = Index::new(".")?; for (id, checksum, _, _) in gen { - index.insert(id, "sha25", &checksum); + let meta = ChunkMeta::new(&checksum); + index.insert_meta(id, meta)?; } Ok(()) diff --git a/src/bin/benchmark-indexedstore.rs b/src/bin/benchmark-indexedstore.rs index a4191ac..3ee4c38 100644 --- a/src/bin/benchmark-indexedstore.rs +++ b/src/bin/benchmark-indexedstore.rs @@ -19,7 +19,7 @@ fn main() -> anyhow::Result<()> { let opt = Opt::from_args(); let gen = ChunkGenerator::new(opt.num); - let mut store = IndexedStore::new(&opt.chunks); + let mut store = IndexedStore::new(&opt.chunks)?; for (_, _, meta, chunk) in gen { store.save(&meta, &chunk)?; } 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