From 4ed3d1fec4f1d0f00b03f6a0a86dca999694db5e Mon Sep 17 00:00:00 2001 From: edef Date: Tue, 26 Apr 2022 12:38:58 +0000 Subject: ripple/fossil: use the default sled tree for global metadata, not blobs Change-Id: I358a5c354c19cc8cb0a75629758fda476629406d --- ripple/fossil/src/lib.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'ripple/fossil') diff --git a/ripple/fossil/src/lib.rs b/ripple/fossil/src/lib.rs index ed55138..b51fc27 100644 --- a/ripple/fossil/src/lib.rs +++ b/ripple/fossil/src/lib.rs @@ -24,8 +24,8 @@ const CHUNK_BYTES: usize = 0x400; const DIGEST_BYTES: usize = blake3::OUT_LEN; pub struct Store { - db: sled::Db, meta: sled::Tree, + blobs: sled::Tree, chunks: RefCell, chunks_tail: Cell, } @@ -35,7 +35,8 @@ impl Store { let path = path.as_ref(); let db = sled::open(path)?; - let meta = db.open_tree("meta")?; + let meta = (&*db).clone(); + let blobs = db.open_tree("blobs")?; let chunks = fs::OpenOptions::new() .read(true) @@ -51,7 +52,7 @@ impl Store { chunks.set_len(chunks_tail)?; Ok(Store { - db, + blobs, meta, chunks: RefCell::new(chunks), chunks_tail: Cell::new(chunks_tail), @@ -115,7 +116,7 @@ impl Store { encoder.finalize().unwrap() }; - if self.db.contains_key(&*ident.as_bytes()).unwrap() { + if self.blobs.contains_key(&*ident.as_bytes()).unwrap() { // key already exists return ident; } @@ -126,10 +127,6 @@ impl Store { chunks_file.write_all(data).unwrap(); let chunks_tail = offset + data.len() as u64; - // TODO(edef): maybe don't use the default tree? - // we should probably have a "blob" tree, - // and reserve the default tree for DB metadata - let blob_buf = store::Blob { offset, length: data.len() as u64, @@ -144,9 +141,9 @@ impl Store { }; // TODO(edef): figure out fsync for durability - (&*self.db, &self.meta) - .transaction(|(db, meta)| { - db.insert(&*ident.as_bytes(), &*blob_buf)?; + (&self.blobs, &self.meta) + .transaction(|(blobs, meta)| { + blobs.insert(&*ident.as_bytes(), &*blob_buf)?; meta.insert("chunks_tail", &chunks_tail_buf)?; Ok::<_, ConflictableTransactionError>(()) }) @@ -164,7 +161,7 @@ impl Store { pub fn open_blob(&self, ident: Digest) -> Blob { let buf = self - .db + .blobs .get(&*ident.as_bytes()) .unwrap() .expect("blob not found"); -- cgit 1.4.1