summaryrefslogtreecommitdiff
path: root/src/bin/obnam-server.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-01-09 16:52:35 +0200
committerLars Wirzenius <liw@liw.fi>2021-01-10 18:17:27 +0200
commite5f68184bfe91f6874fe8c2344dbd5fa613d6bee (patch)
tree9860e2bc6c827bf69d1c324303e01c86efd94e65 /src/bin/obnam-server.rs
parent7ff248232a414b907b3abe464cc015e5ea48c236 (diff)
downloadobnam2-e5f68184bfe91f6874fe8c2344dbd5fa613d6bee.tar.gz
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.
Diffstat (limited to 'src/bin/obnam-server.rs')
-rw-r--r--src/bin/obnam-server.rs18
1 files changed, 7 insertions, 11 deletions
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);
}