From 3f2cc5144bfaa5deab52c4ffc0c2218973a43918 Mon Sep 17 00:00:00 2001 From: hinto-janai Date: Sun, 28 Apr 2024 20:12:42 -0400 Subject: [PATCH] database: update backends (#119) * `heed 0.20.0-alpha.9 -> 0.20.0`, `redb 2.0.0 -> 2.1.0` * heed: fix * redb: fix --- Cargo.lock | 22 ++++++++++------------ database/Cargo.toml | 4 ++-- database/src/backend/heed/env.rs | 4 +++- database/src/backend/heed/error.rs | 15 ++++++--------- database/src/backend/redb/env.rs | 1 + 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 59f14af..4e8ffa9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -803,9 +803,9 @@ dependencies = [ [[package]] name = "doxygen-rs" -version = "0.2.2" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bff670ea0c9bbb8414e7efa6e23ebde2b8f520a7eef78273a3918cf1903e7505" +checksum = "415b6ec780d34dcf624666747194393603d0373b7141eef01d12ee58881507d9" dependencies = [ "phf", ] @@ -1151,12 +1151,11 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "heed" -version = "0.20.0-alpha.9" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9648a50991c86df7d00c56c268c27754fcf4c80be2ba57fc4a00dc928c6fe934" +checksum = "e7a300b0deeb2957162d7752b0f063b3be1c88333af5bb4e7a57d8fb3716f50b" dependencies = [ "bitflags 2.5.0", - "bytemuck", "byteorder", "heed-traits", "heed-types", @@ -1171,15 +1170,15 @@ dependencies = [ [[package]] name = "heed-traits" -version = "0.20.0-alpha.9" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ab0b7d9cde969ad36dde692e487dc89d97f7168bf6a7bd3b894ad4bf7278298" +checksum = "eb3130048d404c57ce5a1ac61a903696e8fcde7e8c2991e9fcfc1f27c3ef74ff" [[package]] name = "heed-types" -version = "0.20.0-alpha.9" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0cb3567a7363f28b597bf6e9897b9466397951dd0e52df2c8196dd8a71af44a" +checksum = "3cb0d6ba3700c9a57e83c013693e3eddb68a6d9b6781cacafc62a0d992e8ddb3" dependencies = [ "bincode", "byteorder", @@ -1529,14 +1528,13 @@ checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" [[package]] name = "lmdb-master-sys" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "629c123f5321b48fa4f8f4d3b868165b748d9ba79c7103fb58e3a94f736bcedd" +checksum = "dc9048db3a58c0732d7236abc4909058f9d2708cfb6d7d047eb895fddec6419a" dependencies = [ "cc", "doxygen-rs", "libc", - "pkg-config", ] [[package]] diff --git a/database/Cargo.toml b/database/Cargo.toml index d925b51..c8efac2 100644 --- a/database/Cargo.toml +++ b/database/Cargo.toml @@ -43,8 +43,8 @@ tower = { workspace = true, features = ["full"], optional = true } rayon = { workspace = true, optional = true } # Optional features. -heed = { version = "0.20.0-alpha.9", optional = true } -redb = { version = "2.0.0", optional = true } +heed = { version = "0.20.0", optional = true } +redb = { version = "2.1.0", optional = true } serde = { workspace = true, optional = true } [dev-dependencies] diff --git a/database/src/backend/heed/env.rs b/database/src/backend/heed/env.rs index 56ece8f..10ee012 100644 --- a/database/src/backend/heed/env.rs +++ b/database/src/backend/heed/env.rs @@ -185,7 +185,9 @@ impl Env for ConcreteEnv { // Create the database directory if it doesn't exist. std::fs::create_dir_all(config.db_directory())?; // Open the environment in the user's PATH. - let env = env_open_options.open(config.db_directory())?; + // SAFETY: LMDB uses a memory-map backed file. + // + let env = unsafe { env_open_options.open(config.db_directory())? }; // TODO: Open/create tables with certain flags // diff --git a/database/src/backend/heed/error.rs b/database/src/backend/heed/error.rs index 65b781b..bb59116 100644 --- a/database/src/backend/heed/error.rs +++ b/database/src/backend/heed/error.rs @@ -49,10 +49,9 @@ impl From for crate::InitError { | E2::Panic => Self::Unknown(Box::new(mdb_error)), }, - E1::InvalidDatabaseTyping - | E1::BadOpenOptions { .. } - | E1::Encoding(_) - | E1::Decoding(_) => Self::Unknown(Box::new(error)), + E1::BadOpenOptions { .. } | E1::Encoding(_) | E1::Decoding(_) => { + Self::Unknown(Box::new(error)) + } } } } @@ -139,11 +138,9 @@ impl From for crate::RuntimeError { }, // Only if we write incorrect code. - E1::InvalidDatabaseTyping - | E1::DatabaseClosing - | E1::BadOpenOptions { .. } - | E1::Encoding(_) - | E1::Decoding(_) => panic!("fix the database code! {error:#?}"), + E1::DatabaseClosing | E1::BadOpenOptions { .. } | E1::Encoding(_) | E1::Decoding(_) => { + panic!("fix the database code! {error:#?}") + } } } } diff --git a/database/src/backend/redb/env.rs b/database/src/backend/redb/env.rs index bbbb6f3..554333a 100644 --- a/database/src/backend/redb/env.rs +++ b/database/src/backend/redb/env.rs @@ -84,6 +84,7 @@ impl Env for ConcreteEnv { .read(true) .write(true) .create(true) + .truncate(false) .open(config.db_file())?; env_builder.create_file(db_file)?