From be9275342cde83ee51840e5859bf9fa0b2cee4eb Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 15 May 2022 09:42:49 +0300 Subject: stash Sponsored-by: author --- src/bin/obnam-server.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/bin/obnam-server.rs b/src/bin/obnam-server.rs index cfa2cb5..c9e93bc 100644 --- a/src/bin/obnam-server.rs +++ b/src/bin/obnam-server.rs @@ -1,10 +1,9 @@ use anyhow::Context; use clap::Parser; use log::{debug, error, info}; -use obnam::chunk::DataChunk; use obnam::chunkid::ChunkId; use obnam::chunkmeta::ChunkMeta; -use obnam::indexedstore::IndexedStore; +use obnam::chunkstore::ChunkStore; use obnam::server::{ServerConfig, ServerConfigError}; use serde::Serialize; use std::collections::HashMap; @@ -37,7 +36,7 @@ async fn main() -> anyhow::Result<()> { return Err(ServerConfigError::BadServerAddress.into()); } - let store = IndexedStore::new(&config.chunks)?; + let store = ChunkStore::local(&config.chunks)?; let store = Arc::new(Mutex::new(store)); let store = warp::any().map(move || Arc::clone(&store)); @@ -102,7 +101,7 @@ fn load_config(filename: &Path) -> Result { } pub async fn create_chunk( - store: Arc>, + store: Arc>, meta: String, data: Bytes, ) -> Result { @@ -116,9 +115,7 @@ pub async fn create_chunk( } }; - let chunk = DataChunk::new(data.to_vec(), meta); - - let id = match store.save(&chunk) { + let id = match store.put(data.to_vec(), &meta).await { Ok(id) => id, Err(e) => { error!("couldn't save: {}", e); @@ -132,11 +129,11 @@ pub async fn create_chunk( pub async fn fetch_chunk( id: String, - store: Arc>, + store: Arc>, ) -> Result { let store = store.lock().await; let id: ChunkId = id.parse().unwrap(); - match store.load(&id) { + match store.get(&id).await { Ok((data, meta)) => { info!("found chunk {}: {:?}", id, meta); Ok(ChunkResult::Fetched(meta, data)) @@ -233,7 +230,7 @@ pub async fn delete_chunk( enum ChunkResult { Created(ChunkId), - Fetched(ChunkMeta, DataChunk), + Fetched(ChunkMeta, Vec), Found(SearchHits), Deleted, NotFound, @@ -264,7 +261,7 @@ impl warp::Reply for ChunkResult { ); into_response( StatusCode::OK, - chunk.data(), + &chunk, "application/octet-stream", Some(headers), ) -- cgit v1.2.1