summary refs log tree commit diff
path: root/ripple/fossil
diff options
context:
space:
mode:
authoredef <edef@unfathomable.blue>2022-04-26 12:38:58 +0000
committeredef <edef@unfathomable.blue>2022-04-26 12:39:48 +0000
commit4ed3d1fec4f1d0f00b03f6a0a86dca999694db5e (patch)
tree1e7dda36714bf57e5dab3cf3fb5ac8c309959bd4 /ripple/fossil
parent9f922b32c3a952efc083ba473aa0791b91ad9b30 (diff)
downloadunf-legacy-4ed3d1fec4f1d0f00b03f6a0a86dca999694db5e.tar.zst
ripple/fossil: use the default sled tree for global metadata, not blobs
Change-Id: I358a5c354c19cc8cb0a75629758fda476629406d
Diffstat (limited to 'ripple/fossil')
-rw-r--r--ripple/fossil/src/lib.rs21
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");