diff options
Diffstat (limited to 'ripple/fossil/src')
-rw-r--r-- | ripple/fossil/src/lib.rs | 21 |
1 files changed, 9 insertions, 12 deletions
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<fs::File>, chunks_tail: Cell<u64>, } @@ -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"); |