diff options
Diffstat (limited to 'src/bin')
-rw-r--r-- | src/bin/benchmark-index.rs | 6 | ||||
-rw-r--r-- | src/bin/benchmark-indexedstore.rs | 2 | ||||
-rw-r--r-- | src/bin/obnam-server.rs | 18 |
3 files changed, 12 insertions, 14 deletions
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); } |