aboutsummaryrefslogtreecommitdiff
path: root/src/db
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-06-03 16:40:38 +0200
committerAlex Auvolat <alex@adnab.me>2022-06-03 16:40:38 +0200
commit2d5541b0e7ed0939e99710f40d3859c05bc31175 (patch)
treebed4653c7073f927275c8f6aa0f870ea9d227f54 /src/db
parentf7a1c70089bf453554f5ae787da4865caf0ee5c4 (diff)
downloadgarage-2d5541b0e7ed0939e99710f40d3859c05bc31175.tar.gz
garage-2d5541b0e7ed0939e99710f40d3859c05bc31175.zip
Integrate LMDB with rest
Diffstat (limited to 'src/db')
-rw-r--r--src/db/bin/convert.rs11
-rw-r--r--src/db/lmdb_adapter.rs26
2 files changed, 36 insertions, 1 deletions
diff --git a/src/db/bin/convert.rs b/src/db/bin/convert.rs
index 7525bcc9..5dd9e034 100644
--- a/src/db/bin/convert.rs
+++ b/src/db/bin/convert.rs
@@ -48,6 +48,17 @@ fn open_db(path: PathBuf, engine: String) -> Result<Db> {
let db = sqlite_adapter::rusqlite::Connection::open(&path)?;
Ok(sqlite_adapter::SqliteDb::init(db))
}
+ "lmdb" | "heed" => {
+ std::fs::create_dir_all(&path).map_err(|e| {
+ Error(format!("Unable to create LMDB data directory: {}", e).into())
+ })?;
+ let db = lmdb_adapter::heed::EnvOpenOptions::new()
+ .max_dbs(100)
+ .map_size(1usize << 30)
+ .open(&path)
+ .unwrap();
+ Ok(lmdb_adapter::LmdbDb::init(db))
+ }
e => Err(Error(format!("Invalid DB engine: {}", e).into())),
}
}
diff --git a/src/db/lmdb_adapter.rs b/src/db/lmdb_adapter.rs
index d568b5c5..095f512b 100644
--- a/src/db/lmdb_adapter.rs
+++ b/src/db/lmdb_adapter.rs
@@ -72,7 +72,31 @@ impl IDb for LmdbDb {
}
fn list_trees(&self) -> Result<Vec<String>> {
- unimplemented!()
+ let tree0 = match self.db.open_database::<heed::types::Str, ByteSlice>(None)? {
+ Some(x) => x,
+ None => return Ok(vec![]),
+ };
+
+ let mut ret = vec![];
+ let tx = self.db.read_txn()?;
+ for item in tree0.iter(&tx)? {
+ let (tree_name, _) = item?;
+ ret.push(tree_name.to_string());
+ }
+ drop(tx);
+
+ let mut ret2 = vec![];
+ for tree_name in ret {
+ if self
+ .db
+ .open_database::<ByteSlice, ByteSlice>(Some(&tree_name))?
+ .is_some()
+ {
+ ret2.push(tree_name);
+ }
+ }
+
+ Ok(ret2)
}
// ----