diff options
author | Alex Auvolat <alex@adnab.me> | 2022-06-06 11:30:10 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-06-06 11:30:10 +0200 |
commit | 4f5d17d46464b09a9e238bf959d14f3127a129cc (patch) | |
tree | 7dcb49efdf046c8435b7643ecba3178ea1747bc1 /src | |
parent | 2d5541b0e7ed0939e99710f40d3859c05bc31175 (diff) | |
download | garage-4f5d17d46464b09a9e238bf959d14f3127a129cc.tar.gz garage-4f5d17d46464b09a9e238bf959d14f3127a129cc.zip |
fixes
Diffstat (limited to 'src')
-rw-r--r-- | src/db/Cargo.toml | 3 | ||||
-rw-r--r-- | src/db/bin/convert.rs | 2 | ||||
-rw-r--r-- | src/db/lib.rs | 27 | ||||
-rw-r--r-- | src/db/lmdb_adapter.rs | 11 | ||||
-rw-r--r-- | src/db/sqlite_adapter.rs | 1 |
5 files changed, 32 insertions, 12 deletions
diff --git a/src/db/Cargo.toml b/src/db/Cargo.toml index ce9c9373..1a24979f 100644 --- a/src/db/Cargo.toml +++ b/src/db/Cargo.toml @@ -27,9 +27,10 @@ sled = "0.34" # cli deps clap = { version = "3.1.18", optional = true, features = ["derive", "env"] } +pretty_env_logger = { version = "0.4", optional = true } [dev-dependencies] mktemp = "0.4" [features] -cli = ["clap"] +cli = ["clap", "pretty_env_logger"] diff --git a/src/db/bin/convert.rs b/src/db/bin/convert.rs index 5dd9e034..636bd834 100644 --- a/src/db/bin/convert.rs +++ b/src/db/bin/convert.rs @@ -25,6 +25,8 @@ struct Args { fn main() { let args = Args::parse(); + pretty_env_logger::init(); + match do_conversion(args) { Ok(()) => println!("Success!"), Err(e) => eprintln!("Error: {}", e), diff --git a/src/db/lib.rs b/src/db/lib.rs index 86042eaf..2e847f7a 100644 --- a/src/db/lib.rs +++ b/src/db/lib.rs @@ -198,16 +198,25 @@ impl Db { let ex_tree = other.open_tree(&name)?; - let mut i = 0; - for item in ex_tree.iter()? { - let (k, v) = item?; - tree.insert(k, v)?; - i += 1; - if i % 1000 == 0 { - println!("{}: imported {}", name, i); + let tx_res = self.transaction(|mut tx| { + let mut i = 0; + for item in ex_tree.iter()? { + let (k, v) = item?; + tx.insert(&tree, k, v)?; + i += 1; + if i % 1000 == 0 { + println!("{}: imported {}", name, i); + } } - } - println!("{}: finished importing, {} items", name, i); + Ok::<_, TxError<()>>(i) + }); + let total = match tx_res { + Err(TxError::Db(e)) => return Err(e), + Err(TxError::Abort(_)) => unreachable!(), + Ok(x) => x, + }; + + println!("{}: finished importing, {} items", name, total); } Ok(()) } diff --git a/src/db/lmdb_adapter.rs b/src/db/lmdb_adapter.rs index 095f512b..aa365733 100644 --- a/src/db/lmdb_adapter.rs +++ b/src/db/lmdb_adapter.rs @@ -230,7 +230,10 @@ impl<'a, 'db> ITx for LmdbTx<'a, 'db> { fn get(&self, tree: usize, key: &[u8]) -> Result<Option<Value<'_>>> { let tree = self.get_tree(tree)?; match tree.get(&self.tx, &key)? { - Some(v) => Ok(Some(Value(Box::new(v)))), + Some(v) => { + let v: &'_ [u8] = v; + Ok(Some(v.into())) + } None => Ok(None), } } @@ -372,7 +375,11 @@ where match iter_ref.unwrap().next() { None => None, Some(Err(e)) => Some(Err(e.into())), - Some(Ok((k, v))) => Some(Ok((k.into(), v.into()))), + Some(Ok((k, v))) => { + let k: &'a [u8] = k; + let v: &'a [u8] = v; + Some(Ok((k.into(), v.into()))) + } } } } diff --git a/src/db/sqlite_adapter.rs b/src/db/sqlite_adapter.rs index 9f2bf919..10e3bfee 100644 --- a/src/db/sqlite_adapter.rs +++ b/src/db/sqlite_adapter.rs @@ -97,6 +97,7 @@ impl IDb for SqliteDb { while let Some(row) = rows.next()? { let name = row.get::<_, String>(0)?; let name = name.replace("_COLON_", ":"); + let name = name.strip_prefix("tree_").unwrap().to_string(); trees.push(name); } Ok(trees) |